Truffle: using infura in truffle and get Error: Invalid JSON RPC response: ""

Created on 17 Mar 2018  Â·  56Comments  Â·  Source: trufflesuite/truffle

it is my first time to ask questions there ,please forgive my rudeness.

I using metamask, infura, and truffle to try to deploy the contract (the pet-shop-tutorial) to the ropsten testnet, all gone well but this.

that is the error information:

duchendeMacBook-Air:pet-shop-tutorial duchen$ truffle migrate --network ropsten --reset
Using network 'ropsten'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x8bf66529dd4eb0c36a89ecec783808effad37ec4bc6dda9f9fe1a7f7cc219f3d
  Migrations: 0xb2ea93671103da9da0cc8018e4a262280e4944f0
Saving successful migration to network...
  ... 0xef35a32e4e13e9615c597527c082bb0f5cc32018bfa7a8ad4a03b9f8af9c59ce
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Replacing Adoption...
  ... 0x4340c9d747dd134da705a6cc192432b0b4b75d0138a01ef21f5c955958a2bb05
  Adoption: 0x83544aff3420b9a1639fb9944449575f6135d915
Saving successful migration to network...
  ... 0x4774ad3d756e26aeaf047b5e19ae449ace957e3baf3578478c70c0aa951fa8e1
Saving artifacts...
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:128857
var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}else{throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&"function"==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!

Error: Invalid JSON RPC response: ""
 at Object.InvalidResponse (/Users/duchen/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/duchen/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/duchen/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/duchen/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/Users/duchen/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/Users/duchen/node_modules/xhr2/lib/xhr2.js:414:24)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)

and this is my code in truffle.js:

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*" // Match any network id
    },
      ropsten: {
      provider:function(){
      return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/epDGgTgqhFlsPTwmmVC0")
      },
      network_id: 3,
      gas:499000,
      gasPrice:1000000000000
    }
  }
};

I followed the steps from http://truffleframework.com/tutorials/using-infura-custom-provider
but it seemed it has some problems, thank you for your answers.

Most helpful comment

Already a small observation:

I added a console log in HDWalletProvider to log the rpc url used in the constructor.

using provider: new HDWalletProvider(), it cleanly logs the URL once
using provider: () => return new HDWalletProvider(), it logs the url multiple times per migration (2x per artifact.require)

Seems like the () => form is not such a good idea

All 56 comments

@dc1996226 Thanks for opening. It looks very similar to this issue at truffle-migrate and I think we'll have to investigate further to understand exactly why this is happening.

For what it's worth, I see the final transaction in the migration sequence executed successfully on Ropsten here. Will try to reproduce this this week.

+1

+1

+1

+1

Just leaving a note here - @draugaslt @nklipa13 @atygr - anyone else adding to this thread. This bug is difficult to reproduce and there's some evidence that it's intermittent (see comment in #894). We'd really like to figure out if this is an infura connectivity issue or a problem with migrations logic. Anything you can add here might be helpful. Examples:

  • it was broken and then somehow started working (plus details!!)
  • it's always broken and never works

I've been hit by the same issue, but not on Infura.

A project with 4 migration files, all "saving artifacts" work but the last one ends like this:

Saving successful migration to network...
  ... 0x7208b4903b144324a1e14a875f7b63507ff69f9d5c689c9c029b19cac4d9ffe0
Saving artifacts...

.. long time nothing ..

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:414:24)
    at ClientRequest.emit (events.js:180:13)
    at TLSSocket.socketErrorListener (_http_client.js:395:9)
    at TLSSocket.emit (events.js:180:13)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)
Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:414:24)
    at ClientRequest.emit (events.js:180:13)
    at TLSSocket.socketErrorListener (_http_client.js:395:9)
    at TLSSocket.emit (events.js:180:13)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)
Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/roderik/Development/socialcurrency-dapi/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/Users/roderik/Development/socialcurrency-dapi/node_modules/xhr2/lib/xhr2.js:414:24)
    at ClientRequest.emit (events.js:180:13)
    at TLSSocket.socketErrorListener (_http_client.js:395:9)
    at TLSSocket.emit (events.js:180:13)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)

