Search code examples
javascriptethereumtruffleganacheuniswap

Trying to call a function on Uniswap V2 Factory contract on local ganache eth fork, instead getting error that I have no access to archive state


I am trying to call a simple view function allPairsLength() in a JS script using Truffle but I am getting the following error on running the script: Error: Returned error: project ID does not have access to archive state.

Here is the code:

const V2FACTORY = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
const V2PAIR = "0x3356c9A8f40F8E9C1d192A4347A76D18243fABC5";
const V2ROUTER2 = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";

const V3QUOTER = "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6";

const Ifactory = artifacts.require("UniswapV2Factory");
const IPairV2 = artifacts.require("UniswapV2Pair");
const IRouter02V2 = artifacts.require("UniswapV2Router02");
const IQuoter = artifacts.require("Quoter");

module.exports = async function getNoOfPairs() {
    let instance = await Ifactory.at(V2FACTORY);
    let numberOfPairs = await instance.allPairsLength();
    console.log(numberOfPairs);
};

Could someone please point me in the right direction? Thanks a lot!


Solution

  • I see from your comment that you forked a public network using Infura provider.

    Infura provides only a limited number of past blocks. Currently about 200 blocks. So if you fork the network at block 1000, and the current block becomes 1200, they won't provide you with any more data as it's over the limit.

    Solution: Just reinit the local fork, so that it's forked from a newer block.