我有一个来自 Solidity 的问题,我的 IDE 使用的是 Remix,我想给自己寄一些钱。
我的代码:
pragma solidity ^0.4.24;
contract toMyself{
address owner;
function toMyself()public{
owner = msg.sender;
}
function Send(uint x)public payable{
owner.transfer(x);
}
}
但是当我按下“发送”按钮时,它会向我显示一条消息,例如:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
如何修复它?
最佳答案
您确定合约有足够的以太币可供发送吗?
你不喜欢切换
function Send(uint x)public payable{
owner.transfer(x);
}
至
function Send()public payable{
owner.transfer(msg.value);
}
那么您将智能合约中的内容发送给所有者?
此外,您还可以通过以下方式发回刚刚发送到 msg.sender 的数量:
function SendBack() public payable{
msg.sender.transfer(msg.value);
}
但这最终会毫无用处并浪费一些gas。
关于Solidity:给自己寄点钱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54615202/