Interacting with a subnet: fund, release, checkpoint

This guide will walk you through the supported interactions between bitcoin and L2 subnets, specifically depositing BTC and withdrawing BTC back to the bitcoin network. Transferring tokens between L2 subnets is addressed in the Cross-chain token transfers.

We call "wrapped BTC" and "wrapped satoshi" the tokens used in a L2 subnet.


Prerequisites

Before starting, ensure that you have

  1. deployed subnet with id $SUBNET_ID

  2. exported the IPC address of each validator as $IPC_ADDRESS_OF_VALIDATOR_1 ... $IPC_ADDRESS_OF_VALIDATOR_4 and of user 1 as $IPC_ADDRESS_OF_USER_1

  3. created wallets and configuration files for user 1

  4. funded the validators via cross-msg fund

The previous steps should have covered all these prerequisites.

Moreover, the helper scripts described earlier will be useful for monitoring the balances in the subnet and mining bitcoin blocks on regtest. You can optionally run them in separate terminals/panels that you can easily watch.


Step 1: Start a relayer

Running a relayer

You can start a relayer using the following command:

ipc-cli --config-path ~/.ipc/validator1/config.toml checkpoint relayer --subnet $SUBNET_ID

You can use the same command, but pointing to a different validator's config, to start a second relayer.


Step 2: Fund a user

Let's fund the account of user 1 in the subnet $SUBNET-ID with 1 wBTC:

ipc-cli --config-path ~/.ipc/user1/config.toml cross-msg fund --subnet=$SUBNET_ID btc --to $IPC_ADDRESS_OF_USER_1 100000000

Parameters:

  • --subnet: The ID of the subnet where we are depositing BTC.

  • --to: The recipient IPC address within the subnet.

  • The sender is the wallet used by the bitcoin provider of the user (defined in ~/.ipc/user1/.env , which was given as argument when we run the bitcoin provider, in this case the wallet is user1).

Returns:

The bitcoin block height when the fund transaction was submitted to bitcoin (not the block in which it was included).

Make sure you mine a block (not needed if you are running the miner.sh script).

bitcoin-cli generatetoaddress 1 "$(bitcoin-cli --rpcwallet=default getnewaddress)"

Verify the balance in the subnet

You can use the balancer helper script to check that the balance was updated in the subnet (described in Helper scripts):

./scripts/balancer.sh $SUBNET_ID

or use following command.

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

Verify the balance on bitcoin

The following commands can be used to verify that the balance of user 1 on bitcoin was decreased:

bitcoin-cli --rpcwallet=user1 getbalance
cast balance $IPC_ADDRESS_OF_USER_1 --rpc-url http://localhost:8545/

Step 3: Release BTC back to L1

We will perform a release for IPC_ADDRESS_OF_USER_1 , whose wallet on bitcoin is user1.

Check the balances before performing the release for some address IPC_ADDRESS_OF_USER_1 in the L2 subnet:

# Balance on the L1
bitcoin-cli -rpcwallet=user1 getbalance
# Balance on the L2
ipc-cli wallet balances --subnet $SUBNET_ID --wallet-type btc | grep $IPC_ADDRESS_OF_USER_1

Perform the release:

ipc-cli cross-msg release --subnet $SUBNET_ID --from $IPC_ADDRESS_OF_USER_1 btc --to "$(bitcoin-cli --rpcwallet=user1 getnewaddress)" 50000000

Parameters:

  • --subnet: The ID of the subnet where we are releasing from.

  • --from : The IPC address of an account in subnet <SUBNET-ID> .

  • --to: The bitcoin address of the recipient.

You can use the same commands as above to check the balances after the release. Notice that the balance in the subnet is updated almost immediately, while the balance on bitcoin will be updated after the next checkpoint transaction is submitted. This may take a while, depending on the parameter --bottomup-check-period chosen at subnet creation.

Last updated