Using Multiple Call Arguments in Solidity – What Happens?

eth-callevmsolidity

I have a piece of code like so:

address x=0x01234..;
x.call(data1, data2, data3); 

Will this do what I expect and call the contract at address x while passing the data in concatenated like data1+data2+data3 (and bare, without any solidity ABI formatting)? I can't find any documentation about this.

Best Answer

The low-level .call function allows you to call a function by its function signature calculated as bytes4(sha3("functionName()")). Also take a look at https://ethereum.stackexchange.com/a/9722/16 and Call contract and send value from Solidity. If your function has parameters, the signature looks as follows bytes4(sha3("functionName(uint256,string,address)")) - keep in mind that instead of uint you have to use uint256. The following parameters are the actual values of the parameters. Thus, the whole call would look like

x.call(bytes4(sha3("functionName(uint256,string,address)")), myUIntVal, myStringVal, myAddressVal);

You can also specify a specific gas or value (ether (but in Wei!) to send along) like this:

x.call.value(1234)(bytes4(sha3("functionName(uint256,string,address)")), myUIntVal, myStringVal, myAddressVal);
Related Topic