Custom cross-chain call

Call your contract with custom payload on different destination chain

The getDepositAddress function allows developers to interact with contracts on a different destination chain. For instance, if a user holds funds on `Arbitrum` but needs to call a contract on Polygon, they can achieve this seamlessly by generating a deposit address with getDepositAddress and submitting the payload on-chain.

Expected parameters

getDepositAddress accepts following parameters.

Function Call

The getDepositAddress function generates an address based on the provided payload, which must then be funded and submitted on-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 payload: any = {
        // ... remaining params
        destinationRecipient : YOUR_CONTRACT_ADDRESS, 
        targetCalldata: destinationPayload
};

const depositData = await aarcCoreSDK.getDepositAddress(payload); 

// make client sign the generated tx
const { to, value, data, gasLimit, chainId, from } = depositData.txData;
const txHash = await signer.sendTransaction({ to, value, data, gasLimit, chainId, from });

Using onramp for contract call

// Using moonpay for onramp (you can also use kado)
const payload = {
    // rest of the payload,
    transferType: "onramp",  
};

const provider = "moonpay"; 

const url = await aarcCoreSDK.generateMoonpayOnrampUrl({
        walletAddress: depositAddressData.depositAddress,
        defaultCryptoCurrencyCode: depositAddressData.depositTokenSymbol,
        fiatAmount: fromToken.amount_required,
        fiatCurrencyCode: "USD",
        network: "BASE",
        cryptoTokenData: {
          tokenAmount: fromToken.amount_required,
          tokenCode: depositAddressData.depositTokenSymbol ?? "ETH",
        },
      });

const windowRef = window.open(url, "_blank");

For more comprehensive implementation, refer cookbook example.

Last updated