当前位置:   article > 正文

fabric(token-erc-20链码部署)_部署erc20 token

部署erc20 token

确保自己已经安装了fabric。没有安装的可以参考我之前的教程fabric中bootstrap.sh到底帮助我们干了什么?(手动执行相关操作安装fabric2.4)_./bootstrap.sh_小小小小关同学的博客-CSDN博客小伙伴们在跟着官方示例来安装fabric的时候都是相当烦恼的,curl -sSL https://bit.ly/2ysbOFE | bash -s 这个命令怎么执行都是失败的,搞来搞去也没搞明白到底在干嘛最后白白浪费掉了一天的时间(实际上由于网络的原因)。这篇文章介绍如何快速稳定安装官方示例fabric-samples文件、拉取二进制文件和下载所需要的镜像来代替官方示例的这行代码。选取自己的版本后就可以看到官方文档我选取的是2.4。https://blog.csdn.net/qq_45875349/article/details/128138469?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22128138469%22%2C%22source%22%3A%22qq_45875349%22%7D


1.环境准备

进入test-network目录下,使用which peer 检查一下环境是否有问题

如果有问题就下面指令配置一下(后面的路径根据自己的fabric-sample路径确定)

export PATH=$PATH:/home/ubuntu/go/src/github.com/hyperledger/fabric-samples/bin

使用 echo $FABRIC_CFG_PATH 查看是否输入相关路径,否则输入指令

export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/

可以启动两个回话模拟两个组织 org1 和 org2 ,在两个会话中分别输入下面的指令以配置环境

org1

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

org2

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051

然后使用peer channel list指令查看目前通道情况

报错情况:

ubuntu@VM-16-12-ubuntu:~/go/src/github.com/hyperledger/fabric-samples/test-network$ peer channel list

2022-12-06 21:07:20.412 CST 0001 ERRO [main] InitCmd -> Cannot run peer because cannot init crypto, specified path "/home/ubuntu/go/src/github.com/hyperledger/fabric-samples/config/msp" does not exist or cannot be accessed: stat /home/ubuntu/go/src/github.com/hyperledger/fabric-samples/config/msp: no such file or directory

原因是因为没有配置环境变量来使用org1或者org2来进行交互

2. erc20部署

2.1 打包链码

在打包链码之前先检查一下erc20链码所在的目录中是否包含vendor,如果没有的话依旧是手动拉取

ls ../token-erc-20/chaincode-go/

我这里没有,所以需要执行下面命令手动拉取

cd ../token-erc-20/chaincode-go/

go mod vendor

然后再回到test-network目录下打包链码(org1)

peer lifecycle chaincode package erc20.tar.gz --path ../token-erc-20/chaincode-go/ --lang golang --label erc20_1.0 


2.2 安装链码(1&2)

peer lifecycle chaincode install erc20.tar.gz

查看链码安装情况

peer lifecycle chaincode queryinstalled

设置环境变量(org1+org2)

export ERC20_ID=erc20_1.0:7c99f9616d100b2736ad1d03850e24b844e0d5d1af433b8ab673ba934acf8e8c

approve(org1+org2)

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name erc20 --version 1.0 --package-id $ERC20_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

可以检查一下是否可以commit

peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name erc20 --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

commit(org1/org2)

peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name erc20 --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt

2.3 测试erc20

mint测试(只有org1可以执⾏) mint相当于初始化最初的资源数量 类似于发行货币

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n erc20 --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 –tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"Mint","Args":["900"]}'

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/98040
推荐阅读
相关标签
  

闽ICP备14008679号