Contract A interacts with another contract B, which generally interacts with humans (ie, externally owned accounts). Thus when contract B sends ETH to contract A, contract A needs a fallback function to receive the ETH. I found the function below works, though my linter warns me that this is bad form ('no-empty-blocks'). Where's the danger?

 function() external payable { }

note: There are not multiple users of contract A. Contract B sends ETH using the following command:


I don't see anything wrong with an empty fallback function per se. Your linter is probably not smart enough to understand that even an empty function may be useful in the case of Solidity fallback function - often an empty function (in any programming language) is not the best thing to have.

Note that in Solidity 0.6.x the whole fallback paradigm changes into two separate functions: receive and fallback where receive mostly replaces the current payable fallback functionality. More info: https://solidity.readthedocs.io/en/v0.6.0/contracts.html#receive-ether-function

| improve this answer | |
  • Thanks! My linter is pretty stupid, chastising me for having too many comments and using 'now'.... follow-up Q: 'receive() external payable { }' clearly looks safer--no fallback function!--but it seems redundant. Is there some way in which this is profoundly better than 'function() external payable { }'? – Eric Falkenstein Dec 27 '19 at 17:03
  • The point is to separate the concerns. The receive is for receiving Ethers and the fallback function is the ultimate fallback "if nothing else catches it" - a kind of a backup function. Typically you shouldn't have much use for the new fallback function as callers should know which function they want to call. – Lauri Peltonen Dec 27 '19 at 17:12
  • Cool. Now if they could only fix the bugs in 0.6.0 I could use it (soljson.Pointer_stringify is not a function)! – Eric Falkenstein Dec 27 '19 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.