Created
March 31, 2020 15:48
-
-
Save shanefontaine/5bd2a40f6d967748710850d61ebf1bbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.4; | |
/** | |
* @title ReceiveTest | |
* @author Shane Fontaine - <[email protected]> | |
* @notice THIS IS UNAUDITED CODE. DO NOT USE IN PRODUCTION. USE AT YOUR OWN RISK. | |
* @dev Testing Solidity 0.6.x receive() function | |
*/ | |
contract ReceiveTest { | |
uint256 public a = 0; | |
uint256 public b = 0; | |
receive () external payable { | |
// Will fail if `send()` or `transfer()` | |
a = 1; | |
b = 1; | |
} | |
function getBalance() external view returns (uint256) { | |
return address(this).balance; | |
} | |
} | |
contract SendTest { | |
function myTest(address payable _receiveAddress) external payable { | |
_receiveAddress.transfer(msg.value); | |
} | |
} |
I don't understand - I read that if the contract had a receive function then it would get called if a .send or .transfer is made to the recipient contract ?
In this code it says that it the receive() function will fail 'if send() or transfer()' - why is that?
It's because transfer and send have 23000 gas fixed https://solidity-by-example.org/sending-ether/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
have you solved this problem?