Contract Call

Call contract on different destination chain

The performCheckout function enables developers to call a contract on a different destination chain. For example, if a user has funds on arbitrum and wants to call a contract on polygon, they can easily do so using the performCheckout function.

Expected parameters

performCheckout accepts following parameters

ParameterTypeDescription

senderSigner

ethers.Signer

The signer object from ethers

fromChainId

number

Source chain id

fromTokenAddress

string

address of initial token on source chain

toChainId

number

Chain id of the destination chain

toTokenAddress

string

Address of the final token on the destination chain.

fromAddress

string

Address of source chain from which smart contract is being called

toAmount

string

Amount needs to be send to destination chain for contract call.

targetContractAddress

string

Smart contract address of destination chain.

destinationPayload

string

Call data of a contract call

routeType [Optional]

string

The type of route to be preferred. It can be Value,Fee and Time, default route is Value

destinationGasLimit

number

The gas limit on the

destination chain.

estimateGas [Optional]

boolean

Default is set to true. If you don't want to estimate gas on the backend.

Function Call

performCheckout function will initiate all required transactions on source chain such as getting an approval and sending tokens and calling contract on destination chain.

const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

const address = signer.getAddress();
const contractInterface = new ethers.Interface(ABI); // create interface with your own ABI

const destinationPayload = contractInterface.encodeFunctionData("mint", [
  address,
  1000000000000,
]); // Replace with your own function name and parameters

const tx = await aarcSDK.performCheckout({
  toChainId: polygon.id,
  fromChainId: arbitrum.id,
  destinationPayload,
  destinationGasLimit: 2000000, // Change gas limit as per your requirement
  fromAddress: address, 
  toTokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Replace with your token Address
  fromTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548", // Replace with your token Address
  targetContractAddress: "0x6D8473f39AB16b7aE854d90acDcCDC83fa3A32b4", // Replace with your contract Address
  senderSigner: signer,
  toAmount: "10000000", // Amount of token needs to be send to contract
});

console.log('tx', tx);

Last updated