Solidity:给自己寄点钱

标签 solidity remix

我有一个来自 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?

如何修复它?

最佳答案

  1. 您确定合约有足够的以太币可供发送吗?

  2. 你不喜欢切换

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/

相关文章:

java - 在Web3j中生成Java Wrapper时出错

solidity - 使用 ethers js 运行安全帽测试时,契约(Contract)事件监听器未触发

ethereum - 将用户地址与数组中定义的地址相匹配的可靠方法

testing - 如何在松露中测试具有多个帐户/地址的契约(Contract)?

ethereum - 我如何计算以美元为单位的交易成本

java - 在 Web3j 中监听事件

ethereum - 如何在松露中手动创建合约的实例

boolean - Solidity:为什么错误的输入将我的 boolean 值设置为 "true"?

ethereum - Solidity Remix 简单问题