In this post, we’ll explain why to use gRPC and show how to develop DApp quickly by AMIS tools.

sol2proto. Convert solidity ABI to gRPC proto. grpc-contract. Generate corresponding gRPC server code.

In our proposed solution, the only thing you have to do is to write contract code and we would take care the rest for you. :)

Problem Statement

In DApp architecture, the client communicates with smart contract through a server. However, in traditional development, there are some weaknesses:

No interface definition between client and server. It’s hard to work across languages and platforms between client and server. Although in most cases the server just relays the requests to a contract, we still need to write the relaying codes to pass the requests to the corresponding contract calls.

DApp Architecture

Approach

To solve above issues, we decide to use gRPC to define the client-server interface, and generate the interface as well as the server from solidity ABI (Application Binary Interface) file automatically. Below are the tools we used:

solc: generates contract ABI and BIN files from contract code.

generates contract ABI and BIN files from contract code. abigen: generates go-binding code from ABI and BIN files.

generates go-binding code from ABI and BIN files. sol2proto: generates proto file from ABI file. In ABI file, it defines the interface of the contract which can be converted to the corresponding proto file.

generates proto file from ABI file. In ABI file, it defines the interface of the contract which can be converted to the corresponding proto file. grpc-contract: generates the server implementation code based on proto and go-binding file.

Below are our proposed DApp development flow:

Write the contract code. Use solc to generate ABI and BIN files. Use abigen to generate the go binding code for the contract. Use sol2proto to generate the proto file. Use grpc-contract to generate the server code. Done!

Proposed Flow

Proposed Architecture

Example

This exercise can be found in https://github.com/getamis/grpc-contract/tree/master/examples.

If you run into issues, feel free to file issues on sol2proto or grpc-contract. You can find other interesting projects in our github.

AMIS

Amis is a financial technology creating bonds between people as they pay, creating a secure system centered on its community. Using breakthrough blockchain technology, Amis has created a standardized platform to let business create information exchange systems and make transaction data open and shareable to improve the quality of life for everyone.

References