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 shuttle to realize Cross-chain Asset Exchange on bytom

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

Share

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

This article focuses on "how to use shuttle to achieve cross-chain asset exchange on bytom", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use shuttle to achieve cross-chain asset exchange on bytom.

Recently, shuttle based on different asset exchange tools on the original chain is very eye-catching, because this tool can exchange not only different assets on the same chain, but also multiple assets on different blockchain platforms. This tool establishes the complete decentralization of assets in the process of transaction, without the intervention of third parties, and ensures the security and atomicity of assets in the process of exchange. Let's take a look at how this tool is used!

The main function of this tool is to exchange different assets on the original chain, first of all, the exchange of different assets on the original chain. This mainly uses currency exchange contracts for the exchange of assets. If the cross-chain asset exchange is carried out on the original main and side chain, the hash time lock contract is used to complete the asset exchange on two different chains.

Let's take a look at the specific steps of operation:

Step 1: first, build the node environment 1.1 golang version higher than 1.12, and set up the $GOPATH environment directory 1.2 to start and configure the bytom node. Refer to: bytom readme.md1.3 source code build: Shuttle is still in the testing stage, so the repository code will be changed frequently. You can build the tool directly from the source code. Refer to the following command: $git clone https://github.com/Bytom/shuttle.git $GOPATH/src/github.com/shuttle $cd $GOPATH/src/github.com/shuttle $make install

The commands related to Shuttle help are as follows:

Swap-h swap is a commond line client for bytom contract Usage: swap [flags] swap [command] vailable Commands: callHTLC callHTLC contract for asset swapping callTradeoff call tradeoff contract for asset swapping cancelHTLC cancelHTLC contract for asset swapping cancelTradeoff cancel tradeoff contract for asset swapping deployHTLC deployHTLC contract deployTradeoff deploy tradeoff contract help Help about any commandFlags:-h,-- help help for swapUse "swap [command]-- help" for more information about a command. Step 2: cross-chain asset exchange on the same chain

If you want to exchange the original assets on a single chain, whether it is the bytom main chain or the vapor side chain, you can directly use the Tradeoff contract to exchange the assets. The whole exchange flow chart is as follows:

First, let's start the bytom node. For testing, you can start the solnet node:

$bytomd init-chain_id=solonet-home $HOME/bytom/solonet # init bytom solonet node$ bytomd node-home $HOME/bytom/solonet-mining # launch bytom solonet node and start mining

After building the test node, you can create an account on the block chain and issue assets (issue asset) to test.

Create account reference

Reference for issuing assets

For example, on the bytom main chain, account A has 200BTC and account B has 10 BTM, and they can exchange them with the shuttle tool.

# 2.1 formal deployment of tradeoff contract (the following are contract deployment related commands and related parameters)

$swap deployTradeoff-hdeploy tradeoff contractUsage:swap deployTradeoff [contract flags (paramenters and locked value)] [txFee flag] [URL flags (ip and port)] [flags] Flags:-- amountLocked uint tradeoff contract locked value with amount / / number of locked assets-amountRequested uint tradeoff contract paramenter with requested amount / / lock the number of assets to be exchanged-assetLocked string tradeoff contract locked value with assetID / / asset ID-- assetRequested String tradeoff contract paramenter with requested assetID / / convertible asset ID-- cancelKey string tradeoff contract paramenter with seller pubkey for cancelling the contract / / pubkey-h required to unlock the contract -help help for deployTradeoff-- ip string network address (default "127.0.0.1")-- port string network port (default "9888")-- seller string tradeoff contract paramenter with seller control-program-- txFee uint contract transaction fee (default 40000000)

The following is the process of instantiating a deployment contract:

$swap deployTradeoff 10CJPO1HG0A02 12345-amountLocked 20000000000-- amountRequested 1000000000-- assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a-- assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-- cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e-- seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f-- txFee 4000000Mel-> contractUTXOID: 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f

After the contract is deployed, 2.5 minutes later, after a new block on the original chain is packed by the miners, the deployed contract can be certified.

2.2 call the tradeoff contract (the following is the command to invoke the contract) $swap callTradeoff-hcall tradeoff contract for asset swappingUsage:swap callTradeoff [txFee flag] [URL flags (ip and port)] [flags] Flags:-h,-- help help for callTradeoff-- ip string network address (default "127.0.0.1")-port string network port (default "9888")-txFee uint contract transaction fee (default 40000000)

The instantiation parameters of the calling contract are as follows:

$swap callTradeoff 10CKAD3000A02 12345 00140fdee108543d305308097019ceb5aec3da60ec66 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f-- > txID: 55e43274d2d92504a903a13e3f6517d63434fc19a2fa0e1fc0a9a5c8c75e8f6c

After the call, when the transaction is confirmed in the new block, the entire asset exchange process is completed, as shown in the following figure:

After the exchange is completed, account A now has 200 BTC and account B has 10 BTM.

2.3 cancel the tradeoff contract (the following is the relevant order to cancel the tradeoff contract)

