Skip to content

doocho/btc-simple-staking

Repository files navigation

Bitcoin Simple Staking

A React Native demo application for Babylon Bitcoin Staking

This is a React Native demo application that demonstrates Bitcoin staking functionality using the Babylon Chain protocol. Built on top of the Ignite boilerplate by Infinite Red, it provides a complete implementation of Bitcoin staking operations including wallet setup, address generation, and staking execution.

Features

  • Built on Ignite: Leverages Infinite Red's proven React Native architecture and best practices
  • Wallet Management: Import existing wallets using 12 or 24-word recovery phrases
  • Multi-Chain Address Generation: Automatically generates Bitcoin (Signet) and Babylon addresses
  • Bitcoin Staking: Complete Bitcoin staking workflow with Babylon Chain integration
  • Real-time Validation: Mnemonic validation and address verification
  • User-Friendly Interface: Modern React Native UI with comprehensive error handling

Technical Stack

  • Boilerplate: Ignite by Infinite Red
  • Framework: React Native with Expo
  • State Management: MobX State Tree
  • Navigation: React Navigation v6
  • Styling: Themed components with dark/light mode support
  • Crypto Libraries:
    • @babylonlabs-io/[email protected] - Core Bitcoin staking functionality
    • bitcoinjs-lib - Bitcoin operations
    • @scure/bip39 - BIP39 mnemonic handling
    • @scure/bip32 - HD wallet derivation

Important Notice

⚠️ This application is configured for Bitcoin Signet testnet. Before using in production or mainnet, you must modify the network configurations accordingly.

Library Patches

This project uses patch-package to apply critical modifications to several libraries, especially the Babylon SDK. The following patches are essential for proper functionality:

  • @babylonlabs-io+btc-staking-ts+1.0.2.patch - Critical Babylon SDK modifications
  • bitcoinjs-lib+6.1.7.patch - Bitcoin library compatibility fixes
  • @bitcoin-js+tiny-secp256k1-asmjs+2.2.4.patch - Secp256k1 compatibility
  • @bufbuild+protobuf+2.2.5.patch - Protobuf fixes

Getting Started

Prerequisites

  • Node.js ^18.18.0 || >=20.0.0
  • Yarn package manager
  • Expo CLI
  • React Native development environment

Installation

# Clone the repository
git clone <repository-url>
cd btc-simple-staking

# Install dependencies
yarn install

# Apply patches (automatically runs after install)
yarn patch

# Start the development server
yarn start

Building the Application

# iOS Simulator
yarn build:ios:sim

# iOS Device (Development)
yarn build:ios:dev

# Android Simulator
yarn build:android:sim

# Android Device (Development)
yarn build:android:dev

Usage

Setting Up a Wallet

  1. Launch the application
  2. Tap "Setup Wallet" on the welcome screen
  3. Enter your 12 or 24-word recovery phrase
  4. Tap "Generate Addresses" to create Bitcoin and Babylon addresses
  5. Review the generated addresses and tap "Save Wallet"

Bitcoin Staking

  1. Navigate to the staking screen
  2. Enter the amount of Bitcoin you want to stake
  3. Review the finality provider and staking terms
  4. Confirm the staking transaction

Network Configuration

The application is currently configured for Bitcoin Signet testnet. Key configurations:

  • Bitcoin Network: Signet (testnet)
  • Derivation Path: m/86'/1'/0'/0/0 (Signet)
  • Address Format: P2TR (Taproot)
  • Babylon Network: Testnet

Switching Networks

To switch to mainnet or other networks, modify the following files:

  1. app/utils/chain-keys/index.ts - Update derivation paths and network parameters
  2. app/config/network/ - Update network configurations
  3. app/constants/staking.ts - Update staking parameters

Project Structure

This project follows the Ignite boilerplate structure with additional Bitcoin staking-specific modules:

app/
├── components/          # Reusable UI components (Ignite standard)
├── config/             # Network and environment configurations
├── constants/          # Application constants (Bitcoin staking specific)
├── hooks/              # Custom React hooks (staking functionality)
├── models/             # MobX State Tree models (Ignite standard)
├── navigators/         # Navigation configuration (Ignite standard)
├── provider/           # React context providers (Babylon RPC)
├── screens/            # Application screens (Ignite standard + staking screens)
├── types/              # TypeScript type definitions (Bitcoin/Babylon types)
├── utils/              # Utility functions and helpers (crypto utilities)
└── theme/              # Styling and theming (Ignite standard)

Key Components

Wallet Management (AddressStore)

  • Secure mnemonic storage
  • Multi-chain address generation
  • Wallet state management

Staking Execution (useStakingExecution)

  • Bitcoin staking workflow
  • Transaction signing and broadcasting
  • Error handling and status tracking

Network Integration

  • Babylon Chain RPC integration
  • Bitcoin mempool API integration
  • UTXO management

Development

Running Tests

# Run unit tests
yarn test

# Run tests in watch mode
yarn test:watch

# Run end-to-end tests with Maestro
yarn test:maestro

Linting and Formatting

# Check for linting errors
yarn lint:check

# Fix linting errors
yarn lint

# Compile TypeScript
yarn compile

Security Considerations

⚠️ Important Security Notice:

  1. Recovery Phrases: Never share your recovery phrase with anyone
  2. Testnet Only: This application uses testnet addresses for development
  3. Private Keys: Private keys are handled securely within the application
  4. Network Security: Ensure you're using trusted RPC endpoints

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Ensure all tests pass
  5. Submit a pull request

Known Issues

  • Application is currently configured for Signet testnet only
  • Some library patches are required for compatibility
  • Network switching requires manual configuration changes

License

This project is private and proprietary.

Support

For questions or support, please refer to the Babylon Chain documentation or create an issue in this repository.


Note: This is a demo application for educational and testing purposes. Always verify transactions and use appropriate network configurations for your intended use case.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages