Create a Chaincode Project with the Blockchain App Builder VS Code Extension
To create a Chaincode Project when using the Blockchain App Builder, you need to scaffold a chaincode project from a detailed specification file. This generates a project with all the files you need.
Background
- 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
- Transient and private data support
- Identity management
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.
Create a Specification File
Before you begin, you need to create an input specification file. Note that you cannot alter the sample specification files that were installed as part of Blockchain App Builder, but you can duplicate them or use them as a reference file for your own specification files.
- In the Specifications pane, select Create New Spec File.
- The Specifications Details pane opens:
- Enter the name for the specification file.
- Select the file type - YAML and JSON are supported.
- Optionally enter a description for the file.
- The Reference File drop-down allows you to generate your specification file from a pre-existing file in your workspace if you have a file you'd like to use as a template. If nothing is selected, the created file will be empty and you can enter your specification from scratch.
- Enter the location where you want the specification file to be stored on your system.
Import a Specification File
- In the Specifications pane, click More Actions and select Import Specification.
- Browse to your file and click Import Specification.
Duplicate a Specification File
You can also duplicate a specification file that's already in your Specifications pane by right-clicking it and selecting Duplicate. Right-click the file and select Rename to update the name.
The details about the contents of specifications files are described here: Input Specification File. Use this information and the sample specification templates to create your specification content.
Scaffolding the Chaincode Project
- In the Chaincodes pane, select Create New Chaincode.
- The Chaincode Details pane opens:
- Enter the name of your chaincode project
- Select the language: TypeScript or Go
- Select the specification file you're using to create the chaincode.
- Enter the location or Go domain where you want the project to be created within your local development environment.
Note:
- The Chaincodes pane allows you open and work with content within the chaincode project, but won't let you add, delete, or rename files within the project. To do that, right-click your project and select Open in Explorer. This opens the project in the VS Code Explorer view.
- Deleting or renaming files in the chaincode project can potentially break the link between the project files and the specification file used to create it. If you plan to synchronize your code between the two, don't change the file names.
Import an Existing Chaincode Project
If you've created a chaincode project through the CLI or you've cleaned your VS Code blockchain content and want to import a locally saved project, in the Chaincodes pane click the More Actions... icon and select Import Chaincode. Browse to the project and click Import Chaincode.