What is similar to infura is that the node I target is a load balancer in front of 2 parity nodes running a PoA network. (actually, there are 2 networks configured exactly the same, both behave the same way)

In this project it is an "always" error.

@roderik It looks like this might be caused by the HDWallet provider continuing to poll the remote client for blocks after the client disconnects. Does that seem like a plausible description for your case?

If so, we now have a simple way of reproducing this behavior and should be able to detect whether or not hdWallet is being used in migrations / close the provider appropriately.

I am indeed using HDWalletProvider configured like:

    mintnet: {
      provider: () => {
        return new HDWalletProvider(
          process.env.ETHEREUM_DEPLOYER_SEED,
          'https://mintnet.settlemint.com'
        )
      },
      gasPrice: 0x00,
      network_id: '8995',
    },

You are mentioning a client but I'm a bit confused about what you mean by that. HDWalletProvider polls, so it is an HTTP request that gets a response and then closes the connection. The Parity node and/or the loadbalancer do not stop answering, so polling at any time for new blocks should just work.

Going by the error message, usually means that I forgot to turn on ganache when developing, makes me think that in that last phase, it tries to connect to a different network / endpoint.

I also tried the network config without the function, similar result. It still hangs, but I do not get the error messages.

Digging deeper!

Already a small observation:

I added a console log in HDWalletProvider to log the rpc url used in the constructor.

using provider: new HDWalletProvider(), it cleanly logs the URL once
using provider: () => return new HDWalletProvider(), it logs the url multiple times per migration (2x per artifact.require)

Seems like the () => form is not such a good idea

@roderik Ah that's interesting - I was thinking it's possible that Infura occasionally times out or fails to respond because it's under heavy load.

Would you be open to testing a possible fix for this? Have published an experimental build that forces truffle to exit after a command is run and would like to see if that short-circuits this problem. It's available by running:

npm install -g darq-truffle@roderik

darq-truffle migrate  # <-- Example command

NB: truffle develop and truffle console are likely broken by this change - just trying to see if there's a way out the hang. A little more info on darq-truffle at npm here.

@cgewecke for us the error was removed, but the outcome is the same.

@Warrantoken Could you describe the outcome?

Also if you have a second, could you uninstall the roderik build and re-install it? Just published another version of that which replaces the hard exit with timer clearing and might be more viable as a PR.

@cgewecke as @Warrantoken mentioned, it does not solve the hanging issue.

I've found a way for you to trigger this issue, that will make it a lot easier to try and find the root cause. This repo (a token sale) triggers the bug: https://github.com/DataBrokerDAO/dtx-crowdsale-contracts

You can trigger it by running: (0 gas, 5s blocktime, Parity-based PoA network)

ETHEREUM_DEPLOYER_SEED="help help help help help help help help help help help help" darq-truffle migrate --reset --network mintnet

Explorer: https://explorer.mintnet.settlemint.com/
Netstats: https://stats.mintnet.settlemint.com/

An observation already, if I enable migration 1_ and 2_ it does not hang. If I enable another one (i did 14_ now) it hangs.

@cgewecke
Well, we are only having this issue deploying to the main net. so its going to get kinda expensive to keep trying it.

here is the contract we tried to deploy, its a slightly modified openzepplin erc20 token with crowdsale:
https://etherscan.io/address/0xcb3b07feb71b10ec70c999a8436ff25ee6ea0a5f

@Warrantoken That contract looks like it might be Migrations.sol? Have you successfully deployed to Rinkeby or Ropsten?

@Roderik - I will try out Mintnet, looks amazing. One thing that occurs to me is that Parity has a known issue interacting with web3 (see truffle migrate 15) that can be resolved by running the nodes in geth mode. Do you know if that might be relevant?

@roderik May have gotten it to work. Have published (yet another) @roderik build that closes sockets and timers on exit. So:

npm uninstall -g darq-truffle
npm install -g darq-truffle@roderik

Then fix the missing await in 2_deploy_contracts.js here. Super impressed with your block explorer and setup btw - this was a joy to debug.

Output

cgewecke$ darq-truffle migrate --reset --network mintnet
Using network 'mintnet'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x51500047ae18688efca1c7ef82887aa6868094ab48c91358861399ce85e8ea8f
  Migrations: 0x0a70c9ab017117be5fa6b6d7b587b89ba548eddd
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Running step...
  Replacing MiniMeTokenFactory...
  ... 0x5314464d47f70aef8ff7a1e08fc345060a5706e1f1f8e9af6a4bf3a45ee9e1d5
  MiniMeTokenFactory: 0x122a0bd157ecf23406ce4851c93b3c23ffa4eeb6
  Replacing MultiSigWalletWithDailyLimit...
  ... 0x25617048235eb8b95769ed2d46c5f2691a0367b7f4a161be32f59bb1c0bf1d95
  MultiSigWalletWithDailyLimit: 0x8bc790a583789367f72c9c59678ff85a00a5e5d0
  Replacing DTXToken...
  ... 0x1dec0ea86f06785e4ad540bac931d6fdb8a7dd732f45c3f02028c5fa5fb7e6c4
  DTXToken: 0x57a474713701d60a1e3c22e1827bf421f4948006
  Replacing TokenSale...
  ... 0xc66a183e36369be5680b47fc90b17fa83510af1a0084c15b1682f5e1cf002773
  TokenSale: 0x026950f443feb8be15bf0a3b878ba1fe23e0ab61
  ... 0xe7d853bb1302f0d71fbef36c41f55d41f078e72dee512fcc8589f8851aa39ec0
Saving artifacts...
Running migration: 3_early_sale_participants.js
  Running step...
Saving artifacts...
Running migration: 4_private_sale_syndicates.js
  Running step...
Saving artifacts...
Running migration: 5_lastcall_private_sales.js
  Running step...
Saving artifacts...
Running migration: 6_initial_private_sales.js
  Running step...
Saving artifacts...
Running migration: 7_cc_private_sales.js
  Running step...
Saving artifacts...
Running migration: 8_coinfalcon.js
  Running step...
Saving artifacts...
Running migration: 9_d10.js
  Running step...
Saving artifacts...
Running migration: 10_ko_private_sale.js
  Running step...
Saving artifacts...
Running migration: 11_fix_dates.js
  Running step...
Saving artifacts...
Running migration: 12_test.js
  Running step...
Saving artifacts...
Running migration: 13_fix_dates.js
  Running step...
Saving artifacts...
Running migration: 14_fixdates2.js
  Running step...
  ... 0xebf6e4ff706373fce43002e04b08d278c037fae99917e46ae8615fa0d2d375c3
1521471600 BigNumber { s: 1, e: 9, c: [ 1521471600 ] }
1524754799 BigNumber { s: 1, e: 9, c: [ 1524754799 ] }
1524783600 BigNumber { s: 1, e: 9, c: [ 1524783600 ] }
1524869999 BigNumber { s: 1, e: 9, c: [ 1524869999 ] }
1524870000 BigNumber { s: 1, e: 9, c: [ 1524870000 ] }
1527375600 BigNumber { s: 1, e: 9, c: [ 1527375600 ] }
Saving artifacts...
Running migration: 15_newdates3.js
  Running step...
Saving artifacts...
Running migration: 16_new_dates.js
  Running step...
Saving artifacts...
Users-MacBook-Air:dtx-crowdsale-contracts cgewecke$

@cgewecke fixed in all my projects!

And feel free to use mintnet if you want, happy to give something back for all the work! If you really want to mess around, replace mintnet in all URL's to minttestnet, exact same setup, fewer production apps :)

@roderik Oh good, and thank you!

Could this be somehow related? #729

@Alonski I don't think so. This is happening in a migrations context using HDWalletProvider and is caused by failing to close the provider correctly as Truffle exits a command. #729 looks like its caused by web3 / XHR2 consuming too many port resources in long running tests that make thousands of server requests.

