You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ethers v6.7.1在Sepolia测试网获取WETH/USDC报价时触发CALL_EXCEPTION错误求助

Ethers v6.7.1在Sepolia测试网获取WETH/USDC报价时触发CALL_EXCEPTION错误求助

我是Web3新手,最近在做一个小工具,想在Sepolia测试网通过Ethers v6.7.1获取WETH/USDC的Uniswap报价。我自己梳理了逻辑,觉得代码看起来没问题,但每次调用报价接口都会触发CALL_EXCEPTION错误,而且没有给出具体的回滚原因数据,实在卡在这里搞不定,恳请各位大佬帮忙排查一下!

错误核心信息

我反复遇到的错误代码是CALL_EXCEPTION,错误信息里只附带了Ethers版本version=6.7.1,没有有效的回滚详情,完全摸不着头脑。

完整代码片段

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);
});

错误日志输出

Price check failed: Error: missing revert data (action="call", data=null, reason=null, transaction={ "data": "0xf7729d43000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b1400000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c80000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000000000", "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": "0xf7729d4300000000000000000000000094a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b14000000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000", "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"
  }
}

我自己怀疑会不会是ABI写得有问题?因为我只写了需要用到的函数签名,会不会遗漏了什么必要的内容?或者是合约地址、代币地址在Sepolia测试网不对?麻烦各位帮我看看,感激不尽!

备注:内容来源于stack exchange,提问作者Samuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 08:53:06