contract A { // This doesn't have to match the real contract name. Call it what you like.
function f1(bool arg1, intuint arg2) returns(uint); // No implementation, just the function signature. This is just so Solidity can work out how to call it.
}
contract YourContract {
function doYourThing(address addressOfA) returns(uint) {
A my_a = A(addressOfA);
return my_a.f1(true, 3);
}
}
Also, if f1
encounters an exception (imagine its implementation is function f1(bool arg1, intuint arg2) returns(uint) { throw; }
), the exception is propagated and my_a.f1
will also throw
and it will revert a transaction that invoked doYourThing
.
In practice, you'll have 3 files.
AbstractA.sol contains:
contract A {
function f1(bool arg1, uint arg2) returns(uint); // No implementation, just the function signature. This is just so Solidity can work out how to call it.
}
YourContract.sol contains:
import "AbstractA.sol"
contract YourContract {
function doYourThing(address addressOfA) returns(uint) {
A my_a = A(addressOfA);
return my_a.f1(true, 3);
}
}
A.sol contains:
contract A {
// implementation of f1
function f1(bool arg1, uint arg2) returns(uint) {
if (arg1) {
throw;
} else {
return arg2;
}
}
}
Also, the return value of f1
can't be obtained by using call
like addressOfA.call(bytes4(sha3keccak256("f1(bool, int256uint256)")), true, 3)
because call
only returns a bool
(false
if the call encounters an exception).
if (!addressOfA.call(bytes4(sha3keccak256("f1(bool, int256uint256)")), true, 3)) {
throw;
}