Interacting with contracts via frontends
It is desirable to interact with the contracts in a user-friendly manner via a webpage. It is possible to interact with the contracts using the web3.js
library from HTML-/JS-/CSS-based webpages.
The HTML and JavaScript frontend
The HTML content can be served using any HTTP web server, whereas web3.js
can connect via local RPC to the running Ethereum client (geth
) and provide an interface to the contracts on the blockchain. This architecture can be visualized in the following diagram:
Figure 15.6: web3.js, frontend, and blockchain interaction architecture
If web3.js
is not JavaScript frontend already installed, use these steps; otherwise, move on to the next section, Interacting with contracts via a web frontend.
Installing Web3.js JavaScript library
Web3, which we discussed earlier in this chapter, was looked at in the context of the Web3 API exposed by geth
. In this section, we will introduce the Web3...