39: Calling Other Contracts
Calling Other Contracts
contract ContractA {
ContractB b;
constructor(ContractB _b) public { b = _b; }
function callContractB() public {
b.delegatecall(bytes4(keccak256("foo()")));
}
}
contract ContractB {
function foo() public { // Do something }
}contract ContractA {
ContractB b;
constructor(ContractB _b) public { b = _b; }
function callContractB() public {
(bool success, uint256 result) = b.call(
bytes4(keccak256("foo()"))
);
}
}
contract ContractB {
function foo() public returns (uint256) { return 42; }
}Conclusion
Last updated