Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Fabric SDK in GO

This SDK enables Go developers to build solutions that interact with Hyperledger Fabric.

使用说明

初始化配置请参考connection.yaml
1.1 实例化一个对象

sdk, err := fabricsdk.New("./test/connect-profile.yaml")
if err != nil {
    return err 
}
// 创建gateway
g, err := sdk.NewGatewayWithAdmin()
if err != nil {
    return err 
}

1.2 创建通道与加入通道

channelFile := channel.NewChannelFile("mychannel", "./test/mychanne.tx")
err := g.CreateChannel(channelFile)
if err != nil {
    // handle error 
}

err = g.JoinChannel("mychannel")
if err != nil {
    // handle error 
}

1.3 安装链码

chaincodeSpec := chaincode.GetChaincodePackageFromLocal("./mycc.tar.gz")
err := g.InstallChaincode(chaincodeSpec, /* client.WithPeer("peer0.org1.bnpschainta.com") */)
if err != nil {
    // handle error 
}

err = g.ApproveChaincode("mycc", "1.0", "mychannel")
if err != nil {
    // handle error 
}

// 如果有多个组织同样执行切换到对应gateway,并同样调用`ApproveChaincode`方法 

err = g.CommitChaincode("mycc", "1.0", "mychannel")
if err != nil {
    // handle error 
}

1.4 调用链码

c, err := g.NewContract("mycc", "1.0", "mychannel")
if err != nil {
    // handle error 
}
args := [][]byte{[]byte("invoke"), []byte("a"), []byte("b"), []byte("2000")}
resp, err = c.Invoke(args, /* contract.WithTimeout(3*time.Second) */)
if err != nil {
    // handle error 
}

args := [][]byte{[]byte("query"), []byte("a")}
resp, err := c.Query(args)
if err != nil {
    // handle error 
}

Comments ( 0 )

Sign in for post a comment

About

fabric go sdk spread retract
Go
MulanPSL-2.0
Cancel

Contributors

All

Activities

load more
can not load any more