1

I am trying to send ether from one wallet to another. The receivers wallet and the ether amount is hard coded in contract. This is how the contract looks. I am using the Remix IDE with injected provider - Meta Mask as the environment

pragma solidity ^0.8.15;
// SPDX-License-Identifier: MIT


contract sendeth{

    
    address payable public target = payable(xxxxwalletAddress);
    uint public etherAmount = 1 ether;


    function sendEth() public payable {
        payable(target).transfer(etherAmount);
    }

}

It gives me an error:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Returned error: {"jsonrpc":"2.0","error":"execution reverted","id":2658715818644854}

However if I enter 1 ether in the Remix IDE "Value" field it allows me to send the ether. I do not want to do that as the ether value is hard coded in the contract. Am I missing something here?

I also tried using the msg.value but that does not work either:

function sendEther() public payable {
        require(msg.value == etherAmount, "Incorrect Ether amount sent");
        payable(target).transfer(msg.value);      
       
        
    }

1 Answer 1

0

What you're asking for is simply impossible, the amount of ether sent by a transaction is decided by the sender, you can't pull ether from a wallet with a smart contract. You can require that the value sent be equal to a specific amount though, like in your second example.

1
  • The sender will have the option of checking the amount of ether that is required to be sent and then click the transfer button. However the question was, does the Remix IDE allow a user to send ether without using the default "value" input field.
    – isenhiem
    Mar 17 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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