A decentralized wallet application for managing sBTC (Stacks Bitcoin) built on the Stacks blockchain using Clarity smart contracts. This project provides a secure, user-friendly interface for interacting with Bitcoin-backed assets on the Stacks ecosystem.
- Overview
- Architecture
- How It Works
- Features
- Prerequisites
- Installation
- Development
- Testing
- Deployment
- Project Structure
- API Reference
- Contributing
- Security
- License
- Resources
The sBTC Simple Wallet is a full-stack decentralized application that enables users to manage their sBTC tokens through an intuitive web interface. The application consists of:
- Smart Contracts: Clarity-based contracts deployed on the Stacks blockchain
- Frontend Application: React-based user interface built with modern web technologies
- Integration Layer: Seamless connection between frontend and blockchain contracts
The project demonstrates best practices for DeFi application development on the Stacks ecosystem, including secure wallet connections, transaction management, and real-time blockchain state updates.
graph TB
A[User Interface<br/>React + TypeScript] --> B[Wallet Connection<br/>@stacks/connect]
B --> C[Transaction Layer<br/>@stacks/transactions]
C --> D[Stacks Blockchain]
D --> E[sBTC Simple Wallet Contract]
D --> F[sBTC Token Contract]
E --> G[Deposit/Withdraw<br/>Functions]
F --> H[Token Management<br/>Functions]
I[Frontend State<br/>React Query] --> A
J[Network Configuration<br/>@stacks/network] --> C
graph TD
A[sBTC Simple Wallet Contract] --> B[Deposit Function]
A --> C[Withdraw Function]
A --> D[Transfer Function]
A --> E[Balance Query]
F[sBTC Token Contract] --> G[Mint Function]
F --> H[Burn Function]
F --> I[Transfer Function]
F --> J[Balance Query]
B --> K[Update User Balance]
C --> L[Validate Withdrawal]
D --> M[Transfer Validation]
K --> N[Contract State]
L --> N
M --> N
sequenceDiagram
participant U as User
participant F as Frontend
participant W as Wallet
participant C as Contract
participant B as Blockchain
U->>F: Initiate Transaction
F->>W: Request Signature
W->>U: Show Transaction Details
U->>W: Approve Transaction
W->>F: Return Signed Transaction
F->>C: Submit Transaction
C->>B: Process Transaction
B->>C: Confirm Transaction
C->>F: Return Transaction Result
F->>U: Display Result
- Wallet Connection: Users connect their Stacks-compatible wallets (e.g., Hiro Wallet, Xverse) to the application
- sBTC Management: The application interacts with sBTC tokens through the deployed smart contracts
- Transaction Processing: All operations are processed as blockchain transactions requiring user signatures
- State Synchronization: Real-time updates of balances and transaction history from the blockchain
The frontend communicates with the Stacks blockchain through the following flow:
- Contract Calls: Read operations query contract state without requiring transactions
- Transaction Submission: Write operations create and submit transactions to the network
- Event Monitoring: The application monitors blockchain events for transaction confirmations
- State Updates: UI state is updated based on blockchain confirmations
- Non-custodial: Users maintain full control of their private keys and assets
- Transaction Signing: All operations require explicit user approval
- Contract Verification: Smart contracts are deployed with source code verification
- Audit Trail: All transactions are recorded immutably on the blockchain
- Secure Wallet Integration: Connect with popular Stacks wallets
- sBTC Balance Management: View and track sBTC token balances
- Deposit Functionality: Deposit sBTC tokens into the wallet contract
- Withdrawal Operations: Secure withdrawal of sBTC tokens
- Transfer Capabilities: Send sBTC tokens to other addresses
- Transaction History: Complete history of all wallet operations
- Real-time Updates: Live balance and transaction status updates
- Responsive Design: Mobile-first design with modern UI components
- Type Safety: Full TypeScript implementation for reliability
- Error Handling: Comprehensive error handling and user feedback
- Network Support: Support for mainnet, testnet, and devnet environments
- Node.js: Version 18.0.0 or higher
- npm: Version 8.0.0 or higher (comes with Node.js)
- Git: Version 2.30.0 or higher
- Clarinet: Stacks smart contract development toolkit
- Stacks Wallet: Hiro Wallet, Xverse, or compatible wallet
- Code Editor: VS Code recommended with Clarity and TypeScript extensions
- Internet Connection: Required for blockchain interactions
- Stacks API: Access to Stacks blockchain nodes
- Test BTC: For testing on testnet (faucet available)
git clone https://github.com/your-username/sbtc-simple-wallet.git
cd sbtc-simple-wallet# Install frontend dependencies
npm install
# Install contract dependencies
cd clarity-contract
npm install
cd ..- Configure Networks: Update network configurations in
clarity-contract/settings/ - Wallet Setup: Install and configure a Stacks-compatible wallet
- Testnet Access: Obtain test BTC from the Stacks testnet faucet
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Run linting
npm run lintcd clarity-contract
# Run contract tests
npm test
# Start local development network
clarinet integrate
# Deploy to testnet
clarinet deployments apply -p deployments/default.testnet-plan.yaml- Local Development: Use
clarinet integratefor local blockchain testing - Contract Testing: Write and run comprehensive test suites
- Frontend Integration: Connect frontend to local contract deployments
- End-to-End Testing: Test complete user flows
cd clarity-contract
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test sbtc-simple-wallet.test.ts# Run frontend tests (when implemented)
npm test
# Run E2E tests (when implemented)
npm run test:e2e- Unit Tests: Individual function and component testing
- Integration Tests: Contract-frontend interaction testing
- End-to-End Tests: Complete user journey testing
cd clarity-contract
# Deploy to testnet
clarinet deployments apply -p deployments/default.testnet-plan.yaml
# Verify deployment
clarinet deployments checkcd clarity-contract
# Deploy to mainnet (use mainnet settings)
clarinet deployments apply -p deployments/default.mainnet-plan.yaml# Build optimized production bundle
npm run build
# Deploy to hosting platform (Vercel, Netlify, etc.)
# Follow platform-specific deployment instructions- Contract Addresses: Update deployed contract addresses in frontend config
- Network Settings: Configure appropriate network endpoints
- API Keys: Set up any required API keys for external services
sbtc-simple-wallet/
├── clarity-contract/ # Smart contract layer
│ ├── contracts/ # Clarity smart contracts
│ │ ├── sbtc-simple-wallet.clar
│ │ └── sbtc-token.clar
│ ├── tests/ # Contract test suites
│ ├── deployments/ # Network deployment configs
│ ├── settings/ # Network configurations
│ └── package.json # Contract dependencies
├── src/ # Frontend application
│ ├── components/ # Reusable UI components
│ ├── pages/ # Application pages
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility functions
│ └── App.tsx # Main application component
├── public/ # Static assets
├── package.json # Frontend dependencies
├── vite.config.ts # Build configuration
├── tailwind.config.ts # Styling configuration
└── tsconfig.json # TypeScript configuration
deposit(amount: uint)- Deposit sBTC tokens into walletwithdraw(amount: uint)- Withdraw sBTC tokens from wallettransfer(recipient: principal, amount: uint)- Transfer sBTC to another addressget-balance(user: principal)- Query user balance
mint(recipient: principal, amount: uint)- Mint new sBTC tokensburn(amount: uint)- Burn sBTC tokenstransfer(recipient: principal, amount: uint)- Transfer tokensbalance-of(owner: principal)- Query token balance
WalletConnect- Wallet connection interfaceBalanceDisplay- Token balance displayTransactionForm- Transaction input formsTransactionHistory- Transaction history viewer
We welcome contributions from the community. Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- TypeScript: Strict type checking enabled
- ESLint: Code linting and formatting
- Prettier: Consistent code formatting
- Testing: Comprehensive test coverage required
type(scope): description
Types:
- feat: New feature
- fix: Bug fix
- docs: Documentation
- style: Code style changes
- refactor: Code refactoring
- test: Testing
- chore: Maintenance
- Update the README.md with details of changes
- Update the version numbers in package.json
- Test all changes thoroughly
- Ensure CI/CD checks pass
- Request review from maintainers
- Private Key Security: Never store private keys in the application
- Transaction Validation: All transactions require user confirmation
- Contract Audits: Smart contracts should be audited before mainnet deployment
- Dependency Updates: Regularly update dependencies for security patches
Please report security vulnerabilities by emailing security@yourproject.com or opening a private issue.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ on the Stacks blockchain

