-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (26 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require('dotenv').config();
const { ethers } = require('ethers');
const {
exactInputSingleSwap,
} = require('./src/v3_swap_functions');
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
async function main() {
try {
console.log('Initializing wallet...');
// Swap example
const swapParams = {
tokenIn: process.env.WETH_ADDRESS,
tokenOut: process.env.USDC_ADDRESS,
recipient: wallet.address,
amountIn: ethers.utils.parseUnits("0.001", 18),
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);
}
}
main();