Introducing Web3
Web3 is a JavaScript library that can be used to communicate with an Ethereum node via RPC communication. Web3 works by exposing methods that have been enabled over RPC. This allows the development of user interfaces that make use of the web3 library in order to interact with the contracts deployed over the blockchain.
In order to expose the methods via geth
, the following command can be used:
$ geth --datadir .ethereum/privatenet/ --networkid 786 --rpc --rpcapi 'web3,eth,debug' --rpcport 8001 --rpccorsdomain 'http://localhost:7777'
Note the --rpcapi
flag that allows the web3, eth
and debug
methods.
This is a powerful library and can be explored further by attaching a geth
instance. Later in the section, you will be introduced to the concepts and techniques of making use of web3 via JavaScript/HTML frontends.
The geth
instance can be attached using the following command:
$ geth attach ipc:.ethereum/privatenet/geth.ipc
Once the geth
JavaScript console is running, web3 can be...