如何以坚固性将()或转移()从合同地址发送到帐户地址(我的意思是从地址(this).balance扣除)
部署合同时,它会有一个可以按地址调用的地址。我的合同是从一个地址收到的,这意味着我可以将()或转移()转移到本合同中,但是如果我想将此实际合同转移到任何帐户,我该怎么办?
示例代码:
function submitTransaction(address _to,uint _value,string memory _desc) public
onlyOwner
{
require(_value <= address(this).balance,"This wallet does not have enough balace to send");
if(!_to.send(_value)){
revert("doposit fail");
}
}
但是如何从地址(此)扣除?
When the contract is deployed it has an address that we can call by address(this). My contract is receivable from an address which means I can send() or transfer() to this contract but If I want to transfer from this actual contract to any account how can I do that?
example code:
function submitTransaction(address _to,uint _value,string memory _desc) public
onlyOwner
{
require(_value <= address(this).balance,"This wallet does not have enough balace to send");
if(!_to.send(_value)){
revert("doposit fail");
}
}
but how can I deduct from address(this).balance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以看到此智能合约代码的示例:
建议:在这种情况下,如果您只使用转移或发送,我建议您使用
transfer()
方法而不是<代码> send(),因为如果传输不起作用,它会导致故障。我建议阅读此 thread 。相反,要避免重新输入攻击,您必须对呼叫
方法进行转移以太。You can see this example of smart contract code:
ADVICE: In this case, if you want use only transfer or send, I advice you to use
transfer()
method insteadsend()
, because it throws on failure if transfer didn't work. I recommend to read this thread. On the contrary for avoid reentracy attack you must tocall
method to transfer ether.不要使用
安全
如果您没有充分的理由,请改用Transfer
。传输
在发生故障的情况下会丢失错误,而Safe
方法只会返回false
,这意味着代码的下一行将仍然可以执行,如果您不处理错误,交易将不会恢复。Don't use
safe
if you don't have a good reason, usetransfer
instead. Whiletransfer
will throw an error in case of a failure, thesafe
method will just returnfalse
, which means the next lines of the code will still be executed and the transaction will not be reverted if you don't handle the error.