@cgewecke ok thanks. I've been following #729 and someone mentioned this one to me as well

This should be fixed in 4.1.9. Please ping if you continue see this error.

I'm running truffle driven javascript tests against a remote private ethereum network built using Azure
https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft-azure-blockchain.azure-blockchain-ethereum

The tests succeed but the test runs intermittently print:

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/home/project/build/contracts/solidity/node_modules/web3/lib/web3/errors.js:35:16)
    at XMLHttpRequest.request.onreadystatechange (/home/project/build/contracts/solidity/node_modules/web3/lib/web3/httpprovider.js:115:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/project/build/contracts/solidity/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/project/build/contracts/solidity/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/home/project/build/contracts/solidity/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/home/project/build/contracts/solidity/node_modules/xhr2/lib/xhr2.js:414:24)
    at ClientRequest.emit (events.js:182:13)
    at Socket.socketErrorListener (_http_client.js:382:9)
    at Socket.emit (events.js:182: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)

Environment:

The tests are run from inside a Alpine Linux based docker container

> uname -a
Linux 6b872200eadf 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 Linux
> node --version
v10.2.1
> ./node_modules/.bin/truffle version
Truffle v4.1.11 (core: 4.1.11)
Solidity v0.4.24 (solc-js)

Hi @roderik - Just wanted to leave you a note here - am testing a recent rewrite of the migrations command and might run a few (dozen?) migrations against the minttestnet to get a sense of the errors a Parity cluster sends back when things go wrong. Also to make sure things go right.

Please let me know if this inconveniences you in any way and I will stop. Thanks!

why stop at a dozen, go nuts, make those nodes sweat! :)

Having the same issue with Rinkeby through Infura. Migrations and tests go well. After running 10 test (all pass) receive 10 "Invalid JSON RPC" responses.

+1

+1

+1
@porobov, @okwme, @haraldini, what truffle version do you have?
I have 4.1.13

Truffle v4.1.13 (core: 4.1.13)
Solidity v0.4.24 (solc-js)

Re-opening this because it seems some users are having trouble with this still.

+1
Truffle v4.1.13 (core: 4.1.13)
Solidity v0.4.24 (solc-js)

FYI upgrading the HDWallterProvider to version 0.0.7-beta.0 resolved the issue for me

@danielCommitted
Truffle v4.1.13 (core: 4.1.13)
Solidity v0.4.24 (solc-js)

Hi, I have got the same Error but the got it from different scene.
it happen during my token.methods.transfer(spender, amount)

Truffle v4.1.14 - a development framework for Ethereum
pragma solidity ^0.4.21;

"web3": "^1.0.0-beta.20",

Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-core-helperssrcerrors.js:42:16)
at XMLHttpRequest.request.onreadystatechange (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-providers-httpsrcindex.js:60:32)
at XMLHttpRequestEventTarget.dispatchEvent (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-providers-httpnode_modulesxhr2libxhr2.js:64:18)
at XMLHttpRequest._setReadyState (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-providers-httpnode_modulesxhr2libxhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-providers-httpnode_modulesxhr2libxhr2.js:509:12)
at IncomingMessage. (D:projectsblockchainbitxcoinnode_modulesweb3packagesweb3-providers-httpnode_modulesxhr2libxhr2.js:469:24)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

I'm getting this error with darq-truffle@next. After it deploys my smart contracts and wants to save the artifacts, I get the following error:

