Create a Chaincode Project with the Blockchain App Builder CLI

To create a Chaincode Project when using the Blockchain App Builder CLI, you need to scaffold a chaincode project from a detailed specification file. This generates a project with all the files you need.

Background

Blockchain App Builder's init command initializes and scaffolds a chaincode project right out of the box for you. Based on simple input, the init command can generate complex chaincode projects with features such as:
  • Multiple assets (models) and their behaviors (controllers)
  • Auto-generate CRUD (Create/Read/Update/Delete) and non-CRUD methods
  • Automatic validation of arguments
  • Marshalling/unmarshalling of arguments
  • Transparent persistence capability (ORM)
  • Calling rich queries

The generated project follows model/controller and decorator pattern, which allows an asset's properties maintained on the ledger to be specified as typed fields and extended with specific behaviors and validation rules. This reduces the number of lines of code which helps in readability and scalability.

Prerequisites

Before you begin, you need to create an input specification file. The detailed specifications for this file are described here: Input Specification File.

Scaffolding the Chaincode Project with the init Command

Typing ochain init -h will list the command usage with all its options. The init command has four options:
  • --cc/-c:

    The name of the chaincode project. The default value is MyChaincode.

  • --lang/-l

    The language of the scaffolded chaincode. Currently Blockchain App Builder supports Typescript (ts) and Go (go). If no option is given it is defaulted to ts.

  • --conf/-f or -spec

    The path to an input specification file. Blockchain App Builder reads the input specification file and generates the scaffolded project with many helper tools which helps in reducing the overall development effort. Taking full advantage of the input specification file can significantly reduce the development time.

    The specification file could be in yaml or json format. If the path is not specified, it defaults to the current directory. See Input Specification File.

  • --out/-o

    The output directory of the scaffolded chaincode project. If not specified, the scaffolded project is generated in the current directory.

    The output is a fully contained, light-weight and scalable Typescript or Go chaincode project.

Example
my-mac:~ name$ ochain init --cc MyNewTsProject --lang ts --conf spec.yml

Defaults

If no options were specified in the ochain init command, the name of the scaffolded project is MyChaincode and the language is TypeScript.

The MyChaincode.model.ts contains only one asset called MyAsset with one property named value. MyChaincode.controller.ts contains one controller with the corresponding CRUD methods for the MyAsset model.

Output

When the process is complete, you'll have a fully-functional chaincode project that you can deploy either locally or to a remote Oracle Blockchain Platform. For a detailed overview of the files created, see: