How does Solidity ".call" work?

tcimolitcimoli Cagliari - ItalyMember Posts: 35
edited May 2016 in Solidity
I want to invoke a method on a contract from another contract using call.

If the method has no parameters, it works fine, otherwise it doesnt.

For instance, this:
secondContract.call.value(3).gas(20764)( bytes4(sha3("ping()")));
invokes the method ping on SecondContract , sending also 3wei and limiting gas usage to 20764.

But in case the method has one parameter, what should I write?

(from here)

Comments

  • tcimolitcimoli Cagliari - ItalyMember Posts: 35
    edited January 2017
    Ok, I found out . Here is an example. Let's assume I have a function which take an integer parameter:
    function setCounter(uint n){ counter = n; }
    then, its calling (to set the counter to 4) would be:

    sec.call.gas(20764)( bytes4(sha3("setCounter(uint256)")), 4);

    (!!!! Please notice that the signature of the function says uint256. I was trying uint (as the declared function says) but in that way it does not work.)

    I found the solution reading this, where basically they says that they hash the signature of the function and they use the first 4bytes to get the index.



    Post edited by o0ragman0o on
Sign In or Register to comment.