[test] Error: Invalid JSON RPC response: ""
webpack_1     | [1]     at Object.InvalidResponse (/usr/src/webpack/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/errors.js:35:16)
webpack_1     | [1]     at XMLHttpRequest.request.onreadystatechange (/usr/src/webpack/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:115:32)
webpack_1     | [1]     at XMLHttpRequestEventTarget.dispatchEvent (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:64:18)
webpack_1     | [1]     at XMLHttpRequest._setReadyState (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:354:12)
webpack_1     | [1]     at XMLHttpRequest._onHttpRequestError (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:544:12)
webpack_1     | [1]     at ClientRequest.<anonymous> (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:414:24)
webpack_1     | [1]     at ClientRequest.emit (events.js:182:13)
webpack_1     | [1]     at TLSSocket.socketErrorListener (_http_client.js:399:9)
webpack_1     | [1]     at TLSSocket.emit (events.js:182:13)
webpack_1     | [1]     at emitErrorNT (internal/streams/destroy.js:82:8)
webpack_1     | [1]     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
webpack_1     | [1]     at process.internalTickCallback (internal/process/next_tick.js:72:19)
webpack_1     | [1] [test] Error: Invalid JSON RPC response: ""
webpack_1     | [1]     at Object.InvalidResponse (/usr/src/webpack/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/errors.js:35:16)
webpack_1     | [1]     at XMLHttpRequest.request.onreadystatechange (/usr/src/webpack/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:115:32)
webpack_1     | [1]     at XMLHttpRequestEventTarget.dispatchEvent (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:64:18)
webpack_1     | [1]     at XMLHttpRequest._setReadyState (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:354:12)
webpack_1     | [1]     at XMLHttpRequest._onHttpRequestError (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:544:12)
webpack_1     | [1]     at ClientRequest.<anonymous> (/usr/src/webpack/node_modules/xhr2/lib/xhr2.js:414:24)
webpack_1     | [1]     at ClientRequest.emit (events.js:182:13)
webpack_1     | [1]     at TLSSocket.socketErrorListener (_http_client.js:399:9)
webpack_1     | [1]     at TLSSocket.emit (events.js:182:13)
webpack_1     | [1]     at emitErrorNT (internal/streams/destroy.js:82:8)
webpack_1     | [1]     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
webpack_1     | [1]     at process.internalTickCallback (internal/process/next_tick.js:72:19)

I tried with truffle-hdwallet-provider 0.0.7-beta.0. Doesn't work.

Is this still a problem in the latest version of Truffle?

@gnidan
I had this issue on

Truffle v5.0.2 (core: 5.0.2)
Solidity - 0.4.24 (solc-js)
Node v11.7.0

I was able to fix this problem by changing provider in truffle-confing.js from

provider: function () {
   return new HDWalletProvider(...)
}

to

provider: new HDWalletProvider(....)

Don't know why this works...

I am also seeing this with the following versions:
Truffle v5.0.2 (core: 5.0.2)
Solidity v0.5.0 (solc-js)
Node v10.14.1

I tried @t4sk 's solution which allowed me to push to Ropesten but My test suite still won't run.

I am still getting:

Invalid JSON RPC response: "WebSockets request was expected\r\n"

I was able to run tests locally by adding the following network configuration in truffle.js:

test: { host: "127.0.0.1", port: 9545, network_id: '*', }

then running my tests using

truffle test --network test

@EvanTedesco Is your code available anywhere to look at?

package.json

"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();

json rpc error

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)

can anyone help me resolving this issue please??

@sushanth3366 Is your code available somewhere on github so I can take a look? The above is very difficult to read. Also, I want to look at your truffle config.

@eggplantzzz i am new to this stuff can u tell me where the truffle config is available??

no i dont have this code on github
i am sending u screen shots these are bit readable

On Thu, Feb 21, 2019 at 11:16 PM tyler feickert notifications@github.com
wrote:

@sushanth3366 https://github.com/sushanth3366 Is your code available
somewhere on github so I can take a look? The above is very difficult to
read.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/trufflesuite/truffle/issues/852#issuecomment-466096280,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AssV5nw8Iv3O6WuT10DEciWNCX0vqaopks5vPttngaJpZM4Sut52
.

@sushanth3366 It is the file in the root directory of a truffle project named truffle-config.js (it also could be named truffle.js). I'm not sure it looks like deploy.js is set up correctly here...are you using truffle or are you just usingtruffle-hdwallet-provider?

@sushanth3366 , hopefully you were able to figure this out, but if not can you try setting the provider?

Example:

const HDWalletProvider = require('truffle-hdwallet-provider');
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);
web3.setProvider(provider); // <=======================

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);
};
deploy();

