3

Let's say I need to send some EOS to 2 different addresses from within a smart contract!

Now, let's suppose that one of those addresses is actually a smart contract and can reject the transfer! In this case, since one of the transfers failed, my whole transaction will fail!

Is there a way I can catch the exception of the first transaction and even it fails, I can still trigger the second transfer?

2 Answers 2

2

There is no exception handling in web assembly, therefore you can't implement it in the C++ code either.

Update: Deferred transactions are deprecated in EOSIO, so I do not recommend using them.

The answer from @Gassa is good with reference to the claim function. Let anyone call it and you can set up a cronjob either on your local server or using something like LiquidApps to claim whenever you need to.

3
  • exception handling in web assembly in proposal state github.com/WebAssembly/proposals/issues/4 Oct 17, 2018 at 8:35
  • Is there anything that can be done here? I just need a way to send EOS to multiple people in one transaction and make sure that if any of them rejects the transfer, then the whole transaction doesn't fail! Oct 17, 2018 at 8:40
  • 2
    You could send them as deferred transactions, then if one failed the others would be fine Oct 17, 2018 at 9:58
0

One way to do what transfers can be done is to use deferred transactions.

Setup a table where you will record what you owe to different addresses.

Make a claim function which does not require authorization, sends all owed EOS to the account provided in the parameter, and clears the respective table entry.

Now, when you want to transfer to two accounts, add two records to the table, and make two separate deferred claim transactions for these accounts, with some minimal delay like 0.0 or 0.5 seconds.

If any of the deferred transactions fails for any reason, it does not affect the other transaction. Moreover, when the reason for failure is fixed, the user can claim the owed EOS by themselves at any time.

This scheme is used, for example, in the eosio.system contract for name bidding.

Your Answer

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

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