无法在 hyperledger fabric 中调用链代码
Failed to invoke chaincode in hyperledger fabric
我正在学习如何使用 Hyperledger fabric 和 Chaincode。基本上,我按照这个 link 在 Hyperledger fabric 中创建了一个 Java 链码,但我无法在 cli/channel.
中调用我的链码
我使用了 Hyperledger fabric 官方指南中的 BYFN.sh
来构建 fabric 网络,并按照博客制作了 Gradle & Java Chaincode。
在我尝试用
调用它之后
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["createWallet","tom","100"]}'
我收到这个错误:
Error: error getting endorser client for invoke: endorser client failed to connect to peer0.org2.example.com:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 172.21.0.4:7051: connect: connection refused"
如果有人能指出方向并告诉我可能出了什么问题,那将非常有帮助。我尝试 google 它但找不到任何有用的信息。
更新:
原来是端口号问题。我进入了对等方的一个容器,结果发现端口号是 9051 而不是 7051。所以我在链代码调用命令中更改了端口号,一切正常。
您可以在 https://www.chaincoder.org 上查看免费工具 Chaincoder,这对初学者来说是一个很好的开始。它使用标准 CLI 在 IDE.
中用于结构网络、链代码、通道...
您在命令中为 peer0.0rg1.example.com 和 peer0.0rg2.example.com 指定了相同的端口号。如果您使用 byfn 拓扑创建了网络,peer0.org2 会在端口 9051 上侦听。此外,在询问此类问题时,最好提供您的配置,即 docker-compose.yaml 文件。这对理解题目很有帮助。
您的 compose.yaml 文件中可能没有将 Org2 的端口号映射到其他端口号。
您可以尝试以下任一方法-
查看 docker yaml 文件中定义的端口号,并在调用 chain-code 的命令中使用该端口号。每个同行应该都不一样。
修改yaml文件,让7051重定向到一个新的端口号,比如9051。
像下面
环境:
- CORE_PEER_ID=peer0.org2.example.com
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
卷:
- /var/run/:/主机/var/run/
- ../crypto-config/peerOrganizations/org2.示例.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.示例.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org2.example.com:/var/hyperledger/production
端口:
- 9051:7051
- 9053:7053`.
查看端口号 7051 映射到 9051 的末尾。
我正在学习如何使用 Hyperledger fabric 和 Chaincode。基本上,我按照这个 link 在 Hyperledger fabric 中创建了一个 Java 链码,但我无法在 cli/channel.
中调用我的链码我使用了 Hyperledger fabric 官方指南中的 BYFN.sh
来构建 fabric 网络,并按照博客制作了 Gradle & Java Chaincode。
在我尝试用
调用它之后peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["createWallet","tom","100"]}'
我收到这个错误:
Error: error getting endorser client for invoke: endorser client failed to connect to peer0.org2.example.com:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 172.21.0.4:7051: connect: connection refused"
如果有人能指出方向并告诉我可能出了什么问题,那将非常有帮助。我尝试 google 它但找不到任何有用的信息。
更新:
原来是端口号问题。我进入了对等方的一个容器,结果发现端口号是 9051 而不是 7051。所以我在链代码调用命令中更改了端口号,一切正常。
您可以在 https://www.chaincoder.org 上查看免费工具 Chaincoder,这对初学者来说是一个很好的开始。它使用标准 CLI 在 IDE.
中用于结构网络、链代码、通道...您在命令中为 peer0.0rg1.example.com 和 peer0.0rg2.example.com 指定了相同的端口号。如果您使用 byfn 拓扑创建了网络,peer0.org2 会在端口 9051 上侦听。此外,在询问此类问题时,最好提供您的配置,即 docker-compose.yaml 文件。这对理解题目很有帮助。
您的 compose.yaml 文件中可能没有将 Org2 的端口号映射到其他端口号。
您可以尝试以下任一方法-
查看 docker yaml 文件中定义的端口号,并在调用 chain-code 的命令中使用该端口号。每个同行应该都不一样。
修改yaml文件,让7051重定向到一个新的端口号,比如9051。 像下面
环境:
- CORE_PEER_ID=peer0.org2.example.com
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org2MSP
卷:
- /var/run/:/主机/var/run/
- ../crypto-config/peerOrganizations/org2.示例.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org2.示例.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org2.example.com:/var/hyperledger/production 端口:
- 9051:7051
- 9053:7053`.
查看端口号 7051 映射到 9051 的末尾。