7 Web3 and a channel Dapp

 

This chapter covers

  • Using the web3 API to access Ethereum client node functions
  • Programming with web3 modules and a web3 provider
  • Designing a Dapp with a side channel
  • Implementing a micropayment channel for a global cleanup problem
  • Connecting off-chain operations with on-chain operations

The focus of this chapter is web3. Using web3, you can pretty much set your Dapp on autopilot. What is web3? The web3 API, called simply web3, is a comprehensive package for accessing blockchain functions. Blockchain infrastructure provides services for managing accounts, recording transactions (Txs), and executing smart contracts, all of which you explored in previous chapters. Web3 exposes the functions of the Ethereum blockchain client node; it facilitates the interaction of external applications and the blockchain node, and it facilitates programs to access blockchain services. You used web3 in Dapp application development in chapters 4 and 6, which discussed web3 use at a high level. In chapter 4, you used web3.js in Dapp development as part of the glue code (app.js) between the web application and the smart contract, and you included web3 (the minified version in web3.js.min) in the Dapp.

Definition

web3.js is a JavaScript library--commonly referred to as web3--that enables applications to access the services offered by the Ethereum blockchain client node.

7.1 Web3 API

7.1.1 Web3 in Dapp stack

7.1.2 Web3 packages

7.2 The channel concept

7.3 Micropayment channel

7.4 Micropayment channel use case

7.4.1 Traditional banking solution

7.4.2 Users and roles

7.4.3 On-chain and off-chain operations

7.4.4 MPC smart contract (MPC-contract)

7.4.5 MPC application development (MPC-app)

7.4.6 MPC sequence diagram

7.4.7 Demonstration of MPC execution

7.4.8 Accessing the web3 provider