Cross-chain token transfers

Now we have two subnets up and running. We can send tokens from subnet A to subnet B.

Prerequisites

All steps of the are a prerequisite. In particular, make sure

  • you have created and deployed both subnets

  • the relayer for subnet 1 is running

  • you have exported the IPC address of user 1 and user 2 as $IPC_ADDRESS_OF_USER_1 and $IPC_ADDRESS_OF_USER_2 , respectively

Step 1: Set env variables for ease of use

  • Create a env variable $SOURCE_SUBNET_ID with the SubnetID of the subnet of the first subnet.

  • Create a env variable $TARGET_SUBNET_ID with the SubnetID of the second subnet.

Step 2: Transfer tokens between subnets

To transfer tokens from address IPC_ADDRESS_OF_USER_1 in subnet SOURCE_SUBNET_ID to address IPC_ADDRESS_OF_USER_2 in subnet TARGET_SUBNET_ID, we use the following command.

ipc-cli --config-path ~/.ipc/user1/config.toml cross-msg transfer --source-subnet $SOURCE_SUBNET_ID --destination-subnet $TARGET_SUBNET_ID --source-address $IPC_ADDRESS_OF_USER_1 --destination-address $IPC_ADDRESS_OF_USER_2 222200

The command returns the epoch in the source subnet in which the transfer was submitted.

Check balance updates

The balance of user 1 one the source subnet is updated immediately. Observe the balancer script or run:

ipc-cli wallet balances --subnet $SOURCE_SUBNET_ID --wallet-type btc | grep  $IPC_ADDRESS_OF_USER_1

For the target subnet, wait until the next checkpoint is created and finalized in the source subnet (parameter --bottomup-check-period of ipc-cli subnet create ). Then you can check the balances in the output of the balancer script or use:

ipc-cli wallet balances --subnet $TARGET_SUBNET_ID --wallet-type btc | grep  $IPC_ADDRESS_OF_USER_2

Implementation details for the transfer

You can also test the opposite direction, sending funds from subnet B to subnet A. The command is analogous to the one above. However, make sure you run a relayer for subnet B first.

Last updated