0

I'm trying to create an account through Node.js. This is my code:

export async function createNewAccount() {
    var web3Instance =  new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    return web3Instance.eth.accounts.create();
}

But I'm getting the following error (from 'create' function):

Invalid JSON RPC response: undefined

I have installed web3.js in my project.

What other step have I missed?

BTW opening the browser on address "http://localhost:8545" returns 404. Is there anything I need to install in order to make it work? Is that the testrpc?

Notice that I want to work against the real blockchain, not a test one.

Edit:

As suggested by Karthikeyan, I downloaded and started geth. I don't know if it's actually working, it looks like this:

enter image description here

But I keep getting the same error when I try to create an account.

11
  • Have you started Local Blockchain in your system with geth command Commented Nov 9, 2017 at 5:58
  • @KarthikeyanThangavel no I haven't. A local blockchain is a test one? Because I want to work with the real one. Additionally, if I use Node.js should I use Geth? I thought Geth is for Go lang.
    – Alon
    Commented Nov 9, 2017 at 6:27
  • You have start geth in your local system with rpc commands, else you can't communicate with the main Blockchain . Commented Nov 9, 2017 at 9:09
  • @KarthikeyanThangavel are you sure it's geth and not something else? Because the 'g' in 'geth' stands for Go lang, but I don't use Go, I use Node.js.
    – Alon
    Commented Nov 9, 2017 at 9:14
  • Without syncing blockchain in your local system, you cant do any operation blockchain. Commented Nov 9, 2017 at 9:16

1 Answer 1

2

If you have started geth with the code like below, that means its a test network (rinkeby)

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --cache=2048  --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*"

Even if you have started without --rinkeby you must have mentioned the other parameters like --rpc,--rpcapi and all other to work with the web3.js

2
  • I don't want to use a test network. I want the real one. What parameters should I place?
    – Alon
    Commented Nov 9, 2017 at 10:25
  • Remove --rinkeby from the above line and execute it. But better try it on a test network before you do on a real one
    – Rajesh
    Commented Nov 9, 2017 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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