> For the complete documentation index, see [llms.txt](https://docs.b14g.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b14g.xyz/user-guide/for-btc-holders/guide-btc-staking-babylon/staking-via-cli.md).

# Staking via CLI

## b14g Babylon BTC Staking Tool

A CLI tool that lets you stake BTC natively on the Bitcoin network and earn co-staking rewards from the Babylon Genesis network via b14g.

{% embed url="<https://github.com/b14glabs/b14g-babylon-btc-staking-tool>" %}

## Staking Workflow

The `stake` command starts the BTC staking process. It communicates with the Babylon Genesis chain, the Covenant emulators, and the Bitcoin network to:

* Creates your co-staking order (if it’s your first time)
* Builds and registers your staking transaction on Babylon Genesis chain
* Waits for signature verification from the Covenant emulators
* Broadcasts the staking transaction to the Bitcoin network

**1. Create Order**

* First, the system checks if you have an existing order on the b14g marketplace
* If no order exists:
  * A new order is created with your chosen validator address specified in the parameters.
  * The `btcsharing` percentage defines how rewards are split between you and the Babylon stakers
  * This order is linked 1:1 to your Babylon address

**2. Staking Transaction Creation**

* Uses `preStakeRegistrationBabylonTransaction()` from `@babylonlabs-io/btc-staking-ts` to create an unsigned staking transaction with:
  * Your staking amount (in satoshis)
  * Timelock period (blocks until unlock)
  * Finality provider public key
  * Your public key
  * Available UTXOs (unspent transaction outputs)
  * Current Bitcoin tip height
* This function generates:
  * Staking transaction
  * Slashing transactions
  * Unbonding transaction
  * Proof of Possession (PoP) signature

**3. Babylon Delegation**

* Creates a delegation message containing:
  * Staking transaction data
  * Slashing transaction signatures
  * Unbonding transaction and signatures
  * Proof of possession (PoP) signature
* Broadcasts the delegation to Babylon network through the order smart contract
* Waits for verification (delegation state becomes `VERIFIED`)

**4. Bitcoin Broadcasting**

* Once verified on Babylon, uses `createSignedBtcStakingTransaction()` from `@babylonlabs-io/btc-staking-ts` to:
  * Sign the staking transaction with your private key
  * Validate that transaction hash matches expected hash from Babylon
* Broadcasts the signed transaction to Bitcoin network
* Your BTC is now locked and staking begins
