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);
}