依赖教程
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);