Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

Latest commit

 

History

History
108 lines (79 loc) · 2.97 KB

File metadata and controls

108 lines (79 loc) · 2.97 KB

Browser Wallet

The browser wallet connects to the user's BSV wallet extension (such as MetaNet Client) and provides a full-featured API for blockchain operations.

Connecting

import { createWallet } from '@bsv/simple/browser'

const wallet = await createWallet()

This prompts the user to approve the connection. Once approved, the wallet is ready to use.

With Custom Defaults

const wallet = await createWallet({
  network: 'main',
  changeBasket: 'my-change',       // auto-recover change outputs
  tokenBasket: 'my-tokens',        // default basket for tokens
  messageBoxHost: 'https://messagebox.babbage.systems',
  registryUrl: '/api/identity-registry'
})

Any default can be overridden per-method call.

Wallet Info

// Identity key (compressed public key, 66 hex chars)
const key = wallet.getIdentityKey()
// '02a1b2c3d4...'

// P2PKH address
const address = wallet.getAddress()
// '1A2b3C4d5E...'

// Status object
const status = wallet.getStatus()
// { isConnected: true, identityKey: '02a1b2...', network: 'main' }

// Full info object
const info = wallet.getWalletInfo()
// { identityKey, address, network, isConnected }

Key Derivation

Derive public keys for specific protocols and counterparties.

Generic Derivation

const derivedKey = await wallet.derivePublicKey(
  [2, '3241645161d8'],   // protocol ID (BRC-29 in this case)
  'invoice-001',          // key ID
  recipientIdentityKey,   // counterparty
  false                   // forSelf
)

BRC-29 Payment Key

A convenience method for deriving BRC-29 payment keys:

const paymentKey = await wallet.derivePaymentKey(
  recipientIdentityKey,
  'invoice-001'    // optional invoice number
)

This uses protocol ID [2, '3241645161d8'] internally.

Accessing the Underlying Client

For advanced operations that aren't covered by the simple API:

const client = wallet.getClient()

// Now you can call raw @bsv/sdk methods
const result = await client.createAction({ ... })
await client.listOutputs({ basket: 'my-basket', include: 'locking scripts' })

Default Configuration

Setting Default Description
network 'main' Network to operate on
description 'BSV-Simplify transaction' Default transaction description
outputDescription 'BSV-Simplify output' Default output description
changeBasket undefined If set, auto-recover change outputs
tokenBasket 'tokens' Default basket for token operations
tokenProtocolID [0, 'token'] Default PushDrop protocol ID
tokenKeyID '1' Default PushDrop key ID
messageBoxHost 'https://messagebox.babbage.systems' MessageBox server URL
registryUrl undefined Identity registry API URL

Type Reference

import type { BrowserWallet } from '@bsv/simple/browser'
import type { WalletStatus, WalletInfo, WalletDefaults } from '@bsv/simple'