I added the below three functions to my deployed contract as described in the article https://programtheblockchain.com/posts/2017/12/15/writing-a-contract-that-handles-ether/
I deployed using Remix on Rinkeby. When I enter 1 Ether into the Deposit transaction in Remix I get the "Gas Estimation Failed" Error.
Why is the Deposit function generating an error?
function withdraw() public {
msg.sender.transfer(address(this).balance);
}
function deposit(uint256 amount) payable public {
require(msg.value == amount);
// nothing else to do!
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
Update
I tried to use a fallback function but Remix is not liking it.
pragma solidity >=0.4.0 <0.7.0;
Thank you
Best Answer
receive() external payable {}
How do you send Ether as a function to a contract using Remix?