Running a smart contract using Web3.js
In this section, we will do a hands-on tutorial. So put on your lab coats! We will do the following right now:
- Install Web3.js from GitHub.
- Install an HTTP server and get it up and running.
- Write a quick-and-dirty JavaScript smart contract using Web3.js.
- Open geth and attach our private blockchain with Web3.js.
- Open a web browser to launch our smart contract using Web3.js.
- Open Mist to validate the outcome of our smart contract.
To install Web3.js from GitHub on Windows, we require the git bash kernel. Once we have installed the git bash kernel, we can clone the Web3.js GitHub path and download the HTTP server using the following command:
> git clone https://github.com/ethereum/web3.js.git> install -g http-server
The outcome is as follows:
Figure 7.4: Web3.js and http-server installation from GitHub
Once the HTTP server is installed, we can kick-start the server with the http-server
command. To kill the server instance, we need to press Ctrl + C. Now we...