when i run this script, this error keep showing “Contract Address: 0xe592427a0aece92de3edee1f18e0157c05861564
Error in getUniswapV3Rate: TypeError: Cannot read properties of undefined (reading ‘exactInputSingle’)”
Why is that? in ABI file this ‘exactInputSingle’ is already included
Snippet from my script:
async function getUniswapV3Rate(fromToken, toToken, amount) {
try {
const uniswapV3Router = new ethers.Contract(addresses.uniswapV3Router, UniswapV3RouterABI, provider);
const params = {
tokenIn: fromToken,
tokenOut: toToken,
fee: 3000,
recipient: ethAddress,
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
amountIn: amount.toString(), // Ensure amount is a string
amountOutMinimum: 0,
sqrtPriceLimitX96: 0,
};
console.log('Params:', params);
console.log('Contract Address:', addresses.uniswapV3Router);
if (!uniswapV3Router.functions.exactInputSingle) {
throw new Error('exactInputSingle method not found in Uniswap V3 Router ABI');
}
const quote = await uniswapV3Router.callStatic.exactInputSingle(params);
console.log('Quote:', quote);
return new BigNumber(quote.toString());
} catch (error) {
console.error(‘Error in getUniswapV3Rate:’, error);
return new BigNumber(0); // Return zero if there’s an error
I tired to get current price rates of certain tokens from uniswapv3 router
Bmroxx Roxx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.