Here's an example from solidity docs on Address type methods(call
method specifically):
address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2;
nameReg.call("register", "MyName");
nameReg.call(bytes4(sha3("fun(uint256)")), a);
I can't understand what the second line does. Does it call the fallback function with these two arguments? Or does it pass string MyName to function register on nameReg contract?
Best Answer
From the link in the question, the important part about
nameReg.call("register", "MyName")
is (bold mine):See the note here:
nameReg.call("register", "MyName")
will not invokeregister
on anameReg
contract compiled by Solidity. The reason is that Solidity does not use "register" to lookup "functions" (it uses the first 4 bytes as the method id. For example EVM pseudocode that Solidity produces, see this). Here's code for a quick test:With a
nameReg
contract compiled by Solidity,nameReg.call("register", "MyName")
will invoke the fallback function wheremsg.data
will be "register", "MyName" padded to 32 bytes and concatenated:0x72656769737465720000000000000000000000000000000000000000000000004d794e616d650000000000000000000000000000000000000000000000000000
.