when a i call any of contract methods (the contract is the pancakeswap factory), this error return error: call revert exception (method="allPairsLength()", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.0.13) Anyone know why?

const hre = require ('hardhat');

async function main() {

  const provider = new hre.ethers.providers.JsonRpcProvider('https://bsc-dataseed1.binance.org:443');
  console.log(await provider.getBalance('0xDf5390a504263d35Db42E1Df19775b6855C548af'));
  factory = await hre.ethers.getContractAt('IUniswapV2Factory','0xBCfCcbde45cE874adCB698cC183deBcF17952812');
  await factory.allPairsLength()

  • Please edit your question and provide more details, including what you are trying to achieve and how (with code).
    – Undead8
    Apr 12 '21 at 13:35

The line factory = await hre.ethers.getContractAt('IUniswapV2Factory','0xBCf..12') references the contract on hardhat network. While I think you mean to connect to a contract on bsc.

factory = await hre.ethers.getContractAt('IUniswapV2Factory','0xBCf..12', provider)

Just need to add the provider there, then your factory.allPairsLength() call should be made on bsc instead of hardhat network

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.