我从这个文档中学到了https://docs.soliditylang.org/en/v0.8.15/contracts.html和关于abi.encodeWithSignature()的讨论如何在实体中使用address.call{}()。
我对下面这个片段有疑问。
contract TestPayable {
uint x;
uint y;
// This function is called for all messages sent to
// this contract, except plain Ether transfers
// (there is no other function except the receive function).
// Any call with non-empty calldata to this contract will execute
// the fallback function (even if Ether is sent along with the call).
fallback() external payable { x = 1; y = msg.value; }
// This function is called for plain Ether transfers, i.e.
// for every call with empty calldata.
receive() external payable { x = 2; y = msg.value; }
}然后我们找到了来电者
contract Caller {
function callTestPayable(TestPayable test) public returns (bool) {
(bool success,) = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));
require(success);
// results in test.x becoming == 1 and test.y becoming 0.
(success,) = address(test).call{value: 1}(abi.encodeWithSignature("nonExistingFunction()"));
require(success);
// results in test.x becoming == 1 and test.y becoming 1.
return true;
}
}(bool success,) = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));在逗号(bool success, **What other parameters could fit here?**)之后会发生什么?bool success,那么为什么我们需要将它放在带有逗号(bool success,)的括号中呢?为什么我们不能把bool success = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));nonExistingFunction()是一个默认的保留函数名,可以调用其他智能契约中的无名称回退函数吗?我在官方文件中找不到这方面的信息。
发布于 2022-06-20 10:34:33
发布于 2022-06-20 09:36:20
https://ethereum.stackexchange.com/questions/130496
复制相似问题