Skip to content

Smartdevs17/rootsave-architecture-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building Production Bitcoin Savings dApps on Rootstock

Complete Architecture Guide for developing Bitcoin-backed DeFi applications on Rootstock

Rootsave Banner

🏗️ What You'll Learn

This comprehensive guide demonstrates how to build production-ready Bitcoin savings applications on Rootstock through the Rootsave case study - a real working dApp that enables users to earn 5% APY on their Bitcoin.

🎯 Technical Coverage

  • Rootstock Architecture: Bitcoin-secured smart contract development patterns
  • Smart Contract Design: Production-ready savings contract with security patterns
  • Mobile Integration: React Native + Rootstock development best practices
  • Security Implementation: Biometric authentication and secure key management
  • Production Deployment: Complete testnet to mainnet migration guide

👥 Target Audience

  • Senior blockchain developers entering Rootstock ecosystem
  • DeFi architects exploring Bitcoin-backed applications
  • Mobile developers integrating blockchain functionality
  • Technical leads planning production dApp deployments

🚀 Live Demo

Watch a quick demo of the Rootsave application in action:

Rootsave Live Demo

Rootsave Application Features:

  • 💰 Bitcoin Savings: Deposit RBTC to earn 5% APY
  • 📊 Real-time Yield: Live yield calculation and tracking
  • 🔒 Secure Authentication: Biometric-protected wallet access
  • 📱 Mobile-First: Native React Native experience
  • Instant Transactions: Optimized for Rootstock gas efficiency
  • 📈 Transaction History: Complete transaction recording and analysis

🏛️ Architecture Overview

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Mobile App    │    │  Smart Contract │    │ Bitcoin Network │
│  (React Native) │◄──►│   (Rootstock)   │◄──►│ (Merged Mining) │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         │                       │                       │
    Biometric Auth         RBTC Deposits           Security Layer
    Transaction UX        Yield Calculation       Consensus
    State Management      Emergency Withdrawals    Final Settlement
    Error Handling        Gas Optimization        Network Effects

Technology Stack

  • Smart Contracts: Solidity on Rootstock EVM
  • Mobile Frontend: React Native with TypeScript
  • Blockchain Integration: Ethers.js for Rootstock
  • Security: Hardware-backed biometric authentication
  • State Management: React Context patterns
  • Network: Rootstock Testnet/Mainnet

📖 Complete Technical Guide

6,000+ word comprehensive guide covering every aspect of production Rootstock development

📚 Supporting Documentation

⚡ Quick Start

🧪 Smart Contract Testing (5 commands)

git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide/contracts
npm install
npx hardhat test
npx hardhat coverage

📱 Mobile App Development (3 commands)

cd mobile
npm install  
npx expo start

🚀 Full Stack Development

# 1. Clone and setup contracts
git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide/contracts && npm install

# 2. Test and deploy contract
npx hardhat test && npx hardhat run scripts/deploy.js --network rskTestnet

# 3. Setup mobile app
cd ../mobile && npm install && cp .env.example .env

# 4. Start mobile development
npx expo start

🎯 Choose Your Development Path

📋 Contract Developers Only

Building DeFi protocols, yield strategies, or smart contract integrations

# Get just the contracts
git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide/contracts

# Quick setup and test
npm install && npx hardhat test

What you get:

  • ✅ Production-ready Solidity savings contract
  • ✅ Comprehensive test suite (100% coverage)
  • ✅ Rootstock deployment configuration
  • ✅ Gas optimization patterns

📱 Mobile Developers Only

Building React Native dApps, wallet integrations, or mobile UX

# Get just the mobile app
git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide/mobile

# Quick setup and run
npm install && npx expo start

What you get:

  • ✅ Complete React Native Bitcoin wallet
  • ✅ Biometric authentication patterns
  • ✅ Rootstock blockchain integration
  • ✅ Production-ready UI components

🏗️ Full Stack Architects

Building complete dApp ecosystems or learning end-to-end patterns

# Get everything
git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide

# Setup both layers
npm run setup:all

What you get:

  • ✅ Complete Bitcoin DeFi application
  • ✅ Smart contract + mobile integration
  • ✅ Production deployment pipeline
  • ✅ Security patterns and best practices

Prerequisites

# Development environment requirements
- Node.js 18+
- React Native development setup
- Git and GitHub account
- Basic Solidity/JavaScript knowledge

1. Smart Contract Setup

cd contracts
npm install
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.js --network rskTestnet

2. Mobile Application Setup

cd mobile
npm install

# Create environment file
cp .env.example .env
# Add your deployed contract address to .env

# Run the application
npm start
# or
npx expo start

3. Network Configuration

// Configure for Rootstock Testnet
export const NETWORKS = {
  testnet: {
    name: 'Rootstock Testnet',
    chainId: 31,
    rpcUrl: 'https://public-node.testnet.rsk.co',
    explorerUrl: 'https://rootstock-testnet.blockscout.com',
    symbol: 'RBTC',
    gasPrice: '65000000', // Optimized for Rootstock
  }
};

🏗️ Repository Structure

Modular Design: Each folder is self-contained and can be used independently

