Exception in fetchPairData() : call revert exception in method getReserves()

Viewed 8987

I am trying to call the "fetchPairData" function (https://uniswap.org/docs/v2/SDK/fetcher/) but I am getting the following error.

Error: call revert exception (method="getReserves()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.1.2)
    at Logger.makeError (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\logger\lib\index.js:180:21)
    at Logger.throwError (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\logger\lib\index.js:189:20)
    at Interface.decodeFunctionResult (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\abi\lib\interface.js:289:23)
    at Contract.<anonymous> (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\contracts\lib\index.js:329:56)
    at step (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\contracts\lib\index.js:48:23)
    at Object.next (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\contracts\lib\index.js:29:53)
    at fulfilled (C:\Users\*\Desktop\ProyectoTransaccion\v2\node_modules\@ethersproject\contracts\lib\index.js:20:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'getReserves()',
  errorSignature: null,
  errorArgs: [ null ],
  address: '0x80f836E71a6C92acebf6A49ad39038609c780070',
  args: [],
  transaction: {
    data: '0x0902f1ac',
    to: '0x80f836E71a6C92acebf6A49ad39038609c780070'
  }
}

Relevant code:

const {ChainId, Token, TokenAmount, Fetcher, Pair, Route, Trade, TradeType, Percent} = require('@pancakeswap-libs/sdk');

    const INPUT_TOKEN = new Token(ChainId.MAINNET,InputTokenAddr, 18);
    const OUTPUT_TOKEN = new Token(ChainId.MAINNET, OutputTokenAddr, 18);


    try {
        
        pair = await Fetcher.fetchPairData(INPUT_TOKEN, OUTPUT_TOKEN, provider);
        
    } catch (ex)
    {

        console.log("Debug.INPUT_TOKEN: " + JSON.stringify(INPUT_TOKEN));
        console.log("Debug.OUTPUT_TOKEN: " + JSON.stringify(OUTPUT_TOKEN));
        console.log("Debug.provider: " + JSON.stringify(provider));
        console.log(ex)
        pair = null;
    }

Debug:

Debug.INPUT_TOKEN: {"decimals":18,"chainId":56,"address":"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
Debug.OUTPUT_TOKEN: {"decimals":18,"chainId":56,"address":"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"}
Debug.provider: {"_isProvider":true,"_events":[],"_emitted":{"block":-2},"formatter":{"formats":{"transaction":{},"transactionRequest":{},"receiptLog":{},"receipt":{},"block":{},"blockWithTransactions":{},"filter":{},"filterLog":{}}},"anyNetwork":false,"_networkPromise":{},"_maxInternalBlockNumber":-1024,"_lastBlockNumber":-2,"_pollingInterval":4000,"_fastQueryDate":0,"connection":{"url":"https://bsc-dataseed.binance.org/"},"_nextId":45,"_eventLoopCache":{"detectNetwork":null,"eth_chainId":null},"_network":{"chainId":56,"name":"unknown"}}

I have verified that the swap works correctly in the pancakeswap web interface. It does not indicate route on the web, so it seems that it is a direct swap.

With other tokens the call returns what is expected. For example with the pair WBNB, BUSD.

I found for this error on another site with this comment

I faced the same issue and the problem was that I was trying to fetch price for a pool that did not exist.

The pool exists. It has liquidity and it is also direct, it does not require a route.

1 Answers

The call revert exception happens when

  • the client doesn't receive a response

    (no contract deployed on the address)

  • or when the contract code performs a revert.

    pragma solidity ^0.8;
    
    contract MyContract {
        function foo() external view {
            revert();
        }
    }
    

    (Can also be when you're calling an undefined function and there's no fallback() in the contract)


Your question doesn't specify on which network you tried to perform the call, but there's no contract on the failing address on both mainnet and testnet.

So either your client app is trying to call this non-existing contract directly, or some contract in the chain of calls is trying to call it.

transaction: {
    data: '0x0902f1ac',
    to: '0x80f836E71a6C92acebf6A49ad39038609c780070'
}
Related