Solidity
address.call{}(abi.encodeWithSignature()) 在solidity中返回布爾值和其他哪些參數?
我從這個文件https://docs.soliditylang.org/en/v0.8.15/contracts.html和這個討論中學到了How to use address.call{}() insolidity about
abi.encodeWithSignature()
.我對下面的這個片段有疑問。
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?**)
? 2. 如果該行只返回bool success
,那麼為什麼我們需要用逗號將其放在括號中(bool success,)
?為什麼我們不能把bool success = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));
3. 是否有nonExistingFunction()
一個預設的保留函式名來呼叫其他智能合約的無名回退函式?我在官方文件中找不到此資訊。