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 use Fabtoken in Hyperledger Fabric 2.0

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces how to use Fabtoken in Hyperledger Fabric 2.0, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

There is a new feature in Hyperledger Fabric 2.0 (alpha): Fabtoken, which natively supports the issuance and management of digital cryptocurrencies. We all know that the ERC20 standard of Etay Fang can be used to create digital encrypted tokens on the etherfang block chain. now with Fabtoken, developers can easily use Hyperledger Fabric to achieve digital encrypted currency issuance, money transfer and other functions!

1. Install Hyperledger Fabric 2.0

First of all, we need to install the basic platform of Fabtoken: Hyperledger Fabric 2.0. Download and install using the following command:

Curl-sSL http://bit.ly/2ysbOFE | bash-s-2.0.0-alpha 2.0.0-alpha 0.4.15

Note that to avoid potential conflicts, if you have installed other versions of HyperledgerFabric before, please uninstall them first.

2. The core functions of Fabtoken

The core functions of Fabtoken are as follows:

Create a new cryptocurrency

Digital encrypted currency transfer

Query transfer transactions

Redeem digital cryptocurrency

In most cases, the first three functions are sufficient.

3. Fabtoken pilot test

Once Fabric 2.0 is installed, you can use docker images for quick verification.

Now execute the following command to enter the Fabtoken directory:

Cd $HOME/fabric-samples/fabtoken

Fabtoken requires a Fabric network to run, which contains a sample node application fabtoken.js and a bash script startFabric.sh, both of which are in the current directory. The bash script starts basic-network first, then goes to the javascript directory, runs npm install to install the necessary npm dependencies, and finally starts the fabtoken demo application.

We strongly recommend that you take a look at the contents of this bash script.

Now run the bash script by executing the following command:

. / startFabric.sh

OK, now we can start to try the function of Fabtoken!

First create 1000 gold coins for user1:

Node fabtoken issue user1 goldcoin 1000

You will see the following output:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideToken arg: goldcoinToken arg: 1000Start issue token operationStart token issue with args goldcoin,1000End issue token operation, returns {status: 'SUCCESS', info:'}-fabtoken.js-end

Obviously, it worked!

Now let's take a look at user1's gold coin assets:

Node fabtoken list user1

The output is as follows:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideStart list token operationEnd list token operation, returns [{id: {tx_id: 'e0b8a7ce6b248b8733ac7659c32a45b04a571de2548e371ada810a1e8bcf8eacial, index: 0}, type:' goldcoin', quantity: '1000'}]-- fabtoken.js-end

Good!

Next, suppose user1 is very generous and decides to transfer 10 gold coins to user2:

Node fabtoken transfer user1 user2 10\ e0b8a7ce6b248b8733ac7659c32a45b04a571de2548e371ada810a1e8bcf8eac 0

The above command indicates the transfer of 10 gold coins from user1 to user2, using the following transaction output as transaction input:

Txid:e0b8a7ce6b248b8733ac7659c32a45b04a571de2548e371ada810a1e8bcf8eac

Index:0

You may ask, why do transfer orders specify a transaction id and serial number? The answer is that Fabtoken uses the UTXO mechanism of Bitcoin, not the status account mechanism of Ethernet Square, so you need to specify the transaction output (Transaction Output) of gold coins.

After the above command is executed, you can see the following results:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideToken arg: user2Token arg: 10Token arg: e0b8a7ce6b248b8733ac7659c32a45b04a571de2548e371ada810a1e8bcf8eacToken arg: 0Start transfer token operationStart token transfer with args 10Magna e0b8a7ce6b248b8733ac7659c32a45b04a571de2548e371ada810a1e8bcf8eacrecover0End transfer token operation, returns {status: 'SUCCESS', info:''}

Next, let's verify that user2 did get 10 gold coins:

Node fabtoken list user2

Wow~ seems to have turned out to be:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideStart list token operationEnd list token operation, returns [{id: {tx_id: '7e772f9d2e9e94a5c06e3ff2a62d13a41591b7d47daa9886c842aed6dd6d6582}, index: 0}, type:' goldcoin', quantity: '10'}]-- fabtoken.js-end

Isn't that cool?

4. Issue application-specific tokens with Fabtoken

You might say, user1 and user2 mean nothing to me. I'm sam. I have a friend named don. I want to create some digital currency for my diamond business and send it to my friend don. How can I do that?

First create a digital currency.

Node fabtoken3 issue sam diamondcoin 1000

You may notice that I use "fabtoken3" instead of "fabtoken" and then use "sam" instead of "user1". Let's look at the results:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideToken arg: diamondcoinToken arg: 1000Start issue token operationStart token issue with args diamondcoin,1000End issue token operation, returns {status: 'SUCCESS', info:'}-fabtoken.js-end

Indeed, 1000 diamond coins were created for sam.

Let's check it out:

Node fabtoken3 list sam

The results are as follows:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideStart list token operationEnd list token operation, returns [{tx_id: '837ac2e3bd7a763f3a11d5a3d3dac0a215a98f5ee7849d87111b03f631c6, type:' diamondcoin', quantity: '1000'}]-- fabtoken.js-end

Now let's transfer 50 diamond coins to don.

Node fabtoken3 transfer sam don 50\ 837ac2e3bd7763f3a11d5a3d32822dac0a215a98f5ee7849d87111b03f631c6 0

The results are as follows:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideToken arg: donToken arg: 50Token arg: 837ac2e3bd7a763f3a11d5a3d32822dac0a215a98f5ee7849d87111b03f631c6Token arg: 0Start transfer token operationStart token transfer with args 50837ac2e3bd7a763f3a11d5a3d32822dac0a215a98f5ee7849d87111b03f631c6 0End transfer token operation, returns {status: 'SUCCESS', info:'}-- fabtoken.js-end

Now verify that don actually received 50 diamond coins:

Node fabtoken3 list don

The results are as follows:

-- fabtoken.js-startSetting up client side network objectsCreated client side object to represent the channelCreated client side object to represent the peerCreated client side object to represent the ordererSuccessfully setup client sideStart list token operationEnd list token operation, returns [{id: {tx_id: '74316bd91757907e9c878a78d725b8c9f605b505ccd1801e8afd407bbd8b53b3regions, index: 0}, type:' diamondcoin', quantity: '50'}]-- fabtoken.js-end Thank you for reading this article carefully I hope the article "how to use Fabtoken in Hyperledger Fabric 2.0" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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