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_1and$IPC_ADDRESS_OF_USER_2, respectively (thebitcoin-ipccontainer exports them by default).
Step 1: Set env variables for ease of use
Create a env variable
$SOURCE_SUBNET_IDwith the SubnetID of the first subnet.Create a env variable
$TARGET_SUBNET_IDwith 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.
# from inside the container
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 222200The 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:
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:
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