import { ethers } from "ethers";
// ERC20 ABI for approval
const erc20ABI = [
"function approve(address spender, uint256 amount) external returns (bool)",
];
// Contract ABI for the function you want to call
const contractABI = [
"function purchaseWithUSDC(address to, uint256 usdcAmount) external",
];
// Encode approval transaction
const erc20Interface = new ethers.Interface(erc20ABI);
const approvalData = erc20Interface.encodeFunctionData("approve", [
"0xContractAddress", // Contract that will spend tokens
"1000000000", // Amount to approve (1000 USDC with 6 decimals)
]);
// Encode contract call transaction
const contractInterface = new ethers.Interface(contractABI);
const contractCallData = contractInterface.encodeFunctionData(
"purchaseWithUSDC",
[
"0x742d35Cc6634C0532925a3b8D9d4DB0a2D7DD5B3", // recipient
"1000000000", // 1000 USDC
]
);
const quoteRequest = {
user: "0x742d35Cc6634C0532925a3b8D9d4DB0a2D7DD5B3",
originChainId: 1,
destinationChainId: 8453,
originCurrency: "usdc",
destinationCurrency: "usdc",
amount: "1000000000", // Amount required for call (1000 USDC with 6 decimals)
tradeType: "EXACT_OUTPUT",
txs: [
{
to: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", // USDC contract address
value: "0",
data: approvalData,
},
{
to: "0xContractAddress",
value: "0",
data: contractCallData,
},
],
};