How error propagate between contracts in Solidity?

jklepatch

Let's say we have 2 smart contracts. A and B. A calls B, and B throws an error.

What happen in A?

Not sure? haha, that's a tricky one!

Actually it depends on how B was called.

If B was called the normal way, the whole transaction get reverted:

contract A {
  function foo() {
   B b = new B();
   b.willThrow();
  }
}
contract B {
  function willThrow() {
    revert();
  }
}

BUT, if B was called with a low-level call() method, the error will NOT be propagated to A. Instead, A will received a false boolean value indicating there was an error in B. This way, A can recover from the error and handle the error itself.

Check out this video where I explain this in full details, as well as other error handling mechanisms in Solidity like assert, revert, require and throw.

By the way, in the Dapp 30 course, there is a bonus section dedicated to debugging in Solidity when I explain in details the different kind of errors in Solidity and how to debug them.

More great articles

New videos on EatTheBlocks: Vue Dapp, Solidity Assembly, Oracle

Tip: If you don't want to miss any updates, checkout the updates page of EatTheBlocks Pro. Vue Dapps The Drizzle…

Read Story

What is Ethereum Gas? Dead simple explanation

When you develop decentralized applications, you quickly stumbled upon this weird concept of "gas". That's very confusing for a lot…

Read Story

Introducing “Smart Contract 30”, a 30-day course on Solidity

Are you a beginner learning Solidity? Are you overwhelmed by the complexity of developing an Ethereum smart contract and don't…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.

    Only great content, we don’t share your email with third parties.
    Arrow-up