PancakeSwap – Resolving Factory Smart Contract Error

abierrorfactorypancakeswapweb3js

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.

Best Answer

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.

Related Topic