question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:56 (28 by maintainers)

github_iconTop GitHub Comments

6reactions
roderikcommented, May 4, 2018

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

2reactions
Leon-Africacommented, Dec 14, 2019
rm node_modules/
rm package.json
rm package-lock.json

Create an empty package.json file like this:

{
  "dependencies": { 
  }
}

Update node and npm Ensure latest stable version node installed - currently 12.13.1

The update npm:

npm install -g npm

(restart terminal)

truffle-hdwallet-provider is deprecated: https://www.npmjs.com/package/truffle-hdwallet-provider

Instead use @truffle/hdwallet-provider: https://www.npmjs.com/package/@truffle/hdwallet-provider

(while in your project dir containing the package.json):

npm install @truffle/hdwallet-provider --save

In your truffle-config.js:

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

Then:

truffle migrate --network rinkeby
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Invalid JSON RPC response - Infura Community
I am getting an error. Error: Invalid JSON RPC response: “” truffle-config.js const HDWalletProvider = require('truffle-hdwallet-provider'); ...
Read more >
Error: Invalid JSON RPC response: "" using infura
You are using two providers first you use HDWalletProvider when creating web3 but you override in your contract with a normal HttpProvider. – ......
Read more >
Error: Invalid JSON RPC response while using INFURA
getting error :While implementing ethereum blockchain code , error that i am getting is :Invalid JSON RPC response while using INFURA
Read more >
ConsenSys/truffle - Gitter
guys I have can´t use Infura when I am trying to deploy the contract to the rinkeby network with, ... Error: Invalid JSON...
Read more >
Problem with truffle and hardhat in macos - Support
ERROR IN TRUFFLE Error: Truffle is currently using solc 0.5.16, ... HardhatError: HH110: Invalid JSON-RPC response received: <h1>Not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found