2

I am connecting to Binance Smart Chain mainnet via rpc. The error message I get is following:

(node:17667) UnhandledPromiseRejectionWarning: 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.
    at ABICoder.decodeParameters (/home/username/basc/node_modules/web3-eth-abi/lib/index.js:286:15)
    at Contract._decodeMethodReturn (/home/username/basc/node_modules/web3-eth-contract/lib/index.js:470:22)
    at Method.outputFormatter (/home/username/basc/node_modules/web3-eth-contract/lib/index.js:760:42)
    at Method.formatOutput (/home/username/basc/node_modules/web3-core-method/lib/index.js:147:54)
    at sendTxCallback (/home/username/basc/node_modules/web3-core-method/lib/index.js:523:33)
    at /home/username/basc/node_modules/web3-core-requestmanager/lib/index.js:293:9
    at XMLHttpRequest.request.onreadystatechange (/home/username/basc/node_modules/web3-providers-http/lib/index.js:98:13
)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/username/basc/node_modules/xhr2-cookies/dist/xml-http-request-event
-target.js:34:22)

These are versions of modules:

  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "web3": "^1.3.0"
  }

I am calling a getAmountsIn() in this snippet and expecting "amount" to be returned.

//Check price of a pair
async function checkPair() {
        const WETH = await factoryContract.methods.WETH().call()
        const amount = web3.utils.fromWei('1000000000000000000', 'Ether')
        const getAmountsIn = await factoryContract.methods.getAmountsIn(amount, [WETH, "0xbf5140a22578168fd562dccf235e5d43a02ce9b1"]).call()
        console.log(getAmountsIn)
}

I am accessing this contract (see below) and its ABI in a standard way. I brought the ABI directly from BSCscan and it seems to be working accurately. In fact calling this getAmountsIn on WBNB/BUSD pair went correctly without an error. Other pairs do not work. https://bscscan.com/address/0x5334defbffdd7ec8705878db226cc4a0b498cd12#code

I tried lots of other known solution but none of them work. Essentially, we can be sure it is not 'out of gas' error, it is rather related to ABI decoding or encoding. I will appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.