Create a Chaincode Project with the Blockchain App Builder Visual Studio Code Extension
To create a chaincode project with Blockchain App Builder, you scaffold a chaincode project from a detailed specification file. This generates a project with all the necessary files.
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)
- Rich query support
- Transient and private data support
- Identity management
The generated project follows model/controller and decorator pattern, which enables an asset's properties that are 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 can help with readability and scalability.
Create a Specification File
You must first create an input specification file. 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.
- In the Specifications Details pane, complete the following steps.
- Enter the name for the specification file.
- Select the file type. YAML and JSON formats are supported.
- Optionally, enter a description for the file.
- The Reference File drop-down list lets you generate your specification file from a file in your workspace, if you have a file you want 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 then 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.
For more details about the contents of specifications files, see Input Specification File. Use this information and the sample specification templates to create your specification content.
Validate a Specification File
- Command completion
- Completion of scalar nodes to schema defaults
- Context-sensitive help when you hover over a property or method
- Indents for array items as you type
- Syntax error detection
Scaffolding the Chaincode Project
- In the Chaincodes pane, select Create New Chaincode.
- In the Chaincode Details pane, complete the following steps.
- Enter the name of your chaincode project.
- Select the language: TypeScript or Go.
- Select the specification file that you're using to create the chaincode.
- Enter the location or Go domain where you want the project to be created in your local development environment.
Note:
- The Chaincodes pane lets you open and work with content in the chaincode project, but won't let you add, delete, or rename files in the project. To do that, right-click your project and select Open in Explorer. This opens the project in the Visual Studio 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 Visual Studio 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.