I am using web3js to call PancakeFactory v2 contract (bscscan):

contract address: 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73 

Anytime I want to call any function present in the contract I end up with this error:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.

Strangely enough when I try to use their Router v2 contract I do not get any issues at all. It's just factory one which seems to be a problem. Abi and address where taken from bscscan. Also the address is the same as address displayed on pancakeswap docs page.

Code itself is simple:

const factory = new this.web3.eth.Contract(PancakeFactoryABI, PANCAKE_FACTORY_ADDRESS);
const pair = await factory.methods.getPair(token0, token1).call();

Any help would be appreciated.

  • How are you connecting to web3?
    – Ismael
    Aug 28 at 22:29
  • Through mainnet infura websocket: this.web3 = new Web3(new Web3.providers.WebsocketProvider("wss://mainnet.infura.io/ws/v3/7cd54990221c41a2b9c2fc8eeabce6d9", options)); this.web3.eth.net.isListening().then(() => { this.generatePairs(); this.handleSuccefullConnection(); })
    – mszopen
    Aug 30 at 15:25

The problem is quite clear with the wss://mainnet.infura.io/ws/v3/<code> you are accessing Ethereum mainnet.

The pancake contracts are on the Bsc network. They provide some endpoints you could use in their documentation.

  • Duh! You are right, thanks for help.
    – mszopen
    Aug 31 at 13:23

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.