dappuniversity / price-bot

397 stars 392 forks source link

Error: Returned values aren't valid, did it run Out of Gas? #8

Open daverag opened 3 years ago

daverag commented 3 years ago

Most coins I added give me this error, what am I doing wrong? It will work for DAI, LINK, MKR, LEND, BAT, KNC but not COMP and others afterwards

Error: Returned values aren't valid, did it run Out of Gas? at ABICoder.decodeParameters (/mnt/h/Code/price-bot/node_modules/web3-eth-abi/src/index.js:226:15) at Contract._decodeMethodReturn (/mnt/h/Code/price-bot/node_modules/web3-eth-contract/src/index.js:465:22) at Method.outputFormatter (/mnt/h/Code/price-bot/node_modules/web3-eth-contract/src/index.js:818:46) at Method.formatOutput (/mnt/h/Code/price-bot/node_modules/web3-core-method/src/index.js:163:54) at sendTxCallback (/mnt/h/Code/price-bot/node_modules/web3-core-method/src/index.js:473:33) at /mnt/h/Code/price-bot/node_modules/web3-core-requestmanager/src/index.js:147:9 at XMLHttpRequest.request.onreadystatechange (/mnt/h/Code/price-bot/node_modules/web3-providers-http/src/index.js:96:13) at XMLHttpRequestEventTarget.dispatchEvent (/mnt/h/Code/price-bot/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13) at XMLHttpRequest._setReadyState (/mnt/h/Code/price-bot/node_modules/xhr2-cookies/xml-http-request.ts:219:8) at XMLHttpRequest._onHttpResponseEnd (/mnt/h/Code/price-bot/node_modules/xhr2-cookies/xml-http-request.ts:345:8) at IncomingMessage. (/mnt/h/Code/price-bot/node_modules/xhr2-cookies/xml-http-request.ts:311:39) at IncomingMessage.emit (events.js:203:15) at endReadableNT (_stream_readable.js:1143:12) at process._tickCallback (internal/process/next_tick.js:63:19)

Here is the gist of my code

`let pairs = [
// { symbol: 'DAI', address: '0x6b175474e89094c44da98b954eedeac495271d0f'}, // { symbol: 'LINK', address: '0x514910771af9ca656af840dff83e8264ecf986ca'}, // { symbol: 'MKR', address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2'}, // { symbol: 'LEND', address: '0x80fB784B7eD66730e8b1DBd9820aFD29931aab03'}, // { symbol: 'BAT', address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef'}, // { symbol: 'KNC', address: '0xdd974d5c2e2928dea5f71b9825b8b646686bd200'}, //{ symbol: 'COMP', address: '0xc00e94cb662c3520282e6f5717214004a7f26888' }, //{ symbol: 'VET', address: '0xd850942ef8811f2a866692a623011bde52a462c1' }, //{ symbol: 'YFI', address: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e' }, //{ symbol: 'CRO', address: '0xa0b73e1ff0b80914ab6fe0444e65848c4c34450b ' }, { symbol: 'HEX2T', address: '0xEd1199093b1aBd07a368Dd1C0Cdc77D8517BA2A0' },

];

async function monitorPrice() { if(monitoringPrice) { return }

console.log("Checking prices...") monitoringPrice = true

try { for (p in pairs) {

    console.log(p)
    await checkPair({
      inputTokenSymbol: eth.symbol,
      inputTokenAddress: eth.address,
      outputTokenSymbol: pairs[p].symbol,
      outputTokenAddress: pairs[p].address,
      inputAmount: web3.utils.toWei('1', 'ETHER')
    })  

}

} catch (error) { console.error(error) monitoringPrice = false clearInterval(priceMonitor) return }

monitoringPrice = false }

`

KinectTheUnknown commented 3 years ago

for... in loops iterate over keys, not values. In this case, p is an index (a number from 0 to length - 1). Use a for... of loop instead to get the values of the array.

ghost commented 3 years ago

I am also having this same issue. I'm sure @KinectTheUnknown is correct, but don't know enough to modify it. I actually wasn't able to get the original code to work without getting this error message. I did successfully clone the trading_bot, however not the price_bot. Any help would be great. Thanks

KinectTheUnknown commented 3 years ago

I am also having this same issue. I'm sure @KinectTheUnknown is correct, but don't know enough to modify it. I actually wasn't able to get the original code to work without getting this error message. I did successfully clone the trading_bot, however not the price_bot. Any help would be great. Thanks

Just change for (const p in pairs) to for (const p of pairs)

canberk17 commented 3 years ago

Same problem here, the check price function seems to work only on certain tokens. Did anyone find a solution?