Babylon BABY

@stakefish/sdk-babylon-baby

The @stakefish/sdk-babylon-baby is a JavaScript/TypeScript library that provides a unified interface for staking operations on the Babylon Baby blockchain with stake.fish validators. It allows developers to easily delegate stakes, undelegate, redelegate, claim rewards, sign transactions, and broadcast them to the network.

Table of Contents

Installation

To use this SDK in your project, install it via npm or yarn:

npm install @stakefish/sdk-babylon-baby
yarn add @stakefish/sdk-babylon-baby

Type Imports

import { BabylonBaby } from '@stakefish/sdk-babylon-baby';
import type {
  BabylonBabyConfig,
  BabylonBabyPrepareDelegate,
  BabylonBabyPrepareUndelegate,
  BabylonBabyPrepareRedelegate,
  BabylonBabyPrepareClaimRewards,
  BabylonBabySign,
  BabylonBabyBroadcast,
  BabylonBabyUnsignedTransaction,
  BabylonBabySignedTransaction,
  BabylonBabyTransactionBroadcastResult,
} from '@stakefish/sdk-babylon-baby';

API Reference

Constructor

import type { BabylonBabyConfig } from '@stakefish/sdk-babylon-baby';

new BabylonBaby({ rpcUrl: 'https://rpc.babylonchain.io', apiUrl: 'https://api.babylonchain.io', memo: 'Stake with stake.fish' }: BabylonBabyConfig)

Creates a new instance of the BabylonBaby SDK.

Parameters:

  • rpcUrl: Babylon Baby RPC endpoint URL
  • apiUrl: Babylon Baby API endpoint URL
  • memo: Memo to include in transactions. This should be a unique string approved by stake.fish for your account.

Delegation

import type { BabylonBabyPrepareDelegate, BabylonBabyUnsignedTransaction } from '@stakefish/sdk-babylon-baby';

delegate({ delegatorAddress: 'bbn1...', amount: '1000000' }: BabylonBabyPrepareDelegate): Promise<BabylonBabyUnsignedTransaction>

Creates an unsigned transaction for delegating a specified amount of BABY tokens (in ubbn, the smallest unit) from the delegator's address to the stake.fish validator.

Parameters:

  • delegatorAddress: The Babylon Baby address of the delegator (e.g., 'bbn1...')
  • amount: The amount to delegate in ubbn (1 BBN = 1,000,000 ubbn)

Undelegation

import type { BabylonBabyPrepareUndelegate, BabylonBabyUnsignedTransaction } from '@stakefish/sdk-babylon-baby';

undelegate({ delegatorAddress: 'bbn1...', amount: '1000000' }: BabylonBabyPrepareUndelegate): Promise<BabylonBabyUnsignedTransaction>

Creates an unsigned transaction for undelegating a specified amount from the stake.fish validator.

Parameters:

  • delegatorAddress: The Babylon Baby address of the delegator (e.g., 'bbn1...')
  • amount: The amount to undelegate in ubbn (1 BBN = 1,000,000 ubbn)

Redelegation

import type { BabylonBabyPrepareRedelegate, BabylonBabyUnsignedTransaction } from '@stakefish/sdk-babylon-baby';

redelegate({ delegatorAddress: 'bbn1...', srcValidatorAddress: 'bbnvaloper1...', amount: '1000000' }: BabylonBabyPrepareRedelegate): Promise<BabylonBabyUnsignedTransaction>

Creates an unsigned transaction for redelegating a specified amount from a source validator to the stake.fish validator.

Parameters:

  • delegatorAddress: The Babylon Baby address of the delegator (e.g., 'bbn1...')
  • srcValidatorAddress: The validator address to redelegate from (e.g., 'bbnvaloper1...')
  • amount: The amount to redelegate in ubbn (1 BBN = 1,000,000 ubbn)

Claim Rewards

import type { BabylonBabyPrepareClaimRewards, BabylonBabyUnsignedTransaction } from '@stakefish/sdk-babylon-baby';

claimRewards({ delegatorAddress: 'bbn1...' }: BabylonBabyPrepareClaimRewards): Promise<BabylonBabyUnsignedTransaction>

Creates an unsigned transaction for claiming staking rewards from the stake.fish validator.

Parameters:

  • delegatorAddress: The Babylon Baby address of the delegator (e.g., 'bbn1...')

