1

a user send 10 ethers to Smart Contract A, then Smart Contract A send 10 ethers to Smart Contract B.

Would that be 2 transactions, or 1 transactions?

(What I heard is that the answer is 1, why is that?)

1 Answer 1

0

It's one transaction.

Transactions are..well, transactional. Either everything succeeds or everything is rolled back (with some exception, noted below). It's all done in one transaction.

If you initiate a transaction to some contract you may not even know what the contract does. Maybe it contacts another contract or ten different contracts - it does not matter what it does because everything is encapsulated within the same transaction. And no matter what happens, you (the sender) pay for it all because you initiated the transaction.

Nodes have to be able to process the whole transaction. If something goes wrong (maybe a require fails or the transaction runs out of gas) the whole transaction is typically reverted. Only if some lower-level contract calls fail it may not result in the whole transaction being reverted but only that specific call being reverted within the transaction - depending on implementation.

3
  • Thanks Laurie, just one quick question: The reason behind it is because smart contract won't do anything spontaneously? It would only send ethers to other smart contract automatically when it receives ethers from some users. Thus, the transaction between 2 smart contract A and B is triggered by TX between User and Contract A, which is why this is thought as one transaction?
    – Jason Wang
    May 17, 2018 at 20:43
  • Correct. Contracts can never spawn transactions on their own - someone from the outside always triggers (and pays) for anything that happens. May 17, 2018 at 20:46
  • 1
    "If something goes wrong (maybe a require fails or the transaction runs out of gas) the whole transaction is reverted." This isn't completely true. The EVM doesn't stipulate anything about a child call reverting making the entire transaction revert, it only reverts its call. Of course Solidity bubbles these up unless you do lower level calls that return true/false instead of reverting on failure.
    – natewelch_
    May 18, 2018 at 3:03

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.