用docker搭建fabric网络
找到sfhackfest目录
cd $GOPATH/src/github.com/hyperledger/fabric/examples/sfhackfest
确保docker-compose文件用到的imags都有
docker-compose -f docker-compose-gettingstarted.yml build
构建网络并把peer添加到channel
docker-compose -f docker-compose-gettingstarted.yml up -d
创建自己的channel
进入cli容器
docker exec -it cli bash
创建channel
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer channel create -c myc2
这里channel的名称是myc2
会发现当前路径下多了一个文件myc2.block
这个是channel的创始区块(fabric的官方文档说明的)
把peer0节点添加到myc2的channel
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc2.block
这时在peer0的/var/hyperledger/production/ledgersData/blocks/blocks
会多出来channel名字的文件夹myc2
里面包含一个区块文件blockfile_000000
发布合约
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode deploy -C myc2 -n mycc -p github.com/hyperledger/fabric/examples -c '{"Args":["init","a","100","b","200"]}'
合约调用
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode invoke -C myc2 -n mycc -c '{"function":"invoke","Args":["move","a","b","10"]}'
查询状态
CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode query -C myc2 -n mycc -c '{"function":"invoke","Args":["query","a"]}'
捐赠:
BTC: 1NTom3PgUct3WNmnBYNq5KGDQvY3MXs8dJ
ETH:0x8509f0F37497e094924F5c2e776e0dA522c57e43