Sepolia测试网Uniswap V3做市机器人CALL_EXCEPTION问题求助
问题:Uniswap做市机器人在Sepolia测试网出现CALL_EXCEPTION错误
从James Bachini的GitHub仓库获取的做市机器人在ETH主网运行正常,但部署到Sepolia测试网时触发CALL_EXCEPTION错误,以下是适配Sepolia后的代码及报错信息,请求排查解决。
适配Sepolia测试网后的代码
const ethers = require('ethers'); require("dotenv").config(); const wethAddress = '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'; // Sepolia WETH const routerAddress = '0x0227628f3F023bb0B980b67D528571c95c6DaC1c'; // Uniswap Router Sepolia const quoterAddress = '0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3'; // Uniswap Quoter Sepolia const tokenAddress = '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'; // UNI Sepolia token const fee = 3000; // Uniswap pool fee bps 500, 3000, 10000 const buyAmount = ethers.parseUnits('0.001', 'ether'); const targetPrice = BigInt(16); // target exchange rate const targetAmountOut = buyAmount * targetPrice; const sellAmount = buyAmount / targetPrice; const tradeFrequency = 3600 * 1000; // ms (once per hour) const provider = new ethers.JsonRpcProvider(`https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`); provider.getBlockNumber().then(blockNumber => { console.log('Connected to Sepolia network. Current block number:', blockNumber); }).catch(error => { console.error('Failed to connect to Sepolia network:', error); }); const wallet = new ethers.Wallet(process.env.PRIVATE_KEY); const account = wallet.connect(provider); const token = new ethers.Contract( tokenAddress, [ 'function approve(address spender, uint256 amount) external returns (bool)', 'function allowance(address owner, address spender) public view returns (uint256)', ], account ); const router = new ethers.Contract( routerAddress, ['function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96)) external payable returns (uint256 amountOut)'], account ); const quoter = new ethers.Contract( quoterAddress, ['function quoteExactInputSingle(address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint160 sqrtPriceLimitX96) public view returns (uint256 amountOut)'], account ); const buyTokens = async () => { console.log('Buying Tokens') const deadline = Math.floor(Date.now() / 1000) + 600; const tx = await router.exactInputSingle([wethAddress, tokenAddress, fee, wallet.address, deadline, buyAmount, 0, 0], {value: buyAmount}); await tx.wait(); console.log(tx.hash); }
报错信息
Error: missing revert data (action="call", data=null, reason=null, transaction={ "data": "0xf7729d43000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b140000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000", "from": ... })
排查与解决步骤
- 修正结构体参数传递方式:Uniswap V3 Router的
exactInputSingle方法接受结构体参数,ethers.js中需传递对象而非数组,数组形式会导致参数解析错误触发CALL_EXCEPTION。修改buyTokens函数中的调用代码:const tx = await router.exactInputSingle({ tokenIn: wethAddress, tokenOut: tokenAddress, fee: fee, recipient: wallet.address, deadline: deadline, amountIn: buyAmount, amountOutMinimum: 0, sqrtPriceLimitX96: 0 }, {value: buyAmount}); - 确认合约地址有效性:已验证你使用的Sepolia测试网合约地址均为正确地址
- 检查钱包余额:确保钱包持有足够Sepolia ETH,用于支付0.001 ETH交易金额及gas费用
- 启用调试日志:添加调试代码获取更多交易细节:
provider.on('debug', (info) => { if (info.action === 'call' || info.action === 'sendTransaction') { console.log('Debug info:', info); } }); - 模拟交易验证:使用Sepolia区块浏览器或Tenderly模拟交易,查看具体revert原因(如流动性不足、参数错误等)
内容的提问来源于stack exchange,提问作者Valerio
相关产品推荐
相关产品推荐

