Web3.js: Error: Invalid JSON RPC response: ""

Created on 16 Mar 2018  Â·  21Comments  Â·  Source: ChainSafe/web3.js

Hello,

I make this code for watching the event Submission but I have the error: Error: Invalid JSON RPC response: ""

    const contract = this._web3.eth.contract(abi).at(address);
    contract.Submission({}, { fromBlock: 0, toBlock: 'latest' }).watch((error, result) => {
      if (error) return console.error(error);
      console.log('on watch');
      console.log(result);
    });

I'm using web3 v0.19.1

Thanks !

Most helpful comment

I'm having this issue as well querying a Geth Ropsten node. What's odd is that I was querying the node just fine, then I restarted the node and now I can't query it.

Node v10.0.0
Web3 1.0.0-beta.34
Geth 1.8.6-stable

EDIT:

I found my issue, although it was a stupid error on my part I'm leaving this up incase anyone else happens to have the same issue.

I had conflicting env vars which were overriding the host+port I was connecting to, and pointing it towards a node that wasn't up anymore.

So this is more of a case of a very bad error message (invalid json rpc vs connection refused)

All 21 comments

I'm having the similar issue when I run this "Error: Invalid JSON RPC response: undefined"

const ganache = require('ganache-cli')
const Web3 = require('web3')
const web3 = new Web3();
web3.setProvider(ganache.provider());
console.log(web3.eth.coinbase);

Check your web3 version in package.json , I've switched it to ^1.0.0-beta.31 and its all golden now.

@zo-tahiana did you solve this? can you provide info on what node you are connecting to?

I have the same issue polling regularly a Parity node (ETH), sometimes I receive this error, but not always:

web3: 1.0.0-beta.34
Node.js: 9.8.0
Parity: v1.9.6-20180416

ERR app/modules/systems/server/systemSockets/systems-monitor.server.socket.config.js Error: Invalid JSON RPC response: ""
        at Object.InvalidResponse (app/node_modules/web3-core-helpers/src/errors.js:42:16)
        at XMLHttpRequest.request.onreadystatechange (app/node_modules/web3-providers-http/src/index.js:73:32)
        at XMLHttpRequestEventTarget.dispatchEvent (app/node_modules/xhr2/lib/xhr2.js:64:18)
        at XMLHttpRequest._setReadyState (app/node_modules/xhr2/lib/xhr2.js:354:12)
        at XMLHttpRequest._onHttpRequestError (app/node_modules/xhr2/lib/xhr2.js:544:12)
        at ClientRequest.<anonymous> (app/node_modules/xhr2/lib/xhr2.js:414:24)
        at ClientRequest.emit (events.js:180:13)
        at ClientRequest.emit (domain.js:421:20)
        at Socket.socketErrorListener (_http_client.js:394:9)
        at Socket.emit (events.js:180:13)
        at Socket.emit (domain.js:421:20)
        at emitErrorNT (internal/streams/destroy.js:64:8)
        at process._tickCallback (internal/process/next_tick.js:114:19)

Thank you for your help. I solve it by upgrading the web3 version to latest. So, I will close this issue.

@michelem09 did you solve this? I have exactly the same error message, with the latest web3 version.

No I still have this

I'm having this issue as well querying a Geth Ropsten node. What's odd is that I was querying the node just fine, then I restarted the node and now I can't query it.

Node v10.0.0
Web3 1.0.0-beta.34
Geth 1.8.6-stable

EDIT:

I found my issue, although it was a stupid error on my part I'm leaving this up incase anyone else happens to have the same issue.

I had conflicting env vars which were overriding the host+port I was connecting to, and pointing it towards a node that wasn't up anymore.

So this is more of a case of a very bad error message (invalid json rpc vs connection refused)

Yes, agreed with @jrbury, that wired message was fired when the connection was refused or timeout, and it would be nice to have a meaningful error message returned in that case I think.

i too get the same response.please provide me a solution.
my version is [email protected]

check your code making sure you are using the web3 v1 syntax

Yes. I'm following official web3 documentation

