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
Hi there! I am using Infura to test out some of my code too. I am using truffle-hdwallet-provider and set my provider to Infura. I am getting the same error, have you found out a solution yet? In my case, I am trying to put a bunch of addresses to my smart contract and transfer some tokens to those addresses. Sometimes I dont get any error and everything works fine, sometimes, typically when I import more than 50 addresses into my smart contract, the error shows up and fails to import maybe 1 or 2 address to the smart contract.
async function config() {
var addressLocation = new Object();
var addressList = [];
// console.log("web3:" , web3)
console.log(
"-------------------START IMPORTING CSV FILE-------------------------",
"\n",
"---------------PLEASE IGNORE THE DEPRECATED WARNING!----------------"
);
csv
.fromPath("./data/airdrop.csv", { headers: false })
.on("data", function(data) {
if (
index < addressCap && //These four lines of code verify if addresses in csv file are valid
web3.utils.isAddress(data[0]) &&
data[0] !== null &&
data[0] !== ""
) {
if (data[0] in addressLocation) {
//This line of code checks if a beneficiary already exist in addressLocation
var was_balance = parseInt(addressLocation[data[0]]); //If exist, simply topup the value of that particular beneficiary
addressLocation[data[0]] = parseInt(data[1]) + parseInt(was_balance);
index++;
} else {
//If the beneficiary does not exist in addressLocation Object, it will be added to the Object and assign it a value.
addressLocation[data[0]] = data[1].toString();
addressList.push(data[0]);
index++;
}
} else {
if (data[0] !== "") {
console.log("ERROR:", data[0], "is invalid");
}
}
})
.on("end", async function() {
console.log("------------------------DONE!------------------------");
var totalValue = 0;
Object.keys(addressLocation).forEach(key => {
totalValue = parseInt(addressLocation[key]) + parseInt(totalValue); //Calculate the total value that needs to be transfered.
});
console.log(
"Benefeciaries are listed HERE:",
"\n",
addressLocation, //Print out addressLocation Object
"\n",
"Total beneficiaries are:",
Object.keys(addressLocation).length, //Print out the length of addressLocation
"\n",
"Airdrop total: ",
parseInt(totalValue) //Print out the total value that needs to be transfered.
);
/*The following code will create a new instance of a depolyed Airdrop contract
NOTE!!!!!!!! Every time you alter the contract(Even one single splace), you need to
re-compile the entire contract on Remix using Solidity Compiler V0.4.23commit. Then
deploy the contract, copy and paste the abi of the contract(Can be retrieved through Remix)
to the variable contractAbi. Copy and paste the address of the contract in the following code
where the comment says //ADDRESS!!!!
*/
const instance = new web3.eth.Contract(
JSON.parse(contractAbi),
"0xa356bdbe3abfb1d6e43b906cc52b6e28f85476b9" //ADDRESS!!!!
);
//Get accounts information
const accounts = await web3.eth.getAccounts();
console.log("ACCOUNTS: ", accounts);
const userAccount = accounts[0];
console.log("Coinbase :", userAccount); //This line will show you the first account in accounts.
/*The following code will first add all the beneficiaries and their corresponding values to smart contract,
then after retriving the receipt, it will send correct values to each address.
If there is any error, you will see errors in the console.
*/
Object.keys(addressLocation).forEach(keys => {
instance.methods
.addingBeneficiaries(keys, addressLocation[keys])
.send({
from: userAccount
})
.then(receipt => {
console.log("ADDING RECEIPT: ", receipt, "FOR USER:", keys);
instance.methods
.airDrop(keys)
.send({
from: userAccount
})
.then(receipt => {
console.log("SENDING RECEIPT:", receipt, "FOR USER", keys);
})
.catch(error => {
console.log(
"ERROR WHILE SENDING TO USER:",
keys,
"ERROR: ",
error
);
});
})
.catch(error => {
console.log("ERROR WHILE ADDING USER:", keys, "ERROR: ", error);
});
});
});
}
config();
here is my code, but I could not reproduce the error today, if I see it in near future I will post it here!
Hi mike, the problem just showed up again, here is the error it throws.
ERROR WHILE ADDING USER: 0xe482a827b66f98db32e75d167ad7b5f98bf4d847 ERROR: Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:15:839620)
at e.n.onreadystatechange (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:15:838649)
at e.t.dispatchEvent (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:1:146545)
at e._setReadyState (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:15:894344)
at e._onHttpRequestError (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:15:898012)
at ClientRequest.<anonymous> (/Users/azhu/Desktop/AirdropProject/Airdrop/node_modules/truffle-hdwallet-provider/dist/index.js:15:895509)
at ClientRequest.emit (events.js:198:13)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
I found that the chance for this error to occur is pretty low, but it does greatly affect the stability of the thing I am building. By looking at the error, I think it is produced by truffle-hdwallet-provider.
Doing some searching on the truffle issues, would appear this is a common issue people are seeing using truffle. We will reach out to them and see what they know and ping this thread as soon as we know more.