Cloud Lesson | How to realize data cross-chain interaction?

Abstract: With the development of blockchain technology, the coexistence of multiple chains is a significant pattern in the current market. Therefore, the interoperability of assets between chains, breaking data silos has become an urgent need for users on the chain, and ensuring the credibility of the cross-chain process. Safety is especially important.

This article is shared from HUAWEI CLOUD Community " [Cloud Small Course] Application Platform Lesson 38 How to realize data cross-chain interaction? ", author: Applied Kaleidoscope..

Trusted Cross-Chain Service (TCS) is based on a series of established trusted blockchain standard cross-chain protocols to ensure full-stack traceability, scalability and reliability of cross-chain transactions. The interconnection between isomorphic and heterogeneous chains built by different blockchain cores breaks the data silos of the blockchain, facilitates the credible interconnection of different enterprise alliance chains, and promotes the credible integration of the blockchain industry ecology.

Next, use the following examples to introduce how to implement cross-chain transactions between two blockchain services, break down data silos, understand the entire process of cross-chain services, and help you quickly get started with trusted cross-chain services.

Mainly take two HyperLedger Fabric enhanced blockchains Cross-ChainA and Cross-ChainB as examples to demonstrate cross-chain transactions. The transaction process is shown in Figure 1. orgA and orgB are two organizations on the blockchain, A1 is an account of the orgA organization, and B1 is an account of the orgB organization. It mainly realizes the operations of mutual transfer and mutual query between A1 and B1. .

Figure 1  Transaction Diagram

Ready to work

Please refer to the preparations to complete the following operations.

  1. Order Blockchain Services
  2. Chaincode installation and instantiating chaincode
  3. Download profiles and certificates

Use cross-chain services

After the preparations are completed, the cross-chain transaction demonstration can be performed through the trusted cross-chain service (hereinafter referred to as the TCS service).

1. Register the blockchain

Only after the blockchain service is registered with the trusted cross-chain service, cross-chain transactions can be performed. Next, the blockchain Cross-ChainA and the blockchain Cross-ChainB are registered to the TCS service respectively.

1. Log in to the trusted cross-chain service management console and enter the "Registered Blockchain" page.

2. Click "Register Blockchain", fill in the registration information of the blockchain Cross-ChainA, and refer to Table 1  to register the Cross-ChainA information.

3. Click "Register Now" in the lower right corner and wait for the registration to complete to generate a record on the "Registered Blockchain" page.

4. Click "Register Blockchain" again, fill in the registration information of the blockchain Cross-ChainB, and refer to Table 2  to register the Cross-ChainB information.

5. Click "Register Now" in the lower right corner and wait for the registration to complete to generate a record on the "Registered Blockchain" page.

2. Purchase cross-chain channels

Transactions on the two chains are achieved through a channel as a medium, and a cross-chain channel needs to be purchased to connect two independent blockchain services.

1. Log in to the trusted cross-chain service management console and enter the "Cross-chain Channel" page.

2. Click "Buy Cross-Chain Channel", fill in the basic information, please refer to Table 3  to purchase cross-chain channel information.

3. Click "Buy Now" in the lower right corner to jump to the payment page. After the payment is completed, wait 4 to 5 minutes to create a cross-chain channel. You can see the transfercross-demo cross-chain channel information on the cross-chain channel interface, and the status displays " Normal" means the purchase is successful.

3. Use cross-chain transactions

Introduce the transaction process of Blockchain Cross-ChainA and Blockchain Cross-ChainB.

(1) Configure permissions

Based on different contracts on different chains, there are three main permissions: cross-chain read, cross-chain write, and query ledger. Different types of cross-chain transactions require different permissions. For example, initiating a cross-chain transaction requires “cross-chain write” permission, and querying cross-chain transaction results requires “cross-chain read” permission. Therefore, you need to set the corresponding permission before performing cross-chain transactions. .

  • Cross-chain read: Any contract in the access chain can perform the read operation of the contract specified by the accessed chain.
  • Cross-chain write: Any contract in the access chain can execute the write operation of the contract specified by the access chain.
  • Cross-chain query ledger: The access chain can query the block and transaction information in the accessed chain ledger.

1. Log in to the trusted cross-chain service management console and enter the "Cross-chain Channel" page.

2. Click the name of the cross-chain channel transfercross-demo to enter the details page.

3. Under the cross-chain permission configuration, judge whether there is permission by checking whether the icon corresponding to the permission is highlighted. If it is gray, it means no permission.

4. After clicking the permission icon, check the permissions for query ledger, cross-chain read, and cross-chain write.

5. Click "Confirm" and the permission icon will be highlighted.

(2) Transaction Demo

Take the two accounts of the blockchain Cross-ChainA and Cross-ChainB as an example to perform a cross-chain transaction demonstration of mutual transfer.

The initial value of A1 on the Cross-ChainA chain is 100, and the registered blockchain name is AAAA; the initial value of B1 on the Cross-ChainB chain is 300, and the registered blockchain name is BBBB.

Cross-ChainA chain as transaction initiator

1. Click the name of the cross-chain channel transfercross-demo to enter the details page.

2. Query the value of B1.

    1. Under the cross-chain permission configuration, configure the cross-chain read permission from "AAAA" to "BBBB".
    2. Click "Cross-chain channel test", call the query method of "AAAA", change the parameter "args" to B1, and the others are default. Query the value of B1, the value of B1 is the returned "payload" field, and the initial value of B1 is 300.

3. Trigger cross-chain transactions.

    1. Under the cross-chain permission configuration, configure the cross-chain write permission from "AAAA" to "BBBB".
    2. Click "Cross-chain channel test", call the invoke method of "AAAA", and change the parameter "args" to "A1, B1, 50" (the comma here is an English comma, and the order of A1, B1 cannot be replaced), other defaults That's it. Initiate a transaction that transfers 50 from A1 to B1, and returns "success" to indicate that the transaction is successful.

4. Referring to step 2, the value of query B1 is 350, indicating that the transaction is successful.

Cross-ChainB as the transaction initiator

1. Click the name of the cross-chain channel transfercross-demo to enter the details page.

2. Query the value of A1.

    1. Under the cross-chain permission configuration, configure the cross-chain read permission from "BBBB" to "AAAA".
    2. Click "Cross-chain Channel Test", call the query method of "BBBB", change the parameter "args" to A1, and leave the others as default. Query the value of A1, the value of A1 is the returned "payload" field, and the initial value of A1 is 50.

3. Trigger cross-chain transactions.

    1. Under the cross-chain permission configuration, configure the cross-chain write permission from "BBBB" to "AAAA".
    2. Click "Cross-chain Channel Test", call the invoke method of "BBBB", and change the parameter "args" to "B1, A1, 100" (the comma here is an English comma, and the order of A1, B1 cannot be replaced), other defaults That's it. Initiate a transaction that transfers 100 from B1 to A1, and returns "success" to indicate that the transaction is successful.

4. Referring to step 2, the value of query A1 is 150, indicating that the transaction is successful.

Note: Currently, only the "North China-Beijing Four" region supports trusted cross-chain services.

 

Click Follow to learn about HUAWEI CLOUD's new technologies for the first time~

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324132238&siteId=291194637