I managed to get the homework transactions to work as expected (happy), so far so good...

I also tried the following scenario which did not work.

Q1: Why doesn't it work?

Q2: How would it be possible to make it work!

wallet 1: give 20 Ada wait 1 wallet 2: grab false/true wait 1 wallet 2: grab true/true wait 1

As expected, the first grab is not handled, as it evaluates false But the second grab is also not handled ? The logtrace shows:

Slot 3: 00000000-0000-4000-8000-000000000002 {Wallet Wc30e}: No requests handled ]

Why isn't it possible for the same wallet to "correct" its previous mistake and try again with acceptible parameters ?

playground actions resluting in no grab

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Jan 23, 2022 at 22:30

1 Answer 1


Your scenario fails because the way off-chain code was implemented: Once on-chain grab validation fails, the off-chain caller grab fails and the execution finishes. Why? - Because off-chain code is not handling errors.

How to make it work? - Replace function endpoint with these 2 functions.

endpoints :: AsContractError e => Contract () GiftSchema e ()
endpoints = handleError handler (selectList [give', grab']) >> endpoints
    give' = endpoint @"give" give
    grab' = endpoint @"grab" grab

handler :: AsContractError e => e -> Contract w s e ()
handler _ = logError @String "an error occurred"

Note: If I'm not wrong, in lecture 4 Lars talks about error handling in off-chain code.

  • 1
    Follow up question: suppose the above scenario played out on the MAINNET. Say Wim's code was v1, kindofdev's improvement is v2. Can the v2 code grab those 20 ADA 'locked' up by the v1 code ? My guess: yes, as long as you don't change the validator code, because that determines the script address. Am I right?
    – wmoco_6725
    Commented Jan 25, 2022 at 8:16
  • Yes, that's correct. @wmoco_6725
    – kindofdev
    Commented Jan 25, 2022 at 9:57
  • Thanks @kindofdev, finally got time to execute it and your solution works! Commented Jan 28, 2022 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.