Hyperledger Fabric应用程序开发讲解

依赖教程

Fabric环境搭建

https://blog.csdn.net/Bjxhub/article/details/119352058

Fabric代码样例体验

https://blog.csdn.net/Bjxhub/article/details/119352058

示例代码位置

网络配置(gateway)

$HOME/go/src/github.com/fabric/fabric/internal/peer/chaincode/testdata/connectionprofile.yaml
$HOME/go/src/github.com/fabric/fabric/internal/peer/common/testdata/connectionprofile.yaml
$HOME/go/src/github.com/fabric/fabric/internal/peer/lifecycle/chaincode/testdata/connectionprofile.yaml

应用程序(application)

$HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/application/issue.js

智能合约(contract)

$HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/commercial-paper/organization/digibank/contract/lib/papercontract.js
$HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/contract/lib/papercontract.js

应用程序发送交易请求步骤:

步骤1:从钱包(Wallet)中选择一个身份(用户+wallet

const { Wallets, Gateway } = require(‘fabric-network’);
const wallet = await Wallets.newFileSystemWallet(’…/identity/user/isabella/wallet’);
const userName = ‘isabella’;

步骤2:连接到网关(gateway)(配置+链接选择项

let connectionProfile = yaml.safeLoad(file.readFileSync(’./gateway/connectionProfile.yaml’, ‘utf8’));
let connectionOptions = {
identity: userName,
wallet: wallet,
discovery: { enabled:true, asLocalhost: true }
};
await gateway.connect(connectionProfile, connectionOptions);

步骤3:访问所需的网络(network)

const network = await gateway.getNetwork(‘PaperNet’);

步骤4:为智能合约(smart contract)构建交易请求(transaction request )

const contract = await network.getContract(‘EuroCommercialPaperContract’);

步骤5:将交易(transaction )提交到网络

const issueResponse = await contract.submitTransaction(‘issue’, ‘MagnetoCorp’, ‘00001’, ‘2020-05-31’, ‘2020-11-30’, ‘5000000’);

步骤6:处理响应(response)

let paper = CommercialPaper.fromBuffer(issueResponse);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A&long@2020

多一份打赏,多一份共享。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值