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?

eth
  • 85,679
  • 53
  • 285
  • 406
Simon de la Rouviere
  • 1,224
  • 10
  • 18

1 Answers1

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.

0xSanson
  • 3,114
  • 2
  • 11
  • 23
Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118
  • To clarifiy, you will still pay the cost of the CALL? – Simon de la Rouviere Feb 17 '16 at 13:34
  • Yes, but it will be pretty nominal. The same amount of gas as just sending ETH – Tjaden Hess Feb 17 '16 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 '22 at 11:22