rootsave-architecture-guide/
│
├── 📁 contracts/                     # 🔶 SMART CONTRACT LAYER
│   ├── contracts/
│   │   └── RootsaveBitcoinSavings.sol    # Main savings contract
│   ├── test/                             # Complete test suite
│   ├── scripts/                          # Deployment scripts
│   ├── hardhat.config.js                 # Rootstock configuration
│   ├── package.json                      # Contract dependencies only
│   └── README.md                         # Contract-specific setup
│
├── 📁 mobile/                        # 📱 REACT NATIVE LAYER  
│   ├── src/
│   │   ├── components/                   # Reusable UI components
│   │   ├── contexts/                     # Wallet & state management
│   │   ├── screens/                      # Application screens
│   │   ├── services/                     # Blockchain integration
│   │   └── utils/                        # Helper functions
│   ├── package.json                      # Mobile dependencies only
│   ├── app.config.js                     # Expo configuration
│   └── README.md                         # Mobile-specific setup
│
├── 📁 docs/                          # 📚 DOCUMENTATION
│   ├── ARCHITECTURE.md                   # System design analysis
│   ├── SMART_CONTRACT_ANALYSIS.md        # Contract deep dive
│   ├── MOBILE_INTEGRATION.md             # React Native patterns
│   ├── SECURITY_PATTERNS.md              # Security implementation
│   └── DEPLOYMENT_GUIDE.md               # Production deployment
│
├── 📄 ARTICLE.md                     # Main technical guide (6,000+ words)
├── 📄 README.md                      # This file - project overview
├── 📄 package.json                   # Root scripts for full-stack setup
└── 📄 LICENSE                        # MIT License

🎯 Independent Development Paths

Smart Contract Only (/contracts folder)

# Work with just the contract layer
cd contracts/

# Everything you need is self-contained:
├── hardhat.config.js      # Rootstock testnet/mainnet config
├── test/                  # 100% coverage test suite  
├── scripts/deploy.js      # One-command deployment
└── package.json           # Only contract dependencies

Perfect for:

  • DeFi protocol developers
  • Smart contract auditors
  • Yield strategy builders
  • Integration partners

Mobile App Only (/mobile folder)

# Work with just the mobile layer
cd mobile/

# Everything you need is self-contained:
├── src/                   # Complete React Native app
├── package.json           # Only mobile dependencies
├── app.config.js          # Expo configuration
└── .env.example           # Environment template

Perfect for:

  • Mobile app developers
  • UX/UI designers
  • React Native specialists
  • Wallet integration teams

Full Stack (root folder)

# Work with the complete system
npm run setup:all           # Setup both contracts and mobile
npm run test:all            # Test both layers
npm run dev                 # Start both development servers

Perfect for:

  • Technical architects
  • Full-stack blockchain developers
  • DevOps engineers
  • Product teams

🛡️ Security Features

Smart Contract Security

  • Reentrancy Protection: OpenZeppelin's ReentrancyGuard implementation
  • Access Control: Owner-based emergency functions
  • Input Validation: Comprehensive parameter checking
  • Emergency Mechanisms: Circuit breaker patterns for critical issues

Mobile Security

  • Biometric Authentication: Hardware-backed security on supported devices
  • Secure Key Storage: iOS Keychain / Android Keystore integration
  • Emulator Safety: Development-friendly fallbacks for testing
  • Network Security: TLS/SSL for all blockchain communications

📊 Production Metrics

Metric Value Details
Gas Usage ~100k gas Optimized deposit/withdrawal operations
Transaction Speed <3 seconds Average confirmation on Rootstock
Mobile Performance <2s startup Optimized React Native bundle
Security Level Hardware-backed Biometric + secure enclave storage
Network Support Testnet + Mainnet Complete deployment pipeline

🎯 Key Technical Insights

Rootstock-Specific Optimizations

  • Gas Price Strategy: 65 Mwei optimized for network conditions
  • RBTC Handling: Proper wei conversion and decimal handling
  • Network Configuration: Dynamic testnet/mainnet switching
  • Explorer Integration: Blockscout API integration patterns

Mobile dApp Patterns

  • Embedded Wallet: Complete in-app wallet implementation
  • Transaction State: Comprehensive pending/confirmed/failed handling
  • Error Management: User-friendly blockchain error translation
  • Offline Support: Graceful degradation for network issues

Production Considerations

  • Scalability: Efficient state management for growing user base
  • Monitoring: Transaction tracking and error reporting
  • Upgradability: Proxy patterns for contract evolution
  • Compliance: Considerations for regulatory requirements

🤝 Contributing

This repository serves as both a comprehensive guide and reference implementation for the Rootstock developer community.

Ways to Contribute

  • 🐛 Issue Reports: Found something unclear? Open an issue
  • 💡 Improvements: Suggest architectural enhancements
  • 📖 Documentation: Help improve explanations and examples
  • 🔧 Code: Submit PRs for bug fixes or optimizations

Development Setup

# Fork the repository
git clone https://github.com/Smartdevs17/rootsave-architecture-guide.git
cd rootsave-architecture-guide

# Create a feature branch
git checkout -b feature/your-improvement

# Make your changes and test thoroughly
# Commit and push your changes
git push origin feature/your-improvement

# Create a pull request

📜 License

MIT License - Use this code as a foundation for your own Rootstock applications.

See LICENSE for full details.

🙏 Acknowledgments

  • Rootstock Team: For building the infrastructure that makes Bitcoin DeFi possible
  • OpenZeppelin: For security-audited smart contract libraries
  • React Native Community: For excellent mobile development tools
  • Bitcoin Developers: For the foundational security layer

📞 Contact & Support


Built with ❤️ for the Rootstock developer community

This guide represents hundreds of hours of development, testing, and documentation to provide the most comprehensive resource for Bitcoin-backed dApp development on Rootstock.

About

Complete architecture guide for building production Bitcoin savings dApps on Rootstock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors