总结部署fabirc以及调试go sdk 遇到的坑

本文总结了在部署Fabric网络及调试Go SDK过程中遇到的九大问题,包括证书过期、重复加入通道、配置文件错误、链码安装等,并提供了详细解决办法。强调了仔细阅读错误日志、理解配置文件和网络环境的重要性。

最近在联调fabirc网络遇到了很多坑,主要是对fabric不够熟悉,所以解决问题的时候即使看到了错误信息,也不能很快的确定具体是那里出现了问题,而且问题确实谷歌不到,所以简单记录一下。

坑1:

 CA Certificate is not valid, (SN: 234551506279605485472670524472959491447): could not obtain certification chain: the supplied identity is not valid: x509: certificate has expired or is not yet valid"

证书过期,错误提示的已经很明显了,但是仔细看错误信息显示过期时间还没到(这里我没把错误截全),但是还重新生成了证书,依然出现过期的错误。

解决办法:

  • 原来是服务器上的时间问题,同步一下时间就好了(这里我用的虚拟机,正常的机器应该不会有这个问题…)

坑2:

Error: proposal failed (err: bad proposal response 500)

加入通道的时候出现这个错误,往往是重复加入channel了,这个问题主要是吃亏在没仔细分析错误志,出现问题还是先不要复制粘贴百度。

解决办法:

  • 将实例进行回滚
  • 修改通道名称和组织名

坑3:

使用fabric-go-sdk 实例化时报错:users not found

读取config.yml文件来创建一个sdk 的实例发生的error,排除自己方法传参无误,配置文件的用户名和orgname 也没有问题,谷歌也查不到,只能对着源码中的示例一个个去对比,对比哪里缺少用户信息的配置。

解决办法:

  • 在organizations 这一层下对应的org 添加上相应的用户名和证书路径
organizations
    org1:
     users:
          Admin:
            cert:
              path: ****.pem
          User1:
            cert:
              path: ****.pem

<

Hyperledger Fabric中编写和部署Hello World链码的步骤如下: 1. 安装Hyperledger Fabric环境和配置网络 - 参考官方文档:https://hyperledger-fabric.readthedocs.io/en/latest/install.html 2. 编写链码 - 创建一个新目录,例如`hello-world-chaincode` - 在该目录下创建一个名为`hello-world.go`的文件,内容如下: ```go package main import ( "fmt" "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/protos/peer" ) type HelloWorldChaincode struct {} func (cc *HelloWorldChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response { return shim.Success(nil) } func (cc *HelloWorldChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response { fmt.Println("Hello, World!") return shim.Success(nil) } func main() { if err := shim.Start(new(HelloWorldChaincode)); err != nil { fmt.Printf("Error starting chaincode: %s", err) } } ``` 3. 打包链码 - 在`hello-world-chaincode`目录下执行以下命令: ```sh go mod init hello-world-chaincode go mod vendor go build ``` - 生成的二进制文件为`hello-world-chaincode` 4. 部署链码 - 使用Fabric CLI工具`peer`来部署链码 - 在命令行中执行以下命令: ```sh peer chaincode install -n hello-world -v 1.0 -p ./hello-world-chaincode peer chaincode instantiate -n hello-world -v 1.0 -C mychannel -c '{"Args":[]}' ``` - 第一条命令将链码安装到对等节点,第二条命令在通道`mychannel`上实例化链码 5. 调用链码 - 在命令行中执行以下命令: ```sh peer chaincode invoke -n hello-world -C mychannel -c '{"Args":[]}' ``` - 此命令将触发链码的`Invoke`函数,输出`Hello, World!` 以上就是在Hyperledger Fabric中编写和部署Hello World链码的步骤。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值