ExtropyIO / defi-bot

Tutorial for building DeFi arbitrage bots
1.18k stars 468 forks source link

[Solved]: Error: Invalid JSON RPC response: "" #20

Closed Marvmaster closed 3 years ago

Marvmaster commented 3 years ago

Hi guys and gals,

I was able to successfully deploy the TradingBot.sol contract to the mainnet (after many unsuccessful attempts on Ropsten and Rinkeby). Then I wanted to get index.js to run. After commenting out line 327, I did a yarn install and npm install in the directory and then ran node src/index.js. However I always get the following error messages in return:

Fetching market data @ 2021-08-02T11:18:22-05:00 ...

Fetching market data @ 2021-08-02T11:18:25-05:00 ...

(node:130667) UnhandledPromiseRejectionWarning: Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/root/defi-bot/node_modules/web3-core-helpers/lib/errors.js:43:16)
    at XMLHttpRequest.request.onreadystatechange (/root/defi-bot/node_modules/web3-providers-http/lib/index.js:95:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/root/defi-bot/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/root/defi-bot/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpRequestError (/root/defi-bot/node_modules/xhr2-cookies/dist/xml-http-request.js:349:14)
    at ClientRequest.<anonymous> (/root/defi-bot/node_modules/xhr2-cookies/dist/xml-http-request.js:252:61)
    at ClientRequest.emit (events.js:375:28)
    at Socket.socketErrorListener (_http_client.js:475:9)
    at Socket.emit (events.js:375:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(node:130667) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 608)

This error message appears almost every time. The cases, where two Fetching market data messages appear after another are extremely rare. Does anyone have an idea how to solve this? Thanks

Best Regards

Marvmaster commented 3 years ago

I was figure out, how to get it to work. The problem was, that I wanted to use my own geth instance instead of infura.io. This geth instance was listening on 127.0.0.1:8545 and I configured this in .env accordingly. However index.js always tried to connect to infura.io instead of local geth. I then removed infura-web3-provider from the package.json file (line 22). Now index.js successfully connects to the local geth instance instead of infura.io. :-)

mindfulme commented 3 years ago

close it?