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
asyncfunctiongetMultichainBalance(address:string) {// this will fetch balances of user in terms of destination tokenreturnawaitaarcCoreSDK.fetchMultiChainBalances(address, { tokenAddress:destinationToken.address, tokenChainId:destinationToken.chainId, tokenAmount: requestedAmount, });}constbalances=awaitgetMultichainBalance(wallet.address);console.log('Balances:', balances);
asyncfunctiongetDepositAddress(contractPayload, fromToken, fromAmount) {consttransferType=TransferType.WALLET; // decides the transfer methodconstprovider=undefined; // defined in case of onramp or cexconstpayload: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 };returnaarcCoreSDK.getDepositAddress(payload);}constdepositData=awaitgetDepositAddress({ contractPayload: callData, fromToken: { decimals:18, chainId:1, address:'fromTokenAddress' }, fromTokenAmount:'0.01',});console.log('Deposit Address:', depositData);
Execute transaction:
consttx= { to:depositData.depositAddress, value:ethers.utils.parseEther('0.01'), data:depositData.txData,};consttxResponse=awaitwallet.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)awaitaarcCoreSDK.postExecuteToAddress({ depositData, trxHash:txResponse.hash,});
Poll transaction status:
asyncfunctionpollRequestStatus(requestId:string) {let status;do { status =awaitaarcCoreSDK.getRequestStatus(requestId);console.log('Polling status:', status);if (status.pollStatus ==='success') {break; }// Wait for 10 seconds before the next iterationawaitnewPromise(resolve =>setTimeout(resolve,10000)); } while (status.pollStatus !=='success');}// Call the function with the requestIdpollRequestStatus(depositData.requestId);
for more comprehensive implementation of polling refer this
Run the script
npxts-nodecontract-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.
thrownewError("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).
Now you can checkout to a cross-chain contract call with different payment methods. 🎉