On Tue, Aug 14, 2018, 8:42 PM arash kiani notifications@github.com wrote:

check your code making sure you are using the web3 v1 syntax

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ethereum/web3.js/issues/1470#issuecomment-412906937,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Aoax9Gb9zNsbsVK3qKJRuCZt233D4PmWks5uQujOgaJpZM4St6rH
.

I'm closing the issue..I got error because i have'nt declared the correct port.it's working fine now.thanks

In case other debuggers hit this, I was SSHing into a node of a private network and thought I could use localhost -- turns out that you need to use the RPC address specified in the command-line args. Switching over fixed the issue.

"name": "inbox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.3.0",
"mocha": "^4.1.0",
"solc": "^0.4.17",
"truffle-hdwallet-provider": "^1.0.4",
"web3": "^1.0.0-beta.36"
}
}

deploy.js
const HDWalletProvider = require('truffle-hdwallet-provider');//HDWallet says which account we wnat to unlock and which account to use as source of ether and which account to be unlockedfor deploying our constract and what outside node we are gng to connect to
const Web3=require('web3');
const{interface,bytecode}=require('./compile');
const provider=new HDWalletProvider(
'uniform parrot race entry worry saddle during buyer source wait invest slight','https://rinkeby.infura.io/v3/de97edd91145471199555841549fb3bc'
);
const web3=new Web3(provider);//we can use web3 instance to interact with test network we can send eth,deploy contract etcv

// reason we are writing function so that we can avoid promises and use async await
const deploy=async ()=>{
const accounts= await web3.eth.getAccounts();
console.log('attempting to deploy from account',accounts[0]);
const result=await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:'0x'+ bytecode,arguments:['hi! there']})
.send({gas:'1000000',from:accounts[0]});

console.log('contract deployed at',result.options.address);//to know where our contract is deployed

};
deploy();

ERROR IAM GETTING WHEN I RUN ABOVE CODE
kuras-MBP:inbox kurasushanthkumarreddy$ node deploy.js
attempting to deploy from account 0xAe458357763F80a7aAa72F80339911D9Bf48320b
contract deployed at 0x6d31980F771424AaDE60CfAeB961FdD5CF333f78
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:625357)
at e.i.onreadystatechange (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:775475)
at e.t.dispatchEvent (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:1:152983)
at e._setReadyState (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:780284)
at e._onHttpRequestError (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:783952)
at ClientRequest. (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:781449)
at ClientRequest.emit (events.js:189:13)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:625357)
at e.i.onreadystatechange (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:775475)
at e.t.dispatchEvent (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:1:152983)
at e._setReadyState (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:780284)
at e._onHttpRequestError (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:783952)
at ClientRequest. (/Users/kurasushanthkumarreddy/inbox/node_modules/truffle-hdwallet-provider/dist/index.js:15:781449)
at ClientRequest.emit (events.js:189:13)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)

@sushanth3366 Did you solve the issue, I am getting the same problem.

If anybody else has solved the issue mentioned by @sushanth3366. Please write back.

Check the current provider and expected provider

I'm having this issue as well querying a Geth Ropsten node. What's odd is that I was querying the node just fine, then I restarted the node and now I can't query it.

Node v10.0.0
Web3 1.0.0-beta.34
Geth 1.8.6-stable

EDIT:

I found my issue, although it was a stupid error on my part I'm leaving this up incase anyone else happens to have the same issue.

I had conflicting env vars which were overriding the host+port I was connecting to, and pointing it towards a node that wasn't up anymore.

So this is more of a case of a very bad error message (invalid json rpc vs connection refused)

Note to my future self when I forget again and look this up, AND anyone else still having this problem: If you are using Geth make sure to run geth in RPC mode geth --rpc so that you can use the RPC api otherwise this error will occur

I was getting same issue with : web3V1.2.11,
rolled back to web3v1.2.1 solved the issue

@parin13 I had same issue at V1.2.11 upgraded to V1.3 - it's working now

Was this page helpful?
0 / 5 - 0 ratings