Skip to content

Instantly share code, notes, and snippets.

@jt-nti
Last active November 2, 2023 17:39
Show Gist options
  • Save jt-nti/1393262178a61a8130c136cde6046092 to your computer and use it in GitHub Desktop.
Save jt-nti/1393262178a61a8130c136cde6046092 to your computer and use it in GitHub Desktop.
From zero to fabric network with minimum effort
#!/usr/bin/env sh
set -euxo pipefail
go install github.com/hyperledger-labs/microfab/cmd/microfab@latest
mkdir -p microfab-test
pushd microfab-test
mkdir -p chaincode
pushd chaincode
curl -sSL https://github.com/hyperledger-labs/microfab/raw/main/integration/data/asset-transfer-basic-typescript.tgz -o asset-transfer-basic-typescript.tgz
popd
export MICROFAB_CONFIG='{
"endorsing_organizations":[
{
"name": "TestOrg"
}
],
"channels":[
{
"name": "testchannel",
"endorsing_organizations":[
"TestOrg"
]
}
]
}'
# docker rm microfab
# microfab stop
# microfab start
docker run -d --rm -v $(pwd)/chaincode:/home/microfab/chaincode:ro -p 8080:8080 --name microfab -e MICROFAB_CONFIG ghcr.io/hyperledger-labs/microfab:latest
# Urg! Use microfab ping?
sleep 5
cat << ADMIN-TESTORG-ENV-EOF > admin-testorg.env
CORE_PEER_LOCALMSPID=TestOrgMSP
CORE_PEER_MSPCONFIGPATH=/home/microfab/data/admin-testorg
CORE_PEER_ADDRESS=testorgpeer-api.127-0-0-1.nip.io:8080
ADMIN-TESTORG-ENV-EOF
docker exec -it --env-file admin-testorg.env microfab \
/usr/local/bin/peer channel list
docker exec -it --env-file admin-testorg.env -w /home/microfab/chaincode microfab \
/usr/local/bin/peer lifecycle chaincode install asset-transfer-basic-typescript.tgz
export PACKAGE_ID=$(docker exec -it --env-file admin-testorg.env -w /home/microfab/chaincode microfab \
/usr/local/bin/peer lifecycle chaincode calculatepackageid asset-transfer-basic-typescript.tgz | tr -d '\r') && echo $PACKAGE_ID
# export PACKAGE_ID=$(echo $(docker exec -it --env-file admin-testorg.env -w /home/microfab/chaincode microfab \
# /usr/local/bin/peer lifecycle chaincode calculatepackageid asset-transfer-basic-typescript.tgz) | tr -d '\r') && echo $PACKAGE_ID
# (echo -n "PACKAGE_ID="; docker exec -it --env-file admin-testorg.env -w /home/microfab/chaincode microfab \
# /usr/local/bin/peer lifecycle chaincode calculatepackageid asset-transfer-basic-typescript.tgz) > asset-transfer-basic-typescript.env
docker exec -it --env-file admin-testorg.env microfab \
/usr/local/bin/peer lifecycle chaincode approveformyorg \
--orderer orderer-api.127-0-0-1.nip.io:8080 \
--channelID testchannel \
--name assettx \
-v 0 \
--package-id $PACKAGE_ID \
--sequence 1
docker exec -it --env-file admin-testorg.env microfab \
/usr/local/bin/peer lifecycle chaincode commit \
--orderer orderer-api.127-0-0-1.nip.io:8080 \
--channelID testchannel \
--name assettx \
-v 0 \
--sequence 1 \
--waitForEvent
docker exec -it --env-file admin-testorg.env microfab \
/usr/local/bin/peer chaincode query \
-C testchannel \
-n assettx \
-c '{"Args":["org.hyperledger.fabric:GetMetadata"]}'
microfab stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment