I learned from this documentation https://docs.soliditylang.org/en/v0.8.15/contracts.html and this discussion How to use address.call{}() in solidity about abi.encodeWithSignature()
.
I have question about this snippet below.
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; } }
Then we have the caller
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; } }
-
I am wondering this line
(bool success,) = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));
What could come after the comma
(bool success, **What other parameters could fit here?**)
? -
If that line only returns
bool success
, then why we need to put it in a bracket with comma(bool success,)
? Why can’t we just putbool success = address(test).call(abi.encodeWithSignature("nonExistingFunction()"));
-
Is
nonExistingFunction()
a default reserved function name to call no-name fallback function from other smart contract?
I can’t find this information in the official documentation.