I wanted to get a quote for WETH/USDC using ether on testnet(sepolia). To the best of my knowledge being a newbie in web3, I think my code looks decent but when I try get the quote I get an error.
I keep getting an error complaining with an error code CALL_EXCEPTION
and then shows me the version of ether being used(I guess) version=6.7.1
with no proper revert data.
Code snippet
import { ethers } from 'ethers';
import dotenv from 'dotenv';
dotenv.config();
console.log('Starting detection bot...');
// Abi for the Quoter
const QUOTER_ABI = [
"function quoteExactInputSingle(address,address,uint24,uint256,uint160) external returns (uint256)"
];
const UNISWAP_FACTORY_ABI = [
"function getPool(address,address,uint24) external view returns (address)"
];
const config = {
SEPOLIA_RPC_URL: process.env.SEPOLIA_RPC_URL,
UNISWAP_FACTORY: "0x0227628f3F023bb0B980b67D528571c95c6DaC1c",
QUOTER_ADDRESS: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
WETH: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
USDC: "0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8",
MIN_PROFIT_ETH: 0.05,
GAS_LIMIT: 1_000_000
};
const provider = new ethers.JsonRpcProvider(config.SEPOLIA_RPC_URL);
const quoterContract = new ethers.Contract(
config.QUOTER_ADDRESS,
QUOTER_ABI,
provider
);
const uniswapFactory = new ethers.Contract(
config.UNISWAP_FACTORY,
UNISWAP_FACTORY_ABI,
provider
);
async function main() {
// Verify pool existence first
const poolAddress = await uniswapFactory.getPool(
config.WETH,
config.USDC,
3000
);
console.log(`WETH/USDC 0.3% pool address: ${poolAddress}`);
if (poolAddress === ethers.ZeroAddress) {
throw new Error("WETH/USDC 0.3% pool does not exist on Sepolia");
}
provider.on('block', async (blockNumber) => {
console.log(`Scanning block ${blockNumber}...`);
try {
const [price1, price2] = await Promise.all([
getPoolPrice(config.WETH, config.USDC, 3000,'0.001'),
getPoolPrice(config.USDC, config.WETH, 3000, '0.001')
]);
console.log(`Price1: ${price1}, Price2: ${price2}`);
const profit = (price1 * price2) - 1;
if (profit > config.MIN_PROFIT_ETH) {
console.log(`Opportunity found! Profit: ${profit.toFixed(4)} ETH`);
console.log("Sending transaction....");
}
} catch (error) {
console.error('Block processing error:', error.message);
}
});
}
async function getPoolPrice(tokenIn, tokenOut, fee, amountIn) {
console.log(`Checking price for ${tokenIn} -> ${tokenOut}`);
try {
const decimals = tokenIn === config.WETH ? 18 : 6;
const formattedAmount = ethers.parseUnits(amountIn.toString(), decimals);
const amountOut = await quoterContract.quoteExactInputSingle.staticCall(
tokenIn,
tokenOut,
fee,
formattedAmount,
0
);
console.log(`Price check: ${tokenIn}->${tokenOut} = ${ethers.formatUnits(amountOut, 6)}`);
return parseFloat(ethers.formatUnits(amountOut, 6));
} catch (error) {
console.error(`Price check failed: ${error}`);
return 0;
}
}
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});
I am using ether 6.7.1
Log
Price check failed: Error: missing revert data (action="call", data=null, reason=null,
transaction={ "data": "0xf7729d43000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b1400000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c80000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000", "to": "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3" }
, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.7.1)Price check failed: Error: missing revert data (action="call", data=null, reason=null,
transaction={ "data": "0xf7729d4300000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b140000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000", "to": "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3" }
, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.7.1)
Package.json
{
"name": "price-check-bot",
"version": "1.0.0",
"type": "module",
"dependencies": {
"@aave/core-v3": "^1.19.3",
"@flashbots/ethers-provider-bundle": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@openzeppelin/contracts": "^4.8.0",
"@uniswap/v3-periphery": "github:uniswap/v3-periphery",
"dotenv": "^16.0.3",
"ethers": "^6.7.1",
"hardhat": "^2.12.0"
}
}
I am new to ethers and web 3 in general kindly help; Could this be the ABI?