EDIT: I upvoted and recommend @Xavier's answer (@BokkyPooBah's answer is missing ()
at the end).
It's more type-safe and here's an example showing the return value of getX
. You do need to provide non-zero gas:
contract AbstractB {
function getX() returns(uint) {
return 3;
}
}
contract A {
function makeCall(address addressB) returns(uint) {
return AbstractB(addressB).getX.gas(1000)();
}
}
OLD: Use call.gas(g).value(v)(methodId, args)
syntax. Not recommended because not type-safe and you don't get the return value of getX
.
Example: addressB.call.gas(0).value(1 ether)(bytes4(sha3("getX()")));
Complete example, which should always checks the return value of call
:
contract AbstractB {
function getX() returns(uint);
}
contract A {
function makeCall(address addressB){
if (!addressB.call.gas(0).value(1 ether)(bytes4(sha3("getX()")))) {
throw;
}
}
}