-
Notifications
You must be signed in to change notification settings - Fork 4
Wasm demo cheatsheet
These commands should show the Wasm chaincode working with the small network from fabric-dev-networks...
Download the Hyperledger Fabric docker images
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s -- 2.0.0-beta 1.4.4 0.4.18 -s -b
Build the fabric-builders builder peer image
docker build -t hyperledgendary/fabric-builder-peer .
Build the fabric-dev-networks custom tools image
docker build -t hyperledgendary/fabric-tools .
Build the fabric-chaincode-wasm Wasm chaincode image
docker build -t hyperledgendary/fabric-chaincode-wasm .
Generate the small network config files
docker run --rm -v small_config:/etc/hyperledger/fabric -w /etc/hyperledger/fabric --entrypoint=/bin/bash hyperledgendary/fabric-tools -c "setnet.sh"
Replace core.yaml
file with one from fabric-builders
docker run --rm -v ${PWD}:/local:ro -v small_config:/etc/hyperledger/fabric -w /etc/hyperledger/fabric --entrypoint=/bin/bash hyperledgendary/fabric-tools -c "cp /local/core.yaml ."
Update the small network docker-compose.yaml
file to use hyperledgendary/fabric-builder-peer
images
sed -i.bak 's|hyperledger/fabric-peer|hyperledgendary/fabric-builder-peer|g' docker-compose.yaml
Bring up the docker compose network
docker-compose -f docker-compose.yaml up -d orderer.example.com peer0.humboldt.example.com couchdb cli
Create the Fabric network
docker exec humboldt.cli mknet.sh
Create a connection.json
file with details of how Fabric will connect to the external service chaincode
{
"address": "wasmcc.example.com:9999",
"dial_timeout": "10s",
"tls_required": false
}
Package the connection.json
file using the pkgcc.sh script
pkgcc.sh -l wasmftw -t external connection.json
Copy the chaincode package to a docker volume for installing
docker run --rm -v ${PWD}:/local:ro -v small_cli:/var/hyperledgendary/fdn -w /var/hyperledgendary/fdn --entrypoint=/bin/bash hyperledgendary/fabric-tools -c "cp /local/wasmftw.tgz ."
Install the new chaincode package
docker exec humboldt.cli peer lifecycle chaincode install /var/hyperledgendary/fdn/wasmftw.tgz
Create a chaincode.env
file, making sure the CHAINCODE_ID matches the chaincode code package identifier from the install command
CHAINCODE_SERVER_ADDRESS=wasmcc.example.com:9999
CHAINCODE_ID=wasmftw:a5ceee0db53cdb4b50975c2379cc346075697873341af71a7440b5d4d7f1ca0c
CHAINCODE_WASM_FILE=/local/fabric_contract.wasm
Run the chaincode
docker run -it --rm -v ${PWD}/contracts:/local:ro --name wasmcc.example.com --hostname wasmcc.example.com --env-file chaincode.env --network=small_fabricdev hyperledgendary/fabric-chaincode-wasm
Approve the chaincode, making sure the CHAINCODE_ID matches the chaincode code package identifier from the install command
docker exec humboldt.cli peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID smallchannel --name wasmftw --version 1 --sequence 1 --waitForEvent --package-id wasmftw:a5ceee0db53cdb4b50975c2379cc346075697873341af71a7440b5d4d7f1ca0c
Commit the chaincode
docker exec humboldt.cli peer lifecycle chaincode commit -o orderer.example.com:7050 --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID smallchannel --name wasmftw --version 1 --sequence 1
Good luck!
docker exec humboldt.cli peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C smallchannel -n wasmftw -c '{"function":"create_asset","Args":["bond007"]}'