Based Fabric v2.0.1 , the previous version should also be universal.
Article Directory
First, the preparatory work
Fabric Network
- Peer single node
- Single-node Orderer
- Channel has been created
- Peer Join 该 Channel
- Peer enable external builder Reference Fabric 2.0 external builder
- Peer preinstalled Fake Chaincode
Mac or Linux environment to quickly build script based on Fabric Debug Environment
Second, start Peer to Dev mode
When you start to bring Peer dev mode identification, through command-line options --peer-chaincodedev
dev mode is enabled.
Start command is as follows:
bin/peer node start --peer-chaincodedev
Correct start following key log, note WARN log peer will choose a card address to listen 7052 port (see the log information peer.chaincodeListenAddress
) for registrationChaincode
...
2020-03-17 17:38:00.099 CST [nodeCmd] serve -> INFO 00b Running in chaincode development mode
2020-03-17 17:38:00.099 CST [nodeCmd] serve -> INFO 00c Disable loading validity system chaincode
...
2020-03-17 17:38:00.099 CST [nodeCmd] createChaincodeServer -> WARN 00f peer.chaincodeListenAddress is not set, using 192.168.43.62:7052
...
Third, start Chaincode
Peer to dev mode operation, allowing Chaincode
direct connection to Peer registered from the outside.
2.0 Chaincode start change is Chaincode PackageID to identify registered to start, will detect Chaincode is installed when you call, so to install a fake Chaincode PackageID use this fake chaincode registration.
The PackageID to set environment variables FAKE_PACKAGE_ID
for use below.
Chaincode start following information is required:
CORE_CHAINCODE_ID_NAME
: Environment variable to specifyChaincode
thePackageIDHere use$FAKE_PACKAGE_ID
valueCORE_PEER_TLS_ENABLED
: Environment variables , specify whether to enableTLS
, enable TLS also need to configure TLS Key, Cert file, run here do not enable TLS (peer can not configure TLS)--peer.address
: Command line options , registered address peer, see peer boot log
note, Need to debug Chaincode also need approve
, commit
in order to call,And you want to commit
start the registration before (or peer will automatically run fake chaincode)。
First run Chaincode (note replace their peer address)
CORE_PEER_TLS_ENABLED=false CORE_CHAINCODE_ID_NAME=$FAKE_PACKAGE_ID ./module --peer.address 192.168.43.62:7052
IDE runs
approve
& commit
# 设置配置文件路径
export FABRIC_CFG_PATH=/tmp/fabric
# approve 替换下面的变量,--init-required 选项根据自己chaincode觉得是否需要
bin/peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name $CC_NAME --version $CC_VERSION --init-required --package-id $FAKE_PACKAGE_ID --sequence $CC_SEQUENCE --waitForEvent
# commit
bin/peer lifecycle chaincode commit --channelID $CHANNEL_NAME --name $CC_NAME --version $CC_VERSION --init-required --sequence $CC_SEQUENCE
I set up here --init-required
so you need toInit
# init
bin/peer chaincode invoke -o 127.0.0.1:7050 --peerAddresses 127.0.0.1:7051 -C wagaga -n $CC_NAME -I -c '{"Args":["Init", "a","1000","b", "1000"]}'
2020-03-17 17:59:32.799 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
# query
bin/peer chaincode query -C wagaga -n $CC_NAME -c '{"Args":["query","a"]}'
1000
IV Notes
Since the runtime will automatically load 2.0 Peer has started commit
off ChaincodeIf Peer restart too, will automatically start Fake Chaincode, their Chaincode fail to register.
Solution:
After starting his Chaincode failure, stop and start again, stopping to Peer will Deregister
start automatically Chaincode will also chaincodeDeregister
Fifth, another way
2.0 adds Chaincode AS Service , Peer Support initiative to connect Chaincode (requires external builder with support).
Reference official website configuration Chaincode as Service