2

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.

Earlz
  • 471
  • 4
  • 16

1 Answers1

5

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);
SCBuergel
  • 8,774
  • 7
  • 38
  • 69
  • Cool, that matches what I was thinking it did, but couldn't find any documentation confirming it or even indicating that call can take multiple arguments – Earlz May 03 '17 at 21:08
  • IMO most documentation is still patchy. Please do help other people here or on sites where you find some info missing and would expect it. – SCBuergel May 04 '17 at 08:50