Signing

import type { BabylonBabySign, BabylonBabyUnsignedTransaction, BabylonBabySignedTransaction } from '@stakefish/sdk-babylon-baby';

sign({ privateKeyHex: '0x...', unsignedTx }: BabylonBabySign): Promise<BabylonBabySignedTransaction>

Signs the unsigned transaction using the provided private key. This operation works completely offline and does not require network connectivity.

Parameters:

  • privateKeyHex: The private key in hexadecimal format (with or without '0x' prefix)
  • unsignedTx: The unsigned transaction object from delegate(), undelegate(), redelegate(), or claimRewards()

Broadcasting

import type { BabylonBabyBroadcast, BabylonBabySignedTransaction, BabylonBabyTransactionBroadcastResult } from '@stakefish/sdk-babylon-baby';

broadcast({ signedTx, checkInclusion: true, timeoutMs: 60000, pollIntervalMs: 2000 }: BabylonBabyBroadcast): Promise<BabylonBabyTransactionBroadcastResult>

Broadcasts the signed transaction to the Babylon Baby network and optionally waits for inclusion confirmation.

Parameters:

  • signedTx: The signed transaction object from sign()
  • checkInclusion (optional): Whether to wait for transaction inclusion (default: true)
  • timeoutMs (optional): Maximum time to wait for inclusion in milliseconds (default: 60000)
  • pollIntervalMs (optional): Interval between inclusion checks in milliseconds (default: 2000)

Returns: BabylonBabyTransactionBroadcastResult object containing:

  • txId: The transaction hash
  • success: Boolean indicating if the transaction was successful
  • error: Error message if the transaction failed (optional)

Examples

Full delegation example

import { BabylonBaby } from '@stakefish/sdk-babylon-baby';
import type {
  BabylonBabyUnsignedTransaction,
  BabylonBabySignedTransaction,
  BabylonBabyTransactionBroadcastResult,
} from '@stakefish/sdk-babylon-baby';

const delegator = process.env.BABYLON_BABY_ADDRESS;
const rpcUrl = process.env.BABYLON_BABY_RPC;
const privateKeyHex = process.env.BABYLON_BABY_PRIVATE_KEY;

async function main() {
  const babylonBaby = new BabylonBaby({
    rpcUrl: rpcUrl,
    apiUrl: rpcUrl,
    memo: 'Stake with stake.fish',
  });

  // Delegation (1 BBN = 1,000,000 ubbn)
  const unsignedTx: BabylonBabyUnsignedTransaction = await babylonBaby.delegate({
    delegatorAddress: delegator,
    amount: '1000000',
  });

  // Sign
  const signedTx: BabylonBabySignedTransaction = await babylonBaby.sign({ privateKeyHex, unsignedTx });

  // Broadcast
  const result: BabylonBabyTransactionBroadcastResult = await babylonBaby.broadcast({ signedTx });
  console.log('Broadcast result:', JSON.stringify(result));
}

void main().catch(console.error);

Undelegation

Undelegation amount must match the full amount delegated.

const unsignedTx: BabylonBabyUnsignedTransaction = await babylonBaby.undelegate({
  delegatorAddress: delegator,
  amount: '1000000',
});

Redelegation

const unsignedTx: BabylonBabyUnsignedTransaction = await babylonBaby.redelegate({
  delegatorAddress: delegator,
  srcValidatorAddress: 'bbnvaloper1...',
  amount: '1000000',
});

Claim Rewards

const unsignedTx: BabylonBabyUnsignedTransaction = await babylonBaby.claimRewards({
  delegatorAddress: delegator,
});

Configuration

The SDK requires configuration during instantiation with RPC and API endpoints:

const babylonBaby = new BabylonBaby({
  rpcUrl: 'https://custom-rpc.babylon.network',
  apiUrl: 'https://custom-api.babylon.network',
  memo: 'Stake with stake.fish',
});

Notes

  • All amounts in the SDK are specified in ubbn, the smallest unit of BBN (1 BBN = 1,000,000 ubbn)
  • The SDK automatically handles gas estimation and fee calculation for transactions
  • Private keys can be provided in hexadecimal format with or without the '0x' prefix
  • Private keys should be kept secure and never committed to version control
  • The SDK targets Babylon Baby (bbn-1) mainnet