If someone wants to cancel the tradeoff contract transaction, you can call this command to cancel, as follows:

$swap cancelTradeoff-hcancel tradeoff contract for asset swappingUsage:swap cancelTradeoff [txFee flag] [URL flags (ip and port)] [flags] Flags:-h,-- help help for cancelTradeoff-- ip string network address (default "127.0.0.1")-- port string network port (default "9888")-txFee uint contract transaction fee (default 40000000)

The instantiation of canceling a tradeoff contract is as follows:

$swap deployTradeoff 10CJPO1HG0A02 12345-- amountLocked 20000000000-- amountRequested 1000000000-- assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a-- assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-- cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e-- seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f-- txFee 4000000-- > contractUTXOID: e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5 $swap cancelTradeoff 10CJPO1HG0A02 12345 00145b0a81adc5c2d68a9967082a09c96e82d62aa058 e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5-- > txID: 0f75db743196b8b2e514c49d6483dfba9bd5ab8e913a7559ecaea0324977313f

The example diagram is as follows:

The whole process above is the whole process of exchanging different assets on the same chain. Let's look at the exchange of two assets on different chains. Let's take bytom and vapor as an example.

Step 3: exchange assets on different chains

You can use this tool to exchange assets on bytom and vapor:

3.1 build and start bytom and vapor nodes

To facilitate testing. You can start the solonet node of bytom and vapor

Start the bytom solonet node:

$bytomd init-chain_id=solonet-home $HOME/bytom/solonet # init bytom solonet node$ bytomd node-home $HOME/bytom/solonet-mining # launch bytom solonet node and start mining

Start the vapor solonet node:

$vapord init-- chain_id=solonet-- home $HOME/bytom/vapor-solonet # init vapor solonet node$ vapord node-- home $HOME/bytom/vapor-solonet-- mining # launch vapor solonet node and start mining3.2 deployment HTLC contract (the deployment order for the contract is as follows) $swap deployHTLC-h deployHTLC contract Usage: swap deployHTLC [contract flags (paramenters and locked value)] [txFee flag] [URL flags (ip and port)] [flags] Flags:-- amountLocked uint HTLC Contract locked value with amount-assetLocked string HTLC contract locked value with assetID-blockHeight uint HTLC contract locked value with blockHeight-hash string HTLC contract locked value with hash-h -help help for deployHTLC-- ip string network address (default "127.0.0.1")-- port string network port (default "9888")-- recipient string HTLC contract paramenter with recipientPublicKey-- sender string HTLC contract paramenter with sender PublicKey-- txFee uint contract transaction fee (default 40000000)

The instance parameters for deploying a HTLC contract are as follows:

$swap deployHTLC 11BB7TC8G0A02 12345-- sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44-- recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7-- blockHeight 1200-- hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824-- assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a-- amountLocked 20000000000-- > contractUTXOID: e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e3.3 calls HTLC contract $swap callHTLC-hcall HTLC contract for asset swappingUsage:swap callHTLC [txFee flag] [URL flags (ip and port)] [flags] Flags:-h -help help for callHTLC-ip string network address (default "127.0.0.1")-port string network port (default "9888")-txFee uint contract transaction fee (default 40000000)

The enablement parameters of calling HTLC contract are as follows:

$swap callHTLC 11BB86V300A04 12345 0014230cb75fcfcc70c580ce7f1d21c1e374d27334a8 68656c6c6f e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e txID-> df57b7906684e3d85adf59073ccbc0a3c5114b165626e9791f3269e9e57c319e

The actual exchange process is as follows:

3.4 cancel the HTLC contract (command parameters are as follows) $swap cancelHTLC-hcancel HTLC contract for asset swappingUsage:swap cancelHTLC [txFee flag] [URL flags (ip and port)] [flags] Flags:-h,-- help help for cancelHTLC-- ip string network address (default "127.0.0.1")-port string network port (default "9888")-txFee uint contract transaction fee (default 40000000)

The instantiation parameters for canceling a HTLC contract are as follows:

$swap deployHTLC 11BB7TC8G0A02 12345-- sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44-- recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7-- blockHeight 1200-- hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824-- assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a-- amountLocked 20000000kyu-> contractUTXOID: 68ed6b948b93544ea135482f1acd93d6b10cdc88f52d44133d264a5ee8b1ebd$ swap cancelHTLC 11BB7TC8G0A02 12345 001434fec270871c1f3420db85831f59511b2dd2a026 68b948b948b93544ea135482f1acd93d6b10cc88f52d44133d264a5ee86b1ebdFue > txID

The example diagram is as follows:

After canceling the HTLC contract, A4 initiates the assets exchanged for the HTLC contract to be automatically returned to the account. These are all the operations of the an account on the bytom, and the A5 account can achieve the same operation on the side chain at the same time.

At this point, I believe you have a deeper understanding of "how to use shuttle to achieve cross-chain asset exchange on bytom". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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