Here is a step-by-step guide to integrating the SDK into your dApp seamlessly to checkout, cross-chain custom mint function, you can find the complete implementation in this repo
Setup Prerequisites
Ensure you have the following:
Node.js (v16 or higher) installed
TypeScript and ts-node installed
Environment variables configured
Initialize a Node.js project:
mkdir contract-call-example
cd contract-call-example
npm init -y
async function getDepositAddress(contractPayload, fromToken, fromAmount) {
const transferType = TransferType.WALLET; // decides the transfer method
const provider = undefined; // defined in case of onramp or cex
const payload: any = {
userOpHash: "",
transferType,
destinationChainId: destinationToken.chainId?.toString() ?? "",
destinationTokenAddress: destinationToken.address ?? "",
toAmount: baseToAmount,
destinationRecipient: destinationWalletAddress ?? "",
targetCalldata: contractPayload,
// destructure and format the input from fromtoken
fromAmount,
fromChainId,
fromTokenAddress,
fromAddress
};
return aarcCoreSDK.getDepositAddress(payload);
}
const depositData = await getDepositAddress({
contractPayload: callData,
fromToken: { decimals: 18, chainId: 1, address: 'fromTokenAddress' },
fromTokenAmount: '0.01',
});
console.log('Deposit Address:', depositData);
Execute transaction:
const tx = {
to: depositData.depositAddress,
value: ethers.utils.parseEther('0.01'),
data: depositData.txData,
};
const txResponse = await wallet.sendTransaction(tx);
console.log('Transaction Hash:', txResponse.hash);
// Notify Aarc about the transaction hash (this is optional, but recommended to get the status of the transaction faster)
await aarcCoreSDK.postExecuteToAddress({
depositData,
trxHash: txResponse.hash,
});
Poll transaction status:
async function pollRequestStatus(requestId: string) {
let status;
do {
status = await aarcCoreSDK.getRequestStatus(requestId);
console.log('Polling status:', status);
if (status.pollStatus === 'success') {
break;
}
// Wait for 10 seconds before the next iteration
await new Promise(resolve => setTimeout(resolve, 10000));
} while (status.pollStatus !== 'success');
}
// Call the function with the requestId
pollRequestStatus(depositData.requestId);
for more comprehensive implementation of polling refer this
Run the script
npx ts-node contract-call-example.ts
Output Logs:
Wallet balances.
Generated call data.
Deposit address.
Transaction hash.
Polling status updates until completion.
Handle Errors
Use try...catch blocks to manage errors like invalid API keys, insufficient balances, or unavailable routes.
Log descriptive error messages for debugging.
Do input validation and vanity checks.
Notes
Disable transaction execution for testing: Uncomment the throw new Error() line to prevent actual transactions.
throw new Error("Transaction execution is disabled for now. Remove this line to proceed.");
Modify configuration: Adjust the script to your specific use case (e.g., token address, destination chain).