Calling Other Contract

EVM

contract A {
  address private _hello = 0x6e110......011e6;
  
  function hello() external {
    IHello(_hello).hello(10);
  }
}

interface IHello {
  function hello(uint256 times) external;
}

contract Hello {
  mapping(address caller => uint256 times) public contacted;
  
  function hello(uint256 times) external {
    contacted[msg.sender] += times;  
  }
}

Solana

In Solana it is called cross-program invocation (CPI). To make a CPI you need to provide the program address, accounts and arguments.

A signature is sometimes required (e.g. the destination program pulls funds from source program accounts) and you can use new_with_signer to create the context

Without using cpi

Last updated