10

Let's say you call a function at another contract in Solidity:

contractB.doFunction()

It would then match it using the function signature to run the function in contractB. If there's not match, it would run the fallback function.

But if neither exists? What happens? Does it throw an error, or would you just expend the cost of the CALL?

1 Answer 1

12

(Edit) Solidity >= 0.4.0

The call will revert. You'll still pay a small amount of gas since the called contract will execute it's "function dispatcher" trying to find the right selector before reverting. Any ETH sent will be sent back, like any other reverting calls.

Solidity <= 0.3.6

The call will simply return immediately. There will be no code executed, but any value sent with the transaction will remain with the recipient contract. In fact, it will be as if you just sent ether to the contract (note that the value of the transaction can be 0). All extra data (including the ABI) will be ignored.

3
  • To clarifiy, you will still pay the cost of the CALL? Feb 17, 2016 at 13:34
  • Yes, but it will be pretty nominal. The same amount of gas as just sending ETH Feb 17, 2016 at 14:02
  • 1
    I tried this but it doesn't work anymore. I have made 2 contracts A and B. Written receive() ex..{ for A and through B , I am calling function in A which doesn't exist. The txn simply reverts and no ether is sent to the A contract. I checked this with from a function in A which returns address(this).balance
    – 0xAnon
    Aug 30, 2022 at 11:22

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.