Getting the same error. I am using infura.

truffle-config.js

const HDWalletProvider = require('truffle-hdwallet-provider');
// const infuraKey = "";

// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

const mnemonic = config.mnemonic;


ropsten: {
      provider: () => new HDWalletProvider(mnemonic, "https://ropsten.infura.io/v3/" + config.infuraProjectId),
      network_id: 3,       // Ropsten's id
      gas: 1500000,        // Ropsten has a lower block limit than mainnet
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    }

Error Log

> truffle migrate --reset all --network ropsten

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:42:1)
    at e.InvalidResponse [as onreadystatechange] (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/web3/node_modules/web3-providers-http/src/index.js:92:1)
    at e.call [as dispatchEvent] (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at e.dispatchEvent [as _setReadyState] (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at e._setReadyState [as _onHttpRequestError] (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)
    at ClientRequest._onHttpRequestError (/home/prince/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)
    at ClientRequest.emit (events.js:182:13)
    at TLSSocket.socketErrorListener (_http_client.js:391:9)
    at TLSSocket.emit (events.js:182: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)
Truffle v5.0.0 (core: 5.0.0)
Node v10.13.0

@princesinha19 Is config defined in the case above? I don't see it imported or defined anywhere. That would mess up your url.

Thanks @eggplantzzz.
Yes, It's declared. I didn't included it here. I have imported a file where configuration are there.

@princesinha19 Can you also upgrade to the latest version of Truffle to ensure that this is not some problem that has been patched already?

Let me know how it goes. If the problem persists I will try and duplicate your setup to see if I can replicate your problem.

@princesinha19 I was getting the same error. My previous solution still worked on Ropsten. Here is my truffle-config.js

require("dotenv").config()
const HDWalletProvider = require("truffle-hdwallet-provider")

module.exports = {
  networks: {
    ropsten: {
      provider: new HDWalletProvider(
        process.env.HD_WALLET_MNEMONIC,
        `https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`
      ),
      network_id: 3, // Ropsten's id
      gas: 5500000, // Ropsten has a lower block limit than mainnet
      confirmations: 2, // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 50, // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
    },
  },

  mocha: {
    // timeout: 100000
  },

  compilers: {
    solc: {
      version: "0.5.10", // Fetch exact version from solc-bin (default: truffle's version)
      docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {
        // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: false,
          runs: 200,
        },
        evmVersion: "byzantium",
      },
    },
  },
}

@gnidan
I had this issue on

Truffle v5.0.2 (core: 5.0.2)
Solidity - 0.4.24 (solc-js)
Node v11.7.0

I was able to fix this problem by changing provider in truffle-confing.js from

provider: function () {
   return new HDWalletProvider(...)
}

to

provider: new HDWalletProvider(....)

Don't know why this works...

Works for me. Thanks !

rm node_modules/
rm package.json



md5-7e1639a5d2bef800c339bec186df9617



rm package-lock.json



md5-0666100b7832580ac58110ca77ad634b



{
  "dependencies": { 
  }
}



md5-9555c336f42a55419439f8b37ff0e45f



npm install -g npm



md5-db022aa7432b7f78de08bc2f7765fe6b



npm install @truffle/hdwallet-provider --save



md5-223e3ced993a7a1eb9115761f1a530a9



var HDWalletProvider = require("@truffle/hdwallet-provider");



md5-ca4b16a95ba065467eef077242ab7020



truffle migrate --network rinkeby

g provider: new HDWalletProvider(), it cleanly logs the URL once
using provider: () => return new HDWalletProvider(), it logs the url multiple times per migration (2x per artifact.require)

Seems like the () => form is not such a good idea

In my case @roderik sollution worked perfectly. It solved my problem.
I had an issue on ropsten via Infura.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ripper234 picture ripper234  Â·  4Comments

rjl493456442 picture rjl493456442  Â·  4Comments

mezrin picture mezrin  Â·  3Comments

tcurdt picture tcurdt  Â·  3Comments

ysfAskri picture ysfAskri  Â·  4Comments