const { ethers } = require('ethers'); const { Token, CurrencyAmount, Percent, TradeType…
- User
const { ethers } = require('ethers'); const { Token, CurrencyAmount, Percent, TradeType } = require('@uniswap/sdk-core'); const { Pool, Route, Trade, SwapRouter } = require('@uniswap/v3-sdk'); const IUniswapV3PoolABI = require('@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json').abi; const Quoter = require('@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json').abi; const IERC20 = require('@uniswap/v2-periphery/build/IERC20.json');
const SWAP_ROUTER_ADDRESS = '0xE592427A0AEce92De3Edee1F18E0157C05861564';
const WALLET_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'; const WALLET_SECRET = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'; const INFURA_TEST_URL = 'https://mainnet.infura.io/v3/2d5bc62bb8d748cebfc64763e719cb4f'; const POOL_FACTORY_CONTRACT_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984'; const QUOTER_CONTRACT_ADDRESS = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6';
const provider = new ethers.providers.JsonRpcProvider(INFURA_TEST_URL); const chainId = 1;
const wallet = new ethers.Wallet(WALLET_SECRET, provider);
const token0 = new Token(chainId, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'); const token1 = new Token(chainId, '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', 18, 'UNI', 'Uniswap Token');
const fee = 3000; // Change the fee tier as required (500 for low, 3000 for medium, and 10000 for high)
async function main() { try { const poolInfo = await getPoolInfo();
code - Assistant
It seems that there's an error in
getTokenTransferApprovalfunction when you call theapprovemethod. The function receives aswapRouteobject which is a Route instance, but instead it should receive the Swap Router's address. You can replace thegetTokenTransferApprovalfunction call with the correct address:javascriptawait getTokenTransferApproval(token0.address, SWAP_ROUTER_ADDRESS);After you make this change, you should no longer get the "invalid address or ENS name" error.
- User
i still get it
- Assistant
Apologies for the confusion earlier. I've taken a closer look at the code, and it seems there is an issue in the way
getPoolInfo()method is implemented. ThePoolobject expects input amounts in theBigIntformat. You can update the method as follows:javascript - User
- Assistant
Apologies for the confusion earlier. I've taken another deeper look at the code and noticed that the error is caused by the initialization of the
txobject. ThegasLimitand other properties are Promises, which is causing the issue. You shouldawaitthese properties to get their actual values, then use that for thetxobject.Here is the updated
sendTransactionfunction which resolves the promises before creating thetxobject:javascript - User
- Assistant
I see that the official example code is slightly different from your existing code. I've updated your existing code based on the official example. Please find the updated code below:
javascript