Development Preparation
A chaincode, also called a smart contract, is a program written in Go, Java, or Node.js for operating the ledger. It is a code logic that runs on a blockchain and is automatically executed under specific conditions. Chaincodes are an important method for users to implement service logic when using blockchains. Due to the blockchain features, the execution results of smart contracts are reliable and cannot be forged or tampered with.
To use BCS, you must develop your own chaincodes and applications. Applications invoke chaincodes through peers in the blockchain network, and the chaincodes operate ledger data through peers.
Ensure that no security risks (such as command injection) exist in the chaincodes you write and upload.
Preparing the Development Environment
Use the Go or Java development environment based on service requirements.
Preparing the Go Development Environment
- Install the Go development environment. Download the installation package from https://go.dev/dl/. (Select a version later than 1.9.2.)
The package name for each OS is as follows (version 1.11.12 is used as an example):
OS
Package
Windows
go1.11.12.windows-amd64.msi
Linux
go1.11.12.linux-amd64.tar.gz
- In Windows, you can use the .msi installation package for installation. By default, the .msi file is installed in C:\Go. You can add the C:\Go\bin directory to the Path environment variable. Restart the CLI for the settings to take effect.
- In Linux, decompress the downloaded binary package to the /usr/local directory. Add the /usr/local/go/bin directory to the Path environment variable.
export PATH=$PATH:/usr/local/go/bin
After Golang is installed, you can run the go version command to view the version information and run the go env command to view the path configuration.
- Install a Go editor of your choice. GoLand is recommended, which can be downloaded in https://www.jetbrains.com/go/download.
Preparing the Java Development Environment
This is applicable only to Fabric blockchain instances.
- Install the Java development environment. Download the latest JDK version at https://www.oracle.com/technetwork/java/javase/downloads/index.html and install it.
The package name for each OS is as follows (version 15.0.2 is used as an example):
OS
Package
Windows
jdk-15.0.2_windows-x64_bin.exe
Linux
jdk-15.0.2_linux-x64_bin.tar.gz
- In Windows, you can use the .exe installation package for installation.
- In Linux, decompress the downloaded binary package to the /usr/local directory.
export PATH=$PATH:/usr/local/go/bin
Set the environment variables (create them if they do not exist):
- Set JAVA_HOME to the JDK installation directory, for example, C:\Program Files (x86)\Java\jdk1.8.0_91 or /usr/java/jdk1.8.0_91.
- Set CLASSPATH to .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;.
- Add %JAVA_HOME%\bin and %JAVA_HOME%\jre\bin to Path.
After the installation is complete, run the java -version command to view the version information.
- Install a Java editor of your choice. IntelliJ IDEA is recommended.
Downloading the Source Code Package
Download the Fabric source code package as the third-party repository.
Download the required version from the following address:
https://github.com/hyperledger/fabric/tree/release-2.2
The version of the Fabric package should match that of the blockchain. For example, if a blockchain is v4.x.x, it uses Fabric v2.2, so you need to download the Fabric v2.2 package.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot