1

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.

2
  • How are you connecting to web3?
    – Ismael
    Commented Aug 28, 2021 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
    Commented Aug 30, 2021 at 15:25

1 Answer 1

0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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