无法运行基于 Node.js 和 Hyperledger Fabric 2.1 的区块链应用程序

无法运行基于 Node.js 和 Hyperledger Fabric 2.1 的区块链应用程序

我想要做的事(文章的简短部分)

我想成功运行下面的项目

问题

我从 GitHub 安装了一个区块链项目,它使用 Node.js 和 HyperlederFabric V2.1 构建。这是它的链接:https://github.com/TasinIshmam/blockchain-academic-certificates完全按照说明安装后,我运行了 web-frontend,在“注册”和“登录”时没有发现任何错误,但是当我点击“大学”页面中的“问题”按钮时,出现了一些错误:

Schema v1 does not exist
Error: Schema v1 does not exist
    at SingleQueryHandler.evaluate (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/node_modules/fabric-network/lib/impl/query/singlequeryhandler.js:41:27)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Transaction.evaluate (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/node_modules/fabric-network/lib/transaction.js:275:25)
    at async Object.invokeChaincode (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/services/fabric/chaincode.js:65:32)
    at async generateMerkleTree (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/services/encryption.js:17:22)
    at async Object.generateMerkleRoot (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/services/encryption.js:41:18)
    at async Object.issueCertificate (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/services/university-service.js:25:22)
    at async postIssueCertificate (/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/web-app/controllers/university-controller.js:73:31)

我尝试过的解决方案

我向一些人寻求帮助,但大多数人也不知道原因,其中有一个人说我可能没有很好地打包链代码。实际上,我 100% 确定我使用正确的路径和方法打包了链代码。此外,我尝试阅读和理解源代码,但失败了...

以下是我的整个安装记录:(我使用带有 Ubuntu 20 的 AWS EC2)

#step1 install go 1.1.9
wget https://studygolang.com/dl/golang/go1.19.linux-amd64.tar.gz
tar -xzf go1.19.linux-amd64.tar.gz
rm -rf go1.19.linux-amd64.tar.gz
mv go/ /usr/local/
echo 'export GOROOT=/usr/local/go'>> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

#step2 install docker and docker-compose
sudo apt-get update
sudo apt install docker.io
sudo apt install docker-compose

#step3 install mongodb 4.4
sudo apt-get install gnupg curl
curl -fsSL https://pgp.mongodb.com/server-4.4.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org=4.4.23 mongodb-org-server=4.4.23 mongodb-org-shell=4.4.23 mongodb-org-mongos=4.4.23 mongodb-org-tools=4.4.23
sudo systemctl start mongod
sudo systemctl status mongod

#step4 install node 12
cd ~
curl -sL https://deb.nodesource.com/setup_12.x -o setup_12.sh
sh ./setup_12.sh
sudo apt update
sudo apt install nodejs
node -v

#step5 install dotenv tool 
npm install dotenv -g

#step6 install hyperledger fabric 2.1.0 and run
mkdir -p /root/go/src/github.com/hyperledger
cd /root/go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
cd fabric/
git checkout v2.1.0
cd scripts/
./bootstrap.sh 
cd fabric-samples/test-network
./network.sh up createChannel -ca -c mychannel -s couchdb


#step7 install the project mentioned before and instll chaincode in fabric,by the way,"FABRIC_CHAINCODE_NAME"in .env file should be fabcar in this case.if you set the value "fabcar_1",it will failed when you login in web-frontend.
cd ..
cd chaincode
git clone https://github.com/TasinIshmam/blockchain-academic-certificates.git
cd blockchain-academic-certificates/web-app
npm install
npm install --only=dev
touch .env 
echo 'MONGODB_URI_LOCAL = mongodb://localhost:27017/blockchaincertificate'>> .env
echo 'PORT = 3000'>> .env
echo 'LOG_LEVEL = info'
echo 'EXPRESS_SESSION_SECRET = sdfsdfddfgdfg3242efDFHI234'>> .env
echo 'CCP_PATH =/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.json'>> .env
echo 'FABRIC_CHANNEL_NAME = mychannel'>> .env
echo 'FABRIC_CHAINCODE_NAME = fabcar'>> .env
cd ..
cd chaincode
npm i
cd  /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
peer lifecycle chaincode package fabcar.tar.gz --path /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/chaincode/  --lang node --label fabcar_1
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
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/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode install fabcar.tar.gz
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/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051
peer lifecycle chaincode install fabcar.tar.gz

#the command above will return a "PACKAGE_ID",add it below,just like"export CC_PACKAGE_ID=fabcar_1:69de748301770f6ef64b42aa6bb6cb291df20aa39542c3ef94008615704007f3"
export CC_PACKAGE_ID=fabcar_1:

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --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
peer lifecycle chaincode querycommitted --channelID mychannel --name fabcar --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
cd /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/blockchain-academic-certificates/wep-app
npm run start-development

#step 8 Finnaly opening browser and access localhost:3000

您能重复上述步骤后给我一些建议吗?我很感激!

相关内容