i came to know that 'call' method is better for transacting, since all gas is transferred and could withstand reentrancy attack.. but how should we define fallback function for 'call' method? using solidity ^0.6.0

Should we use fallback() external payable{} or receive() external payable {} ? when i used fallback() external payable{} remix gave me this warning

Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function. contract MultiSig{ ^ (Relevant source part starts here and spans across multiple lines). browser/wallet.sol:37:5: The payable fallback function is defined here. fallback() payable external {}

Please explain which fallback function to be used for this scenario and in general what should be used when? And also how will it guard against reentrancy?


1 Answer 1


receive() be run just at times your contract receives some ethers. fallback() be run just at times a function called at your contract that it doesn't exist there. So, if you want to send some ethers to your contract it's better that you use receive(). But, if needed you can use both them in your contract. You can read this to more information.

Before, there was one fallback function that was shawn function() external payable{} in Solidity that performed both mentioned tasks. Since version 0.6.0 the two tasks seperated from eachother and receive() and fallback() concluded.

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