Uniswap V3 Bot on Sepolia Testenet

37 Views Asked by At

I found this interesting bot from James Bachini https://github.com/jamesbachini/Market-Maker-Bot. I tried on ETH Mainet and works fine then I tried on Sepolia Testenet and I got stuck in a CALL_EXCEPTION'

Here James Bachini's code with Sepolia change.

  const ethers = require('ethers');`enter code here`
    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-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`);
    
    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);
    }

And the error:

Error: missing revert data (action="call", data=null, reason=null, transaction={ "data": "0xf7729d43000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b140000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000bb800000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000", "from":

Thanks

0

There are 0 best solutions below