Cross-chain asset mapping

After the full node has synchronized all the blocks with the whole network, we can use the command line tool (hbtccli) to interact with the HBTC Chain and can run the following command to query all the commands.

hbtccli help

We give an introduction to the processes of cross-chain asset deposit, mapping and withdrawal, take the user ALICE as an example to introduce the interactive processes of collateralizing 0.01btc and issuing to get 0.01cbtc (Ethereum ERC20 cbtc). ( Assuming our binary runs in the local node directory, with Alice as one of the users).

1. Create and manage HBTC Chain custodian units

hbtccli keys add alice --home node/hbtccli

With above command we created an ALICE custodian unit in the specified node directory (you need to enter your password to encrypt the custodian unit key during the creation process), and it should be shown as follows after successful creation:

{
  "name": "alice",
  "address": "HBCPNuLKXuQSVgGe4kfF3JxJZb1Uytkajb3Q",
  "pubkey": "hbtpub1addwnpepqdp4ac6l2f7tjtwssvdra7fy2xfrl8th4ltcx4dgy60z2a7ffx5lcu2ja8v",
}

After completion of this operation, you need to apply to HBTC Chain for a certain amount of HBC for testing, please refer to the FAQ for details.

2. Create cross-chain custodian addresses for Bitcoin and Ethereum

First, create a btc cross-chain custodian address for the ALICE custodian unit with the following command:

hbtccli tx keygen keygen alice btc HBCPNuLKXuQSVgGe4kfF3JxJZb1Uytkajb3Q  --chain-id hbtc-testnet --home node/hbtccli

With above command ALICE creates a btc cross-chain custodian unit address, and after the command is sent and executed and waiting for 2-3 blocks (it takes a certain amount of time for distributed key generation), we can get the btc cross-chain custodian address of ALICE by querying the corresponding custodian unit information with the following command:

hbtccli query cu cuinfo HBCPNuLKXuQSVgGe4kfF3JxJZb1Uytkajb3Q --chain-id hbtc-testnet --home node/hbtccli

Response:

{
  "type": "hbtcchain/CustodianUnit",
  "value": {
    "address": "HBCPNuLKXuQSVgGe4kfF3JxJZb1Uytkajb3Q",
    "assets": [
      {
        "denom": "btc",
        "address": "12ayvTjKBxZnScRoEZ67seVySsqD5JboaA",
        "enable_sendtx": true
      }
    ],
  }
}

From the information obtained from the query, a btc cross-chain custodian address (mtZQH3wjTGu8FgPrS7B6gicay4kcPVa1wa) was created for the ALICE custodian unit, and the private key to this address is kept privately by each validator nodes holding one slice of private key shares.. With the same logic, ALICE in turn created for herself a cross-chain custodian address for eth/USDT with the following data query:

{
  "type": "hbtcchain/CustodianUnit",
  "value": {
    "address": "HBCcUCWJNattE5PYm6xQKbaCoRCG2SaVdHvH",
    "assets": [
      {
        "denom": "usdt",
        "address": "0xB48fEe1Df0Ae85415Eb286E66b262DA70BD94693",
        "nonce": "0",
        "enable_sendtx": true
      },
      {
        "denom": "eth",
        "address": "0xB48fEe1Df0Ae85415Eb286E66b262DA70BD94693",
        "nonce": "0",
        "enable_sendtx": true
      }
    ],
  }
}

3. Deposit cross-chain assets

Through the above steps, alice has created the btc/eth related cross-chain addresses, alice can deposit a certain amount of btc to its own cross-chain btc address (12ayvTjKBxZnScRoEZ67seVySsqD5JboaA) through its own wallet, after the deposit, HBTC Chain will automatically scan the cross-chain address of the custodian unit and credit the corresponding deposit to the corresponding custodian unit of HBTC Chain. For example, ALICE deposits 0.01BTC and 0.1eth and queries the information corresponding to the custodian unit as follows:

{
  "type": "hbtcchain/CustodianUnit",
  "value": {
    "address": "HBCcUCWJNattE5PYm6xQKbaCoRCG2SaVdHvH",
    "coins": [
      {
        "denom": "btc",
        "amount": "1000000"
      },
      {
        "denom": "eth",
        "amount": "10000000000000000",
      },
      {
        "denom": "hbc",
        "amount": "10000000000000000000"
      }
    ]
  }
}

You can clearly see that ALICE’s custodian unit already has a corresponding asset in it.

4. Asset mapping

ALICE may issue the impounded 0.01btc mapping as 0.01cbtc of ERC20 through an existing CBC asset mapping contract. The command for the asset mapping offering is as follows:

hbtccli tx mapping swap cbtc 1000000btc --from alice --chain-id hbtc-testnet --home node/hbtccli

With above command we completed the mapping transactions for ALICE, and she has exchanged 0.01btc to 0.01cbtc. After the transaction is completed you can check the assets of the corresponding custodian unit, for example ALICE’s assets are displayed as:

{
  "type": "hbtcchain/CustodianUnit",
  "value": {
    "address": "HBCPNuLKXuQSVgGe4kfF3JxJZb1Uytkajb3Q",
    "coins": [
      {
        "denom": "cbtc",
        "amount": "100000"
      }
    ],
}

As can be seen, btc is fully collateralized and ALICE successfully mapped the issue to herself 0.01cbtc.

5. Withdrawal cross-chain assets

After ALICE completes the asset mapping transaction, if she wants to claim the 0.01 CBTC obtained by the transaction into her own wallet, she can carry out the following command:

hbtccli tx transfer withdrawal alice 0xC933C741416151dAcFE9428d39222f747e2b45EB 100000cbtc 21000000000000000 --chain-id hbtc-testnet --home node/hbtccli

With above command, ALICE withdraws the 0.01cbtc to her own eth account(0xC933C741416151dAcFE9428d39222f747e2b45EB non-custodian address), and after consensus, the users can see the withdrawal received in their wallet account. (Note: ALICE will need to deposit or trade to get a certain amount of eth as the gas fee if she wants to withdraw CBTC).