@babylonlabs-io/babylon-proto-ts

中文文档
1.23.1发布于 2026/08/21ISCTypeScriptESM + CJS构建来源已验证近 30 天下载 71.5万

Babylon Logo

@babylonlabs-io/babylon-proto-ts

Babylon Bitcoin Staking

原始使用文档
文档目录17 节
  1. @babylonlabs-io/babylon-proto-ts
  2. 👨🏻‍💻 Installation
  3. 🚀 Quick Start
  4. Basic Usage
  5. Wallet Integration
  6. Direct Protobuf Access
  7. 📚 API Reference
  8. SDK Functions
  9. SDK Methods
  10. Client Methods (via sdk.client)
  11. SDK Messages
  12. SDK Utilities
  13. Protobuf Exports
  14. 📝 Commit Format & Automated Releases
  15. ✅ How It Works
  16. 🧱 Commit Message Examples
  17. 🚀 Releasing

Babylon Logo

@babylonlabs-io/babylon-proto-ts

Babylon Bitcoin Staking Protocol

TypeScript library

npm version


👨🏻‍💻 Installation

npm i @babylonlabs-io/babylon-proto-ts

🚀 Quick Start

This library provides TypeScript bindings for the Babylon Bitcoin Staking Protocol, offering both low-level protobuf exports and high-level client abstractions.

Basic Usage

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 BTC staking rewards for an address
const btcRewards = await sdk.client.getRewardsForBTCStaking("bbn1...");

// Query BABY staking delegations and rewards
const delegations = await sdk.client.getBabyStakingDelegations("bbn1...");
const babyRewards = await sdk.client.getRewardsForBABYStaking("bbn1...");

// Get all validators
const validators = await sdk.client.getValidators();

// Query balance
const balance = await sdk.client.getBalance("bbn1...", "ubbn");

// Get Bitcoin tip height
const btcTipHeight = await sdk.client.getBTCTipHeight();

Wallet Integration

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(),
  },
);

// BTC Staking: Withdraw BTC staking rewards message
const btcWithdrawMsg =
  sdk.messages.createWithdrawRewardForBTCStakingMsg("bbn1...");

// BABY Staking: Stake BABY tokens message
const stakeMsg = sdk.messages.createStakeBABYMsg(
  "bbn1...", // delegator address
  "bbnvalidator...", // validator address
  { denom: "ubbn", amount: "1000000" }, // 1 BBN
);

// BABY Staking: Withdraw BABY staking rewards message
const withdrawMsg = sdk.messages.createWithdrawRewardForBABYStakingMsg(
  "bbn1...",
  "bbnvalidator...",
);

Direct Protobuf Access

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({...})

📚 API Reference

SDK Functions

createBabylonSDK(config: BabylonConfig): BabylonSDK

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, and connect() method

SDK Methods

sdk.connect(): Promise<void>

Initializes the client connection to the Babylon network.

Client Methods (via sdk.client)

sdk.client.getRewardsForBTCStaking(address: string): Promise<number>

Retrieves the total BTC staking rewards for a given address.

  • Parameters:
    • address: The Babylon address to query
  • Returns: Total BTC staking rewards amount (number)

sdk.client.getBalance(address: string, denom?: string): Promise<number>

Gets the balance of a specific token for an address.

  • Parameters:
    • address: The Babylon address to query
    • denom: Token denomination (defaults to "ubbn")
  • Returns: Balance amount (number)

sdk.client.getBTCTipHeight(): Promise<number>

Retrieves the current Bitcoin blockchain tip height.

  • Returns: Bitcoin tip height (number)

sdk.client.getBabyStakingDelegations(address: string): Promise<DelegationResponse[]>

Gets all BABY token delegations for a given address.

  • Parameters:
    • address: The Babylon address to query
  • Returns: Array of delegation responses

sdk.client.getRewardsForBABYStaking(address: string): Promise<DelegationDelegatorReward[]>

Retrieves all BABY staking delegation rewards for a given address.

  • Parameters:
    • address: The Babylon address to query
  • Returns: Array of delegation rewards

sdk.client.getValidators(): Promise<Validator[]>

Gets all validators in the network.

  • Returns: Array of all validators

SDK Messages

sdk.messages.createWithdrawRewardForBTCStakingMsg(address: string)

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

sdk.messages.createStakeBABYMsg(delegatorAddress: string, validatorAddress: string, amount: Coin)

Creates a message for staking BABY tokens.

  • Parameters:
    • delegatorAddress: The delegator's Babylon address
    • validatorAddress: The validator's Babylon address
    • amount: The amount to stake (Coin object with amount and denom)
  • Returns: Message object with proper typeUrl and value, ready for signing and broadcasting

sdk.messages.createUnstakeBABYMsg(delegatorAddress: string, validatorAddress: string, amount: Coin)

Creates a message for unstaking BABY tokens.

  • Parameters:
    • delegatorAddress: The delegator's Babylon address
    • validatorAddress: The validator's Babylon address
    • amount: The amount to unstake (Coin object with amount and denom)
  • Returns: Message object with proper typeUrl and value, ready for signing and broadcasting

sdk.messages.createWithdrawRewardForBABYStakingMsg(delegatorAddress: string, validatorAddress: string)

Creates a message for withdrawing BABY staking rewards.

  • Parameters:
    • delegatorAddress: The delegator's Babylon address
    • validatorAddress: The validator's Babylon address
  • Returns: Message object with proper typeUrl and value, ready for signing and broadcasting

SDK Utilities

sdk.utils.createRegistry(): Registry

Creates a CosmJS registry with all Babylon message types registered.

sdk.utils.createAminoTypes(): AminoTypes

Creates amino types for Babylon messages, required for hardware wallet compatibility.

sdk.utils.normalizeCosmjsAmount(amount: string): string

Normalizes CosmJS amount from 18-decimal precision to standard ubbn format.

  • Parameters:
    • amount: The amount string from CosmJS (with 18 decimal precision)
  • Returns: The normalized amount as a string in standard ubbn format

sdk.utils.normalizeRewardResponse(response: QueryDelegationTotalRewardsResponse)

Normalizes reward response from CosmJS to standard ubbn format.

  • Parameters:
    • response: The QueryDelegationTotalRewardsResponse from CosmJS
  • Returns: The normalized reward array with amounts in standard ubbn format

Protobuf Exports

The library exports all generated protobuf types directly, allowing for advanced use cases

📝 Commit Format & Automated Releases

This project uses Conventional Commits and semantic-release to automate versioning, changelog generation, and npm publishing.

✅ How It Works

  1. All commits must follow the Conventional Commits format.
  2. 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)

🧱 Commit Message Examples

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!: or refactor!:) and include a description of the breaking change in the commit body.

🚀 Releasing

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.

版本与发布记录

@babylonlabs-io/babylon-proto-ts 共发布 51 个版本,首次发布于 2024/10/17;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.23.1latest2026/08/212 个月前
1.22.12025/11/2511 个月前
1.22.02025/11/2011 个月前
1.21.02025/11/1411 个月前
1.20.02025/11/1111 个月前
1.19.02025/10/271 年前

其他发布通道:canary → 0.0.3-canary.7。

关于 @babylonlabs-io/babylon-proto-ts 的常见问题

@babylonlabs-io/babylon-proto-ts 是什么?

@babylonlabs-io/babylon-proto-ts Babylon Bitcoin Staking

如何安装 @babylonlabs-io/babylon-proto-ts?

在项目目录运行 npm install @babylonlabs-io/babylon-proto-ts,或使用 pnpm add / yarn add / bun add。

@babylonlabs-io/babylon-proto-ts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@babylonlabs-io/babylon-proto-ts 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@babylonlabs-io/babylon-proto-ts 可以商用吗?

@babylonlabs-io/babylon-proto-ts 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@babylonlabs-io/babylon-proto-ts 的下载量有多少?

根据 npm 官方下载统计,@babylonlabs-io/babylon-proto-ts 在 2026/10/08 – 2026/11/06 这 30 天内被下载 715,237 次,日均约 23,841 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@babylonlabs-io/babylon-proto-ts 还在维护吗?

最新版本 1.23.1 发布于 2026/08/21(2 个月前);至今共发布 51 个版本,其中过去 12 个月发布了 5 个;首次发布于 2024/10/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。