I am trying to send ether from contract to a wallet, when I use the call function with msg.value it works, however when I try to send 1 ether instead of msg.value it doesn't work. Why is that and how to overcome this? I am using Remix.io Javascript VM London, can that be the reason?
Here this code below works:
function sendMoney() public payable {
address payable receiver = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2);
(bool sent, bytes memory data) = receiver.call{ value: msg.value }("");
require(sent, "Failed to send Ether");
}
However this code below doesn't work. I have to send fixed amount of ether.
function sendMoney() public payable {
address payable receiver = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2);
(bool sent, bytes memory data) = receiver.call{ value: 1 ether }("");
require(sent, "Failed to send Ether");
}
sendMoney() public payable {
address payable receiver =
payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2);
(bool sent, bytes memory data) = receiver.call{ value: 1 ether }("");
require(sent, "Failed to send Ether");
}
This works. You just need to pass something in "value" in remix, and after 1 ether will be transfered to 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 and value that you passed in remix will be transfered to contract balance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.