Block Contract

This is a hackathon project for "The Building Blocks Hackathon at Consensus 2019" (

Block contract is to build decentralized contract that people can sign, view and trust. To protect the privacy, the content of the contract will NOT be hosted in the blockchain, only the hash of the content is store in the chain.

We use ArcBlock's Forge React Stater to build this application and let it handle the basic logic like DID login, so that we can focus on building the core logic.

High level design

The prototype of the flow of the app looks like this:


Contract Templates

Accord Project is a great open source tool to generate legal contracts. The ultimate goal is integrate this project with Accord Legal Contract Template Studio.


We will use ArcBlock's ForgeFrame to build a custom blockchain for this project's demo. The block explorer lives here: Block Contract Block Explorer

It's possible to use other blockchains, such as Ethereum, Bitcoin to record the contract through Open Chain Access Protocol (OCAP), but it will be limited in features.

DB schema for contract

For contract created by the user, we store it as the following schema in mongo:

const ContractSchema = new mongoose.Schema({
  // the did is calculated by sha3(concat(content, hash, signatures list without each sig))
  _id: { type: String, required: true, trim: true },
  requester: {type: String, required: true, trim: true},
  synopsis: { type: String, required: true, trim: true },
  content: { type: Buffer, required: true },
  hash: { type: String, required: true },
  signatures: [{
    name: { type: String, required: true, trim: true },
    email: { type: String, required: true, trim: true },
    signedAt: { type: Date },
    signature: { type: Buffer }
  finished: { type: Boolean, default: false},
  address: { type: String, default: '' },
  createdAt: { type: Date },
  updatedAt: { type: Date },

Asset Schema for CreateAssetTx protocol

Once a doc is finished signing, we will send a CreateAssetTx to Forge, with its data like this:

message Signature {
  string name = 1;
  string email = 2;
  string signer = 3;
  google.protobuf.Timestamp signed_at = 4;
  bytes signature = 5;
message Contract {
  // did of the contract that stored in the Block Contract app
  string did = 1;
  // hash of the original contract to be signed
  string hash = 2;
  // collected signature list
  repeated Signature signatures = 3;

Run this project from Repo

Install latest nodejs and mongodb

brew upgrade node
brew install mongodb
brew services start mongodb

Install latest forge-cli and init forge

npm install -g @arcblock/forge-cli
forge init
forge join
forge start
forge web start

Start the Block Contract app

cd block-contract
make dep

Before running the app, you need to put a .env file into your repo:

cat > .env
APP_NAME="Block Contract"
EMAIL_USER="<your gmail address>"
EMAIL_PASS="<your gmail password>"

Note that you need to put your gmail user/pass and tune the BASE_URL here.

Make sure that you have your cellphone installed ABT Wallet and it is under the same WIFI as your laptop running the app. Then:

make run

Screen Shots

Pages are being added so screen shots will be gradually available:

The new frontpage

Block contract

Step 1: Scan QR code to login (provided by Forge React Starter kit)

login 1

After you scanned the QR code with ABT wallet:

login 2

Then you are redirect to profile page. User can see the existing contracts:

List contracts

Step 2: Create a new contract

You may want to create a new contract:

Create contract

And all the signers will go emails like this:

Email content

Step 3 (for signer): Sign the contract

As a signer, when you got the email, if you click the "View the Contract" button or the link, you will get:

Sign 1

Then scan the QR code with the wallet app:

Sign 2

Once accepted, you signature will be put into the agreement. If all parties finished signing, the doc is signed:

Signed 1

Step 4 (anyone): Verify the contract in the chain

Then anyone can check the signatures on the chain:

Signed 2

We could make this view much better later on.

Below is created by forge-react-starter. Leave it just for your information.

About Forge React Starter

This project is generated by ArcBlock's Forge React Starter:

Brings tons of thousands react libraries/components to dApps that run on forge powered blockchain.

A starter project that integrates forge javascript sdk with mainstream javascript application batteries:

Forge SDK libraries included in the starter project:

Other javascript project goodies:

  • eslint: for consistent coding style
  • prettier: for consistent code formatting
  • husky: and lint-staged for prepush and precommit hooks
  • nodemon: for auto restart server on node.js code change
  • next.js: supports hot reload on client code change
  • dotenv: to load configurations from .env files

Folder Structure

├── Makefile
├── app.js                    // application entry file
├── client                    // code for client side pages
│   ├── babel.config.js       // custom babel configuration
│   ├── components            // shared react components/layouts across all pages
│   ├── hooks                 // shared react hooks
│   ├── libs                  // shared utility code
│   ├── next.config.js        // custom next.js configuration
│   ├── pages                 // pages
│   └── static                // static assets that can be loaded by browser
├── package.json
├── server                    // backend code
│   ├── libs                  // shared server libs
│   ├── models                // mongoose db models
│   └── routes                // express routes and handlers
├── version
└── yarn.lock

Runtime Requirements

  • Mongodb v3+
  • Node.js v10+
  • That's all


Create new project with forge-cli

npm install -g @arcblock/forge-cli
forge init
forge start
forge create-project hello-forge
cd hello-forge
npm start

Just use this starter repo

Note: You have to setup an .env file manually.

git clone
cd forge-react-starter


dApp configuration file is auto generated and stored in .env, example configure as:

APP_NAME="Forge Starter"

Caution: .env contains very sensitive info such as Application wallet secret key, PLEASE DO NOT COMMIT .env FILE


Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Built With

Share this project: