Function call Reverts from Smart Contract without a reason unniswap V3

23 Views Asked by At

SO I am trying to do a swap exacttokenforToken for Uniswap router2 but it is getting revert without any specific reason

here is the code , forget about naming convention as this was one of code for Pancakeswap and the abis etc are correct for uniswap in there


const { ethers, utils,BigNumber } = require('ethers');

require('dotenv').config()
const BSC_TEST_NET_URL = process.env.BSC_MAIN_NET_URL
const WALLET_ADDRESS = process.env.WALLET_ADDRESS
const WALLET_SECRET = process.env.WALLET_SECRET
const ERC20ABI = require('./abi/abi.json')
const POOLABI = require('./abi/wbnbpool.json')
const SwapRouterABI = require('./abi/bscrouterabi.json')
const provider = new ethers.providers.JsonRpcProvider("https://mainnet.base.org");
const DARK_BUSD_PAIR_ADDRESS = '0x5B8d4aFd3FB13dA0e3f553150429a6370410e7D1' //'0xF7735324b1aD67B34D5958ED2769CFfa98a62dff';
const ROUTER_ADDRESS ='0x2626664c2603336E57B271c5C0b26F421741e481' //'0xD99D1c33F9fC3444f8101754aBC46c52416550D1';
const FACTORY_ADDRESS = '0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73'//'0x6725F303b657a9451d8BA641348b6761A6CC7a17';

const name0 = 'Dark'
const symbol0 = 'DARK'
const decimals0 = 18
const address0 =   '0x8319767a7B602f88e376368DCa1B92d38869B9b4'  //'0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd' // WBNB 

const name1 = 'BUSD'
const symbol1 = 'BUSD'
const decimals1 = 18
const address1 =  '0x4200000000000000000000000000000000000006'  //"0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684" // USDT

async function main(previousMinAmountOut = 110) {
    const poolContract = new ethers.Contract(
      DARK_BUSD_PAIR_ADDRESS,
      POOLABI,
      provider
    );
  
    console.log(BSC_TEST_NET_URL);
    console.log('factory', await poolContract.factory());
  
    const wallet = new ethers.Wallet(WALLET_SECRET);
    const connectedWallet = wallet.connect(provider);
  
    const router = new ethers.Contract(
      ROUTER_ADDRESS,
      SwapRouterABI,
      provider
    );
  
    const inputAmount = previousMinAmountOut;
    const amountIn = ethers.utils.parseUnits(inputAmount.toString(), decimals1);
  
    const approvalAmount = (amountIn ).toString();
    const tokenContract1 = new ethers.Contract(
      address1,
      ERC20ABI,
      provider
    );
    await tokenContract1.connect(connectedWallet).approve(
      ROUTER_ADDRESS,
      approvalAmount
    );
  
    const amountOutMin = await router.getAmountsOut(
      amountIn,
      [address1, address0]
    );
    console.log(`Amount Out Min: ${ethers.utils.formatUnits(amountOutMin[1], decimals0)} ${symbol0}`);
    const slippage = amountOutMin[1].div(100).mul(10); // 1% slippage
    const minAmountOut = amountOutMin[1].sub(slippage); // 1% slippage
    console.log('Min Amount Out:', ethers.utils.formatEther(minAmountOut, decimals0));


    console.log('Amount In:', ethers.utils.formatUnits(amountIn, decimals1));

  
    const amountsWBNB = await router.connect(connectedWallet).swapExactTokensForTokens(
      amountIn,
      BigNumber.from(0),
      [address1, address0],
      WALLET_ADDRESS,
      BigNumber.from(Math.floor(Date.now() / 1000) + (60 * 10)),
      { gasLimit: ethers.utils.hexlify(50000000) }
    );
    console.log('Swap BUSD to DARK Tx Hash:', amountsWBNB.hash);

  
    const tx = await amountsWBNB.wait();
 


    const isSuccess = tx.status === 1;
    const outputAmount = ethers.utils.formatUnits(minAmountOut, decimals0);
  
    return { isSuccess, outputAmount };
  }


  
  
 
    main()
 
  

Here is the error

  var error = new Error(message);
                    ^

Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction={"to":"0x2626664c2603336E57B271c5C0b26F421741e481","data":"0xd06ca61f000000000000000000000000000000000000000000000005f68e8131ecf800000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000042000000000000000000000000000000000000060000000000000000000000008319767a7b602f88e376368dca1b92d38869b9b4","accessList":null}, error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"execution reverted\"},\"id\":57}\n","error":{"code":-32000},"requestBody":"{\"method\":\"eth_call\",\"params\":[{\"to\":\"0x2626664c2603336e57b271c5c0b26f421741e481\",\"data\":\"0xd06ca61f000000000000000000000000000000000000000000000005f68e8131ecf800000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000042000000000000000000000000000000000000060000000000000000000000008319767a7b602f88e376368dca1b92d38869b9b4\"},\"latest\"],\"id\":57,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://mainnet.base.org"}, code=CALL_EXCEPTION, version=providers/5.6.8)
    at Logger.makeError (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\logger\lib\index.js:233:21)
    at Logger.throwError (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\logger\lib\index.js:242:20)
    at checkError (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:108:16)
    at JsonRpcProvider.<anonymous> (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:703:47)
    at step (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23)
    at Object.throw (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53)
    at rejected (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  reason: 'missing revert data in call exception; Transaction reverted without a reason string',
  code: 'CALL_EXCEPTION',
  data: '0x',
  transaction: {
    to: '0x2626664c2603336E57B271c5C0b26F421741e481',
    data: '0xd06ca61f000000000000000000000000000000000000000000000005f68e8131ecf800000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000042000000000000000000000000000000000000060000000000000000000000008319767a7b602f88e376368dca1b92d38869b9b4',
    accessList: null
  },
  error: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"execution reverted\"},\"id\":57}\n", error={"code":-32000}, requestBody="{\"method\":\"eth_call\",\"params\":[{\"to\":\"0x2626664c2603336e57b271c5c0b26f421741e481\",\"data\":\"0xd06ca61f000000000000000000000000000000000000000000000005f68e8131ecf800000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000042000000000000000000000000000000000000060000000000000000000000008319767a7b602f88e376368dca1b92d38869b9b4\"},\"latest\"],\"id\":57,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://mainnet.base.org", code=SERVER_ERROR, version=web/5.6.1)
      at Logger.makeError (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\logger\lib\index.js:233:21)
      at Logger.throwError (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\logger\lib\index.js:242:20)
      at C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\web\lib\index.js:305:32
      at step (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\web\lib\index.js:33:23)
      at Object.next (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\web\lib\index.js:14:53)
      at fulfilled (C:\Users\zahid\Uni-Pan-swap-Market-Making\node_modules\@ethersproject\web\lib\index.js:5:58)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    reason: 'processing response error',
    code: 'SERVER_ERROR',
    body: '{"jsonrpc":"2.0","error":{"code":-32000,"message":"execution reverted"},"id":57}\n',

The Transaction should have gone move smoothly but it isn't and I exactly do not know why , ethers and similar libraries are kind of weirs that these do not provide any error specific to what is happening

0

There are 0 best solutions below