Desktop Wallet Management

Comprehensive Wallet Data Integration with WalletClient

Build a Next.js application that connects to the BSV Desktop Wallet to retrieve and display comprehensive wallet information. This project demonstrates how to use the BSV SDK's WalletClient to access identity keys, derive keys using different protocols, manage baskets, check balances, and explore the full capabilities of wallet integration.

Repository: github.com/bsv-blockchain-demos/desktop-wallet-dataarrow-up-right


What You'll Build

A production-ready wallet information dashboard featuring:

  • Wallet connection and disconnection flow

  • Identity key retrieval and display

  • Public key derivation (Identity, Payment, Data)

  • Address generation from public keys

  • Custom key derivation with different protocols

  • Network status detection (mainnet/testnet)

  • Wallet balance checking

  • Basket management and output listing

  • Complete wallet capabilities discovery


Learning Objectives

By completing this project, you will learn:

  • WalletClient Integration - Connecting to and communicating with BSV Desktop Wallet

  • Identity Management - Retrieving and working with identity keys

  • Key Derivation - Using different protocol IDs to derive specialized keys

  • Public Key Types - Understanding Identity, Payment, and Data key types

  • Address Generation - Converting public keys to BSV addresses

  • Basket Management - Organizing wallet outputs using baskets

  • Balance Checking - Querying wallet balance for different addresses

  • Wallet Capabilities - Discovering available wallet methods (encryption, signing, certificates, HMAC, etc.)


Architecture Overview


Key Patterns

1. Wallet Connection

Initialize and connect to the BSV Desktop Wallet using a React hook:

Reference: WalletClient Integration

2. Identity Key Retrieval

The identity key is the master key that identifies the wallet:

Reference: Public Keys

3. Public Key Derivation

Derive different types of public keys using protocol IDs:

Key Types Explained:

  • Identity Key: Master key representing the wallet's identity

  • Payment Keys: Keys used for receiving payments

  • Data Keys: Keys used for data encryption and signing

Reference: HD Wallets

4. Address Generation

Convert public keys to BSV addresses:

Address Types:

Reference: Public Keys | P2PKH

5. Custom Key Derivation

Derive keys using custom protocols and key IDs:

Protocol Examples:

Reference: BRC-42 | HD Wallets

6. Network Detection

Detect which network the wallet is connected to:

This is useful for:

  • Displaying network status to users

  • Adjusting UI based on network

  • Preventing mainnet operations in testnet environment

  • Showing appropriate block explorers

7. Balance Checking

Query wallet balance for specific addresses:

Multiple Address Balances:

Reference: UTXO Management

8. Basket Management

Baskets organize wallet outputs into categories:

Basket Use Cases:

  • tokens: Store token outputs separately from payment UTXOs

  • receipts: Keep payment receipts organized

  • certificates: Manage certificate outputs

  • custom: Application-specific organization

Creating Outputs in Baskets:

Reference: UTXO Management

9. Wallet Capabilities Discovery

Discover all available wallet methods:

This allows you to:

  • Check which features are available

  • Build adaptive UIs based on capabilities

  • Provide fallback functionality

  • Discover new wallet features


Component Structure

WalletConnector Component

The main component that displays all wallet information:

Additional Components

DerivedKeyGenerator: Interactive component for deriving keys with custom protocols

WalletBalance: Real-time balance display for multiple addresses

BasketManager: Interface for creating, viewing, and managing baskets


Project Structure


Setup

  1. Clone the repository

  2. Install BSV Desktop Wallet

    Download and install the BSV Desktop Wallet from desktop.bsvb.techarrow-up-right

    Make sure the wallet is running before connecting from the application.

  3. Start the application

    Open http://localhost:3000arrow-up-right in your browser.

  4. Connect to Wallet

    Click "Connect Wallet" and approve the connection in your BSV Desktop Wallet.

  5. Explore Wallet Data

    Click "Fetch All Data" to retrieve and display comprehensive wallet information.


Important Concepts

WalletClient vs Wallet Toolbox

WalletClient (used in this project):

  • Frontend integration for user-controlled wallets

  • Connects to BSV Desktop Wallet

  • User must approve operations

  • Keys remain secure in user's wallet

  • Best for dApps and consumer applications

Wallet Toolbox (not used in this project):

  • Backend wallet management

  • Application controls keys

  • Automatic transaction signing

  • Best for services and custodial solutions

Reference: WalletClient Integration

Protocol IDs

Protocol IDs are used to derive different types of keys:

Security Levels:

  • 0: No security requirements

  • 1: Medium security

  • 2: High security (requires user authentication)

Reference: BRC-42 | BRC-43arrow-up-right

Public Key vs Address

Public Key: Raw cryptographic key (hex string, 66 characters)

Address: Human-readable identifier derived from public key

Conversion:

Baskets

Baskets are named containers for organizing wallet outputs:

  • Keep different types of outputs separated

  • Easier to query specific output types

  • Better organization for complex applications

  • Prevents accidental spending of important outputs

Common Basket Names:

  • default: Standard payment outputs

  • tokens: Token outputs

  • receipts: Payment receipts

  • certificates: Certificate outputs

  • Custom names for your application


Use Cases

This project's patterns enable:

  1. Wallet Information Dashboards

    • Display user wallet details

    • Show balances across addresses

    • List available baskets and outputs

  2. Multi-Key Applications

    • Derive different keys for different purposes

    • Separate payment and data keys

    • Protocol-specific key generation

  3. Developer Tools

    • Wallet capability discovery

    • Key derivation testing

    • Network status monitoring

  4. Portfolio Management

    • Track balances across multiple addresses

    • Organize outputs using baskets

    • Monitor token holdings

  5. Identity Management

    • Identity key display and verification

    • Address generation for different contexts

    • Counterparty key derivation


Summary

This project demonstrates:

  • WalletClient Integration - Connecting to BSV Desktop Wallet

  • Identity Management - Retrieving and displaying identity keys

  • Key Derivation - Deriving keys with different protocols and key IDs

  • Address Generation - Converting public keys to addresses

  • Balance Queries - Checking balances for different addresses

  • Basket Management - Organizing wallet outputs

  • Capabilities Discovery - Exploring available wallet features

  • Network Detection - Identifying mainnet vs testnet

These patterns form the foundation for building user-facing BSV applications that integrate with the BSV Desktop Wallet, giving users full control over their keys and transactions.


Last updated