Front end library to interact with smart contract - pinocchio61/Architecture GitHub Wiki

Title: Front-end library to interact with smart contract

Context

When writing data into the smart contract, you will have to wait for the confirmations from the miners to make sure the transaction is valid and is written into blockchain successfully. In this case, the confirmation is an asynchronous request and is difficult for developers to predict when the data is changed in the blockchain. Thus, we hope to find a frontend library that can make developing with smart contracts an easier job.

Investigation of different choices

Pure Web3.js

Since it's the original library that you can use to interact with smart contracts and other libraries are actually the wrappers of this library, it's the most stable and updated library we could find. However, its defect is that we would have to integrate it with our Redux data work flow on our own. It needs more time to set up at the beginning. However, it's not that difficult or complicated and it also makes things more flexible to us. Furthermore, while the biggest problem of using pure Web3.js is the callback hell, it has been solved by promisifying APIs provided in the newly released versions of Web3.js.

Drizzle

It is developed by Truffle Suite. Although it is a spectacular development tools around Redux, it is in its early stage, which makes it less stable and less complete (in develop document) comparing with web3.js. On the other hand, it supports data keys" to monitor whether the data we need in the smart contract is changed, and will re-render our user interfaces after the data has been changed. However, we can develop it on our own. Also, the asynchronous call to smart contract is not that stable. For example, if we want to make sure some data has been responded from the contract and then based on that data to send further calls, it will become quite complex to be achieved in Drizzle.

Truffle-Contract

When integrating this library into our product, I have encountered an issue and you can check from this link. Truffle-Contract may have some leakages when working with some specified version of web3.js. However, although I have used the most stable version, 1.0.0-beta37, I could not solve that problem. Also, it seemed like Truffle-Contract is at its early stage. I worried that we might encounter more issues in the future if we chose to use Truffle-Contract.

Decision

Web3.js is chosen since it is the most stable one and has more complete document. Also, if we encounter any problems, it's more likely that we can find the solution since it has been used by most developers.

Status

Accepted

Consequences

  1. We will have to build our own library which includes frequently used functions.
  2. We will have to integrate it with our own Redux work flow.

Reference