Loading…
High-level wallet API for browser and server — manage payments, tokens, inscriptions, DIDs, and credentials without wrestling with private keys or transactions.
npm install @bsv/simpleimport { createWallet } from '@bsv/simple/browser'
const wallet = await createWallet()
const recipientIdentityKey = '025706528f0f6894b2ba505007267ccff1133e004452a1f6b72ac716f246216366'
// Send a payment via MessageBox P2P
const result = await wallet.pay({
to: recipientIdentityKey,
satoshis: 1000
})
console.log('Paid:', result.txid)const balance = await wallet.getBalance()
console.log(`Balance: ${balance.totalSatoshis} satoshis`)
// Per-basket balance
const tokenBalance = await wallet.getBalance('tokens')
console.log(`Spendable: ${tokenBalance.spendableSatoshis}`)// Register identity handle
await wallet.certifyForMessageBox('@alice', '/api/identity-registry')
// Find recipient and send payment
const results = await wallet.lookupIdentityByTag('bob', '/api/identity-registry')
await wallet.sendMessageBoxPayment(results[0].identityKey, 1000)const recipientIdentityKey = '025706528f0f6894b2ba505007267ccff1133e004452a1f6b72ac716f246216366'
// Create token
const token = await wallet.createToken({
data: { type: 'loyalty', points: 100 },
basket: 'my-tokens'
})
// List tokens
const tokens = await wallet.listTokenDetails('my-tokens')
// Send token to another key
await wallet.sendToken({
basket: 'my-tokens',
outpoint: tokens[0].outpoint,
to: recipientIdentityKey
})// Server generates payment request
const request = serverWallet.createPaymentRequest({ satoshis: 2000 })
// Browser creates BRC-29 derived transaction
const payment = await browserWallet.sendDirectPayment(request)
// Server receives and internalizes
await serverWallet.receiveDirectPayment({
tx: payment.tx,
senderIdentityKey: payment.senderIdentityKey,
derivationPrefix: payment.derivationPrefix,
derivationSuffix: payment.derivationSuffix,
outputIndex: payment.outputIndex
})teratestnet
routing alongside mainnet, testnet, and local presetsbasket insertion vs wallet payment are mutually exclusive — You cannot use both on the same output in a single transactionif (typeof result === 'string') throw new Error(result)result.tx may be undefined — Check before using for overlay broadcasting@bsv/simple/server, not browsertm_; lookup services with ls_ — The Overlay class enforces these prefixes