2

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?

1

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

|improve this answer|||||
  • exception handling in web assembly in proposal state github.com/WebAssembly/proposals/issues/4 – YashwanthKambala Oct 17 '18 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! – Vivek Kumar Oct 17 '18 at 8:40
  • 2
    You could send them as deferred transactions, then if one failed the others would be fine – Phillip Hamnett - EOS42 Oct 17 '18 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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