此文档为官方教程的整合,官方教程
you can download the prerequisites using the following commands:
curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
Next run the script - as this briefly uses sudo during its execution, you will be prompted for your password.
./prereqs-ubuntu.sh
不应使用su
或sudo
执行以下安装命令
Essential CLI tools:
npm install -g composer-cli@0.19
Utility for running a REST Server on your machine to expose your business networks as RESTful APIs:
npm install -g composer-rest-server@0.19
Useful utility for generating application assets:
npm install -g generator-hyperledger-composer@0.19
Yeoman is a tool for generating applications, which utilises generator-hyperledger-composer
:
npm install -g yo
Browser app for simple editing and testing Business Networks:
npm install -g composer-playground@0.19
在VSCode
中打开composer的代码,会自动提示安装插件以支持.cto
.qry
等文件。
This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.
In a directory of your choice (we will assume ~/fabric-dev-servers
), get the .tar.gz
file that contains the tools to install Hyperledger Fabric:
mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
tar -xvf fabric-dev-servers.tar.gz
A zip
is also available if you prefer: just replace the .tar.gz
file with fabric-dev-servers.zip
and the tar -xvf
command with a unzip
command in the preceding snippet.
Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric v1.1 runtime:
cd ~/fabric-dev-servers
export FABRIC_VERSION=hlfv11
./downloadFabric.sh
至此,开发环境已部署好了。
The key concept for Hyperledger Composer is the business network definition (BND). It defines the data model, transaction logic and access control rules for your blockchain solution. To create a BND, we need to create a suitable project structure on disk.
Create a skeleton business network using Yeoman. This command will require a business network name, description, author name, author email address, license selection and namespace.
yo hyperledger-composer:businessnetwork
然后会有交互式的选项,按实际开发情况填写。此命令用于生成一个BND的框架。
框架结构如下:
models/ (optional) # 模型文件 .cto
lib/ # 脚本文件 .js
permissions.acl (optional) # 权限控制
package.json
README.md (optional)
然后根据项目需求进行开发,VSCode中有支持Composer开发的插件。
开发完,即定义好business network之后,需要将它打包成.bna
文件,才能部署。
进入到business network的项目目录,执行以下命令
composer archive create -t dir -n .
然后会在当前目录生成一个.bna
文件
创建好.bna
文件之后,可以将业务网络部署到Hyperledger Fabric实例。
将业务网络部署到Fabirc的前提是:已导入PeerAdminCard并开启Fabirc
PeerAdminCard
./createPeerAdminCard.sh
~/fabric-dev-servers/startFabric.sh
To install the business network, from the tutorial-network
directory, run the following command:
composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna
The composer network install
command requires a PeerAdmin business network card (in this case one has been created and imported in advance), and the the file path of the .bna
which defines the business network.
To start the business network, run the following command:
composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card
The composer network start
command requires a business network card, as well as the name of the admin identity for the business network, the name and version of the business network and the name of the file to be created ready to import as a business network card.
To import the network administrator identity as a usable business network card, run the following command:
composer card import --file networkadmin.card
The composer card import
command requires the filename specified in composer network start
to create a card.
To check that the business network has been deployed successfully, run the following command to ping the network:
composer network ping --card admin@tutorial-network
The composer network ping
command requires a business network card to identify the network to ping.
To create the REST API, navigate to the tutorial-network
directory and run the following command:
composer-rest-server
然后会出现交互式的设置,按需求配置即可。
The first time you start up a new runtime, you’ll need to run the start script, then generate a PeerAdmin card:
配置环境变量:
cd ~/fabric-dev-servers
export FABRIC_VERSION=hlfv11
./startFabric.sh
PeerAdminCard
./createPeerAdminCard.sh
composer-playground
composer-rest-server
If you’ve previously used an older version of Hyperledger Composer and are now setting up a new install, you may want to kill and remove all previous Docker containers, which you can do with these commands:
docker kill $(docker ps -q)
docker rm $(docker ps -aq)
docker rmi $(docker images dev-* -q)