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?

Thank youenter image description here

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;


I tried to use a fallback function but Remix is not liking it.

pragma solidity >=0.4.0 <0.7.0;

Thank you

enter image description here

  • Attach the full contract code including your solidity version. Commented Sep 30, 2020 at 7:36
  • That is a very weird function and in my opinion doesn't make any sense for learning purposes. Furthermore, your example is from three years ago which is an eternity in blockchain world - I suggest you use some more recent tutorial Commented Sep 30, 2020 at 7:37

1 Answer 1

  1. I used the below fallback function and it worked.

receive() external payable {}

  1. This post was what I was actually looking for in my original question. Everything works well now.

How do you send Ether as a function to a contract using Remix?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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