Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement chain Code Development example Commercial Paper by HyperLedger

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how HyperLedger implements chain code development example Commercial Paper. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Chain code development-commercial bond Commercial Paper

Start the test network

Cd fabric-samples/commercial-paper

. / network-starter.sh

Docker-ps will be used to view Fabric nodes running on the local computer

Docker newtwork inspect net_test is used to view the network

Play the role of a magnetic company

Cd fabric-samples/commercial-paper/organization/magnetocorp

Use Magneto's monitoedocker.sh net_test to launch logspout and use it to monitor docker containers associated with net_baisc networks.

Check smart contracts

Const {Contract, Context} = require ('fabric-contract-api') class CommercialPaperContract extends Contract {} async issue (ctx,issuer,paperNumber,issueDateTime,maturityDateTime) let paper = CommercialPaper..createInstance (issuer,paperNumber,issueDateTime...) await ctx.paperList.addPaper (paper) return paper

When a smart contract is deployed to a channel, all entities in the channel can use chain codes, so they must meet multi-party requirements.

Deploy smart contracts

Set the environment variable to facilitate the interaction between CLI and PaperNet source nagnetocorp.sh.

Peer lifecycle chaincode package cp.tar.gz-lang node-path. / contract-label cp_0

Peer lifecycle chaincode install cp.tar.gz

Peer lifecycle chaincode queryinstalled queries the ID of installed chain codes

Peer lifecycle chaincode approveformyorg-- orderer localhost:7050-- ordererTLSHostnameOverride orderer.example.com-- channelID mychannel-- name papercontract-v 0-- package-id $PACKAGE_ID-- sequence 1-- tls-- cafile $ORDERER_CA request endorsement policy

Check the SDK application

Const {Wallets, Gateway} = require ('fabric-network') / / introduces two key classes Wallets and GateWayconst wallet = await Wallets.newFileSystemWallet ('.. / identity/user/isabella/wallet') / / Select a specific logo in the wallet, so that isabella's wallet introduces the local file await gateway.connnect (connectionProfile, connectionOptions) const network = await gateway.getNetwork ('mychannel') const contract = await network.getContract (' papercontract') const issueResponse = await contract.submitTransaction ('issue','MagnetCorp') locally ('00001') / / submit a reply to invoke the transaction issue defined in the smart contract, and the remaining two values indicate that the parameter let paper = CommercialPaper.fromBuffer (issueResponse) / / necessary to create a new commercial bond handles replies from issue transactions, which requires deserialization of the buffer pool.

Npm isntall & & node addToWallet.js

After registering the identity of Isabella, you can call the smart contract.

Play the role of DigiBank

Install and approve the smart contract to receive you at DigiBank

Only when most organizations submit the chain code to the channel will the chain code be officially deployed.

Source digibank.sh configuration environment variables

Peer lifecycle chaincode package cp.tar.gz-- lang node-- path. / contract-- label cp_0 installs chain codes on DigiBank

Peer lifecycle chaincode install cp.tar.gz installs chain codes on peer entities

Export PACKAGE_ID = $(peer lifecycle chaincode queryinstalled) configure the environment variable of the chain code ID

Peer lifecycle chaincode approveformyorg-- orderer localhost:7050-- ordererTLSHostnameOverride orderer.example.com-- channelID mychannel-- name papercontract-v 0-- package-id $PACKAGE_ID-- sequence 1-- tls-- cafile $ORDERER_CA administrator finally approved the chain code.

Peer lifecycle chaincode commit-o localhost:7050-- ordererTLSHostnameOverride orderer.example.com-- peerAddresses localhost:7051-- tlsRootCertFiles ${PEER0_ORG1_CA}-- peerAddresses localhost:9051-- tlsRootCertFiles ${PEER0_ORG2_CA}-- channelID mychannel-- name papercontract-v 0-- sequence 1-- tls-- cafile $ORDERER_CA-- used by the administrator of waitForEventDigiBank

The peer lifecycle chaincode commit command submits paperContract to mychannel. Exe.

Thank you for reading! On "HyperLedger how to achieve chain code development example Commercial Paper" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report