3

If a contract calls several external methods of other contract(s), is it as a whole one atomic transaction (reverted as a whole if an exception happens)?

1 Answer 1

6

Mostly yes.

When a transaction is initiated to a contract all the actions caused by the transaction are included in the same transaction. This includes everything: calling the original contract, calls inside that contract to different functions and all calls to external libraries and contracts (and also possible calls from those contracts onwards).

All actions cost some gas. So the more there are actions the more gas is consumed. You, as the transaction initiator, have to be prepared to pay for all of these actions by specifying high enough a gas limit.

However it is possible to have exceptions in contracts which do not cause for the whole transaction to fail - depends on how the calls to other contracts are initiated. Here's some more info: does revert()/require() revert changes made to other contracts? . One more example is the use of new try/catch keywords: https://blog.ethereum.org/2020/01/29/solidity-0.6-try-catch/

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.