Be sure to respect all the necessary requirements present in V3
1. Open the index.js file in your editor.
2. Replace the placeholder values in the main() function:
async function main() {
try {
console.log('Initializing wallet...');
// Swap example
const swapParams = {
tokenIn: process.env.IN_ADDRESS,
tokenOut: process.env.OUT_ADDRESS,
recipient: wallet.address,
amountOutMinimum: ethers.utils.parseUnits("0", 8), // Minimum USDC expected,
};
console.log('Swapping tokens...');
const receipt = await exactInputSingleSwap(provider, wallet, swapParams.amountIn, swapParams.recipient, swapParams.amountOutMinimum, swapParams.tokenIn, swapParams.tokenOut);
console.log('Swap completed! Transaction hash:', receipt.transactionHash);
} catch (error) {
console.error('An error occurred:', error);
}
}
3. Run the script: