Let's say I want to interact with a contract but I don't know the ABI of this contract. Via the UI I know which functions are called (by inspecting the transaction).

How do I call these functions in a solidity?


You create an interface and you can call it (provided you know the address of the contract).

contract contractX {
  function methodY(uint param1) public pure returns (int);

contract KnownContract {
  address unknownContractAddress = '0x0123...';

  function callFriendContract(uint param1) public {
     uint res = contractX(unknownContractAddress).methodY(param1);
| improve this answer | |
  • I see, but doesn't this need you to know the ABI? How does the compiler know at what (code) address it has to JUMP to? – JBrouwer Mar 29 '18 at 14:58
  • No, you don't need to know the ABI for that. – Elisha Drion Mar 29 '18 at 16:00
  • You do not need the ABI if you know the interface. The answer from @mirg assumes that you know the functions. The interface doesn't need to define the implementation of the functions is enough to know the name and what parameters take in and what parameters return. – Jaime Mar 29 '18 at 16:23
  • You need the ABI to call it from web3 not from Solidity – mirg Mar 29 '18 at 16:45
  • I see, but the compiler needs to know some kind of order here to call the right address of this function? If I have two functions which have a boolean as input and return a boolean, how do I call function 1 and how do I call function 2? – JBrouwer Mar 30 '18 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.