Execute Transaction

NOTE: We are using ethers v6.9for the signer object.

When you receive the calldata from the /bridge-swap/deposit-calldata it needs to be signed to get executed.

To get the data signed and executed, go through the following steps:

  1. Get the the call data.

const BASE_URL = "https://bridge-swap.aarc.xyz";

const endPoint = `${BASE_URL}/deposit-calldata?recipient=${recipient}&routeType=${routeType}&fromChainId=${fromChainId}&fromTokenAddress=${fromTokenAddress}&toChainId=${toChainId}&toTokenAddress=${toTokenAddress}&fromAmount=${fromAmount}&userAddress=${userAddress}`;

const depositCalldataResponse = await fetch(endPoint, {
  method: "GET",
  headers: {
    "x-api-key": "AARC_API_KEY",
    Accept: "application/json",
    "Content-Type": "application/json",
  },
});

const responseInJson = await depositCalldataResponse.json();
  1. Get the approval txns data and execution txns data in separate variables.

const approvalTxsData = responseInJson.data.approvalTxs;
const executionTxsData = responseInJson.data.executionTxs;
  1. Execute the approval transactions.

for (let i = 0; i < approvalTxsData.length ; i++)
{
    await signer.sendTransaction({
        from: signer.address,
        to: approvalTxsData[i].approvalTokenAddress,
        data: approvalTxsData[i].calldata
    });
}
  1. Execute the execution transactions.

for (let i = 0; i < executionTxsData.length; i++)
{
    await signer.sendTransaction({
        from: signer.address,
        to: executionTxsData[i].txTarget,
        data: executionTxsData[i].txData
    });
}

Awesome! Your funds are transferred

Last updated