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
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.