[Ethereum] How to call a function of a deployed contract from another contract

contract-invocationsolidity

How would I call one contract's function from within another contract? I tried to find documentation on this all morning and wasn't able to find anything.

Best Answer

Please find an example here (call part of this section) in solidity documentation where calling an already deployed contract from inside another contract is shown. We can call functions in other deployed contracts using

address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2;
nameReg.call(bytes4(keccak256("fun(uint256)")), a);

Here the first parameter is the function signature and the next parameters are arguments for the function.

Related Topic