|
15 | 15 | npm i @babylonlabs-io/babylon-proto-ts
|
16 | 16 | ```
|
17 | 17 |
|
| 18 | +## 🚀 Quick Start |
| 19 | + |
| 20 | +This library provides TypeScript bindings for the Babylon Bitcoin Staking Protocol, offering both low-level protobuf exports and high-level client abstractions. |
| 21 | + |
| 22 | +### Basic Usage |
| 23 | + |
| 24 | +Use the SDK to access the client, messages, and utilities: |
| 25 | + |
| 26 | +```typescript |
| 27 | +import { createBabylonSDK } from "@babylonlabs-io/babylon-proto-ts"; |
| 28 | + |
| 29 | +const sdk = createBabylonSDK({ rpcUrl: "https://babylon-rpc.example.com" }); |
| 30 | + |
| 31 | +// Connect the client |
| 32 | +await sdk.connect(); |
| 33 | + |
| 34 | +// Query rewards for an address |
| 35 | +const rewards = await sdk.client.getRewards("bbn1..."); |
| 36 | + |
| 37 | +// Query balance |
| 38 | +const balance = await sdk.client.getBalance("bbn1...", "ubbn"); |
| 39 | + |
| 40 | +// Get Bitcoin tip height |
| 41 | +const btcTipHeight = await sdk.client.getBTCTipHeight(); |
| 42 | +``` |
| 43 | + |
| 44 | +### Wallet Integration |
| 45 | + |
| 46 | +For applications that need to create and sign transactions, use the provided registry and amino types: |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { createBabylonSDK } from "@babylonlabs-io/babylon-proto-ts"; |
| 50 | +import { SigningStargateClient } from "@cosmjs/stargate"; |
| 51 | + |
| 52 | +const sdk = createBabylonSDK({ rpcUrl: "https://babylon-rpc.example.com" }); |
| 53 | + |
| 54 | +// Create signing client with Babylon support |
| 55 | +const client = await SigningStargateClient.connectWithSigner( |
| 56 | + rpc, |
| 57 | + offlineSigner as OfflineSigner, |
| 58 | + { |
| 59 | + registry: sdk.utils.createRegistry(), |
| 60 | + aminoTypes: sdk.utils.createAminoTypes(), |
| 61 | + }, |
| 62 | +); |
| 63 | + |
| 64 | +// Create messages using the SDK |
| 65 | +const withdrawMsg = sdk.messages.createWithdrawRewardMsg("bbn1..."); |
| 66 | + |
| 67 | +// Sign and broadcast |
| 68 | +const result = await client.signAndBroadcast("bbn1...", [withdrawMsg], "auto"); |
| 69 | +``` |
| 70 | + |
| 71 | +### Direct Protobuf Access |
| 72 | + |
| 73 | +For advanced use cases, you can import protobuf types directly: |
| 74 | + |
| 75 | +```typescript |
| 76 | +import { btcstaking, incentivequery } from "@babylonlabs-io/babylon-proto-ts" |
| 77 | + |
| 78 | +// Use protobuf types directly |
| 79 | +const stakingParams = btcstaking.Params.fromPartial({...}) |
| 80 | +const rewardQuery = incentivequery.QueryRewardGaugesRequest.fromPartial({...}) |
| 81 | +``` |
| 82 | + |
| 83 | +## 📚 API Reference |
| 84 | + |
| 85 | +### SDK Functions |
| 86 | + |
| 87 | +#### `createBabylonSDK(config: BabylonConfig): BabylonSDK` |
| 88 | + |
| 89 | +Creates a comprehensive SDK instance with client, messages, and utilities. |
| 90 | + |
| 91 | +- **Parameters:** |
| 92 | + - `config.rpcUrl`: RPC endpoint URL for the Babylon network |
| 93 | +- **Returns:** SDK object with `client`, `messages`, `utils`, and `connect()` method |
| 94 | + |
| 95 | +### SDK Methods |
| 96 | + |
| 97 | +#### `sdk.connect(): Promise<void>` |
| 98 | + |
| 99 | +Initializes the client connection to the Babylon network. |
| 100 | + |
| 101 | +### Client Methods (via sdk.client) |
| 102 | + |
| 103 | +#### `sdk.client.getRewards(address: string): Promise<number>` |
| 104 | + |
| 105 | +Retrieves the total rewards for a given address. |
| 106 | + |
| 107 | +- **Parameters:** |
| 108 | + - `address`: The Babylon address to query |
| 109 | +- **Returns:** Total rewards amount (number) |
| 110 | + |
| 111 | +#### `sdk.client.getBalance(address: string, denom?: string): Promise<number>` |
| 112 | + |
| 113 | +Gets the balance of a specific token for an address. |
| 114 | + |
| 115 | +- **Parameters:** |
| 116 | + - `address`: The Babylon address to query |
| 117 | + - `denom`: Token denomination (defaults to "ubbn") |
| 118 | +- **Returns:** Balance amount (number) |
| 119 | + |
| 120 | +#### `sdk.client.getBTCTipHeight(): Promise<number>` |
| 121 | + |
| 122 | +Retrieves the current Bitcoin blockchain tip height. |
| 123 | + |
| 124 | +- **Returns:** Bitcoin tip height (number) |
| 125 | + |
| 126 | +### SDK Messages |
| 127 | + |
| 128 | +#### `sdk.messages.createWithdrawRewardMsg(address: string)` |
| 129 | + |
| 130 | +Creates a message for withdrawing rewards from Bitcoin staking. |
| 131 | + |
| 132 | +- **Parameters:** |
| 133 | + - `address`: The Babylon address to withdraw rewards for |
| 134 | +- **Returns:** Message object with proper typeUrl and value, ready for signing and broadcasting |
| 135 | + |
| 136 | +### SDK Utilities |
| 137 | + |
| 138 | +#### `sdk.utils.createRegistry(): Registry` |
| 139 | + |
| 140 | +Creates a CosmJS registry with all Babylon message types registered. |
| 141 | + |
| 142 | +#### `sdk.utils.createAminoTypes(): AminoTypes` |
| 143 | + |
| 144 | +Creates amino types for Babylon messages, required for hardware wallet compatibility. |
| 145 | + |
| 146 | +### Protobuf Exports |
| 147 | + |
| 148 | +The library exports all generated protobuf types directly, allowing for advanced use cases |
| 149 | + |
18 | 150 | ## 📝 Commit Format & Automated Releases
|
19 | 151 |
|
20 | 152 | This project uses [**Conventional Commits**](https://www.conventionalcommits.org/en/v1.0.0/)
|
|
0 commit comments