Skip to content

Instantly share code, notes, and snippets.

@shanefontaine
Created March 31, 2020 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanefontaine/5bd2a40f6d967748710850d61ebf1bbf to your computer and use it in GitHub Desktop.
Save shanefontaine/5bd2a40f6d967748710850d61ebf1bbf to your computer and use it in GitHub Desktop.
pragma solidity 0.6.4;
/**
* @title ReceiveTest
* @author Shane Fontaine - <shane6fontaine@gmail.com>
* @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);
}
}
@elferno
Copy link

elferno commented Apr 8, 2021

have you solved this problem?

@abdelshok
Copy link

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?

@abdelshok
Copy link

@narayanprusty
Copy link

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