Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 如何撤销部分智能合约';账户上的余额是多少?_Ethereum_Solidity_Transfer_Smartcontracts_Ether - Fatal编程技术网

Ethereum 如何撤销部分智能合约';账户上的余额是多少?

Ethereum 如何撤销部分智能合约';账户上的余额是多少?,ethereum,solidity,transfer,smartcontracts,ether,Ethereum,Solidity,Transfer,Smartcontracts,Ether,我已经研究了许多类似的问题,但它们只涉及将智能合约的全部余额转移到个人帐户,操作如下: msg.sender.transfer(地址(this.balance)) 我试图(但未能)弄清楚的是如何转移部分余额。如果合同中有3个乙醚,我只想转让1个。我希望能够指定每次使用该函数时要传输的金额。我没有发布我的代码,因为我尝试过的任何东西都不起作用,这几乎是猜测 谢谢你的帮助 function withdraw(uint amount) public { msg.sender.transfer(

我已经研究了许多类似的问题,但它们只涉及将智能合约的全部余额转移到个人帐户,操作如下:

msg.sender.transfer(地址(this.balance))

我试图(但未能)弄清楚的是如何转移部分余额。如果合同中有3个乙醚,我只想转让1个。我希望能够指定每次使用该函数时要传输的金额。我没有发布我的代码,因为我尝试过的任何东西都不起作用,这几乎是猜测

谢谢你的帮助

function withdraw(uint amount) public {
    msg.sender.transfer(amount);
}

提取使用
amount
变量指定的金额。无需检查合同的总余额,因为如果您尝试提取的金额超过总余额,它将恢复。

在转移前检查合同是否有该笔代币是一个好做法。“在转移前检查合同是否有该笔代币是一个好做法”为什么?我是说写一份必要的声明。因此,如果出现错误,请保存一些gas,我想这取决于函数正在执行的操作。@ferit,谢谢。另一个问题是,我希望将金额转移到另一个帐户,而不是msg.sender,但是如果我在那里放置另一个地址变量,我会得到一个编译错误“member transfer not found”,就像它在结构中查找一样。你能帮我吗?