using infura in truffle and get Error: Invalid JSON RPC response: ""
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.
@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