Babylon Bitcoin Staking Protocol
TypeScript library
Please use the new location: https://github.com/babylonlabs-io/babylon-toolkit/tree/main/packages/babylon-proto-ts
npm i @babylonlabs-io/babylon-proto-ts
This library provides TypeScript bindings for the Babylon Bitcoin Staking Protocol, offering both low-level protobuf exports and high-level client abstractions.
Use the SDK to access the client, messages, and utilities:
import { createBabylonSDK } from "@babylonlabs-io/babylon-proto-ts"
const sdk = createBabylonSDK({ rpcUrl: "https://babylon-rpc.example.com" })
// Connect the client
await sdk.connect()
// Query rewards for an address
const rewards = await sdk.client.getRewards("bbn1...")
// Query balance
const balance = await sdk.client.getBalance("bbn1...", "ubbn")
// Get Bitcoin tip height
const btcTipHeight = await sdk.client.getBTCTipHeight()
For applications that need to create and sign transactions, use the provided registry and amino types:
import { createBabylonSDK } from "@babylonlabs-io/babylon-proto-ts"
import { SigningStargateClient } from "@cosmjs/stargate"
const sdk = createBabylonSDK({ rpcUrl: "https://babylon-rpc.example.com" })
// Create signing client with Babylon support
const client = await SigningStargateClient.connectWithSigner(
rpc,
offlineSigner as OfflineSigner,
{
registry: sdk.utils.createRegistry(),
aminoTypes: sdk.utils.createAminoTypes()
}
)
// Create messages using the SDK
const withdrawMsg = sdk.messages.createWithdrawRewardMsg("bbn1...")
// Sign and broadcast
const result = await client.signAndBroadcast("bbn1...", [withdrawMsg], "auto")
For advanced use cases, you can import protobuf types directly:
import { btcstaking, incentivequery } from "@babylonlabs-io/babylon-proto-ts"
// Use protobuf types directly
const stakingParams = btcstaking.Params.fromPartial({...})
const rewardQuery = incentivequery.QueryRewardGaugesRequest.fromPartial({...})
Creates a comprehensive SDK instance with client, messages, and utilities.
- Parameters:
config.rpcUrl
: RPC endpoint URL for the Babylon network
- Returns: SDK object with
client
,messages
,utils
, andconnect()
method
Initializes the client connection to the Babylon network.
Retrieves the total rewards for a given address.
- Parameters:
address
: The Babylon address to query
- Returns: Total rewards amount (number)
Gets the balance of a specific token for an address.
- Parameters:
address
: The Babylon address to querydenom
: Token denomination (defaults to "ubbn")
- Returns: Balance amount (number)
Retrieves the current Bitcoin blockchain tip height.
- Returns: Bitcoin tip height (number)
Creates a message for withdrawing rewards from Bitcoin staking.
- Parameters:
address
: The Babylon address to withdraw rewards for
- Returns: Message object with proper typeUrl and value, ready for signing and broadcasting
Creates a CosmJS registry with all Babylon message types registered.
Creates amino types for Babylon messages, required for hardware wallet compatibility.
The library exports all generated protobuf types directly, allowing for advanced use cases
This project uses Conventional Commits and semantic-release to automate versioning, changelog generation, and npm publishing.
- All commits must follow the Conventional Commits format.
- When changes are merged into the
main
branch:semantic-release
analyzes commit messages- Determines the appropriate semantic version bump (
major
,minor
,patch
) - Updates the
CHANGELOG.md
- Tags the release in Git
- Publishes the new version to npm (if configured)
feat: add support for slashing script
fix: handle invalid staking tx gracefully
docs: update README with commit conventions
refactor!: remove deprecated method and cleanup types
Note: For breaking changes, add a
!
after the type ( e.g.feat!:
orrefactor!:
) and include a description of the breaking change in the commit body.
Just commit your changes using the proper format and merge to main
.
The CI pipeline will handle versioning and releasing automatically β no manual
tagging or version bumps needed.