地址(this).send(msg.value)返回false但以太词被转移
以下是我的功能:
// Function
function deposit() payable external {
// if(!wallet_address.send(msg.value)){
// revert("doposit fail");
// }
bool isErr = address(this).send(msg.value);
console.log(isErr);
emit Deposit(msg.sender, msg.value, address(this).balance);
}
我使用具有坚固性版本0.8.7的Remix IDE,我的问题是为什么Send()返回false,但Ethers转移了。默认情况下,send()返回false吗?
Below is my function:
// Function
function deposit() payable external {
// if(!wallet_address.send(msg.value)){
// revert("doposit fail");
// }
bool isErr = address(this).send(msg.value);
console.log(isErr);
emit Deposit(msg.sender, msg.value, address(this).balance);
}
I use Remix IDE with solidity version 0.8.7 and my question is why send() returns false but the ethers got transferred. Is send() returns false when it success by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
地址(this).send(msg.value)
有效地创建了不必要的内部交易,将“ 此合同”接受的价值重定向到“ 此合同“此内部交易失败了,因为您的合同无法实现
receard()
norhallback()
特殊功能接受从send()
,),transfer()
,呼叫()在某些情况下,通常没有调用任何特定现有函数的任何事务(内部或主)。它不会使主要事务失败,只需从send> send()
方法返回false
。TLDR:
send()
函数在这种情况下是冗余的,您可以安全地将其删除。即使没有它,您的合同也能够从存款()
功能中接受ETH。address(this).send(msg.value)
effectively just creates an unnecessary internal transaction redirecting the value accepted by "this contract" to "this contract"This internal transaction fails because because your contract does not implement the
receive()
norfallback()
special functions that are needed to accept ETH sent to your contract fromsend()
,transfer()
,call()
in some cases, and generally any transaction (internal or main) that does not invoke any specific existing function. It does not fail the main transaction, just returnsfalse
from thesend()
method.TLDR: The
send()
function is in this case redundant and you can safely remove it. Your contract is able to accept ETH from thedeposit()
function even without it.它是低级功能调用,转移步骤后可能会失败。如果您不检查
成功
变量,则编译器警告您可以恢复呼叫,并且您可能不知道您忽略了失败。因此,您应该检查
成功
变量,以确保交易成功。It is low level function call, it can fail in after transfer step. If you don't check
success
variable, the compiler is warning you that the call could revert and you might carry on unaware that you ignored failure.So you should check
success
variable to ensure transaction is success.