'Can not call the function Aggregate - Multicall2.sol on BSC testnet

I already deployed the multicall2.sol smart contract on BSC Testnet https://testnet.bscscan.com/address/0x8F3273Fb89B075b1645095ABaC6ed17B2d4Bc576#code then call the contract by using the following typescript code:

  try {
    const multi = getMulticallContract(options.web3 || web3NoAccount)
    const itf = new Interface(abi)

    const calldata = calls.map((call) => [call.address.toLowerCase(), itf.encodeFunctionData(call.name, call.params)])
    const { returnData } = await multi.methods.aggregate(calldata).call(undefined, options.blockNumber)
    const res = returnData.map((call, i) => itf.decodeFunctionResult(calls[i].name, call))

    return res
  } catch (error) {
    throw new Error(error)
  }
}

I got the error

Uncaught (in promise) Error: Error: Returned error: execution reverted: Multicall aggregate: call failed

It's weird. Because the function works properly on Mainnet. Can anyone help me?



Solution 1:[1]

The author found his solution but just to complete the troubleshooting I suggest making sure you have:

Solution 2:[2]

in my case, i resolved the issue by simply switching the rpc from https://data-seed-prebsc-1-s3.binance.org:8545/ to https://data-seed-prebsc-1-s2.binance.org:8545/

looks like they have some substantial inconsistency between nodes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phạm Huy Phát
Solution 2 Patrick