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 [email protected]. Faced the same issue when using [email protected]

1
  • Try using : var web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider(testnet)); May 11, 2018 at 8:22

1 Answer 1

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.

2
  • 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, 2018 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, 2018 at 9:49

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