2

for using web3.js it is necessary to install geth into your system or it automatically connect with geth or ethereum blockchain?

var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))

here we connect something. In this command we are connecting to what? are we connecting to ethereum public chain or something else?

1

No, it isn't. You can test web3 with e.g. testrpc which also runs on port 8545 so you can connect to it in the same fashion. It makes testing way faster, more lightweight and cheaper (no real money for gas). If you want to work with some public blockchain (main chain or testnet) you could consider infura - but beware of centralization that you might not want!

1

web3.js does not have direct access into the blockchain, it always depends on some client to interface with the Ethereum network. geth is one of many options.

Connecting

When running web3.js, here are some options for connecting:

  1. Mist browser: a web3 object is already built-in and connected! (Mist runs a client for you, under the hood)
  2. Normal web browsers: use the Metamask extension to patch in a web3 object. Metamask chooses which client to connect to.
  3. Local use: connect to a local client that you are running, by calling web3.setProvider()

Client Options

geth is one of many options for local clients. Some others are parity and cpp-ethereum. Remotely hosted nodes like Infura offer access at some cost to privacy & control. I haven't seen much usage of it, but EthereumJ might also be of interest. Get a bit more background and see more esoteric clients on ethdocs.

0

NO, Web3 is a connector between your application and the Ethereum client. You can run ganache-cli or geth as a test client in localhost or you can connect your app to online node like infura using web3.

In your example code it listen to local client witch is run on port 8545 . It may be ganache test network or geth client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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