0

I'm new to Ethereum Blockchain. I have been trying to send ether using web3.js npm. Here's my code

const testnet = `https://ropsten.infura.io/${process.evn.ACCESS_TOKEN}`;
let web3 = new Web3(new Web3.providers.HttpProvider(testnet));

web3.eth.personal.unlockAccount(adminWalletAddress, password, 1000)
.then(data => console.log(data))
.catch(err => console.log(err))

I'm getting an error response -

Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/web3-core-helpers/src/errors.js:42:16)
at XMLHttpRequest.request.onreadystatechange (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/web3-providers-http/src/index.js:73:32)
at XMLHttpRequestEventTarget.dispatchEvent (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/home/rplanx/Dwip/node_ethereum/web3-1-x-x-contract-transaction/node_modules/xhr2/lib/xhr2.js:469:24)
at IncomingMessage.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:178:19)

The response is same for web3.eth.sendTransaction method. I'm using web3@1.0.0-beta.34. Faced the same issue when using web3@0.20.4

marked as duplicate by Ismael, Achala Dissanayake, mirg, Richard Horrocks, Linmao Song May 11 '18 at 14:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Try using : var web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider(testnet)); – Prashant Prabhakar Singh May 11 '18 at 8:22
0

This account unlock is valid if you have your keys in the node and this is not the case with Infura. You need to build the transaction and sign it with your private key. Then, you can use sendRawTransaction method. Even if Infura is accepting this (which I do not think so) this absolutely insecure to do, because your keys would be in control of someone else.

  • yes I have tried sending a raw transaction and it worked. Is there any test node available where this code will run? I mean the unlockAccount code. Thanks in advance – dkpaul91 May 11 '18 at 9:42
  • Then you are on the safe side. If raw transactions work, why are you looking further for a solution that put your keys in someone else hands? My recommendation would be then to run your own node, is the only way your keys are safe. – Jaime May 11 '18 at 9:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.