Reputation: 31
I'm trying to connect to a smart contract on pancakeSwap, using web3.js; from the official documentation I know what methods I should use to connect to the contract.
I connect to my provider (quickNode) and use the addresses taken from bscscan.com to connect to the pancakeSwap routerV2 address. I am using Metamask wallet and I think I am connected to default BNB SmartChain.
Below is the JavaScript code I used:
const { Web3 } = require('web3');
const web3 = new Web3("https://ultra-frequent-needle.quiknode.pro/162ggHIDDEN123/");
// ABI
const pancakeRouterV2ABI = require("../scripts/pancakeABI.json");
// tokens pancakeSwap
const pancakeSwapRouterAddress = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
// CONTRACTS
const pancakeContract = new web3.eth.Contract(pancakeRouterV2ABI,pancakeSwapRouterAddress);
async function tryRunMethod(){
const amounts = await pancakeContract.methods.getAmountsOut(
web3.utils.toWei("1", "ether"),
[ethPancakeSwapAddress,usdPancakeSwapAddress]
).call();
console.log("amount=", amounts);
}
tryRunMethod();
No matter what method I try to run, the error will always be the same:
AbiError: Parameter decoding 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.
Instead I connect to a contract on uniswap with the etherscan addresses, and I can call any method I want to. How do I fix this?
Upvotes: 3
Views: 125