SDKs overview
The BSV SDKs and packages cover different jobs, from asking a user’s wallet to sign a transaction to working with raw scripts. Which one to start with depends on where the signing key lives and how close to the protocol your code needs to be.
Find Your Starting Point
Choose where your signing key lives to see which package to start with.
@bsv/sdk with WalletClientThe user's wallet keeps the keys and asks the person to approve each spend.
See it in code →Shared services such as wallet storage, messaging or overlay lookup are not packages. They are covered in Services and Packages for Other Jobs.
See Each Package in Code
Your app asks a local BRC-100The standard interface between an app and a wallet wallet, such as BSV Desktop or BSV Browser, to do the work, and @bsv/sdk is the place to start. Through WalletClient, the app finds the wallet on the user’s machine, and the wallet keeps the keys and asks the user to approve each spend.
import { WalletClient } from '@bsv/sdk'
// The second value is the name of your app, shown in the wallet's prompts
const wallet = new WalletClient('auto', 'example.com')
console.log(await wallet.getNetwork())Sample output #
{ network: 'testnet' }The @bsv/simple/browser package offers shortcuts for payments and tokens, such as pay() and createToken(), on top of these wallet calls. In version 0.7.0, pay() returns an empty txid, and createWallet() reports the network as main whatever network the wallet is on. To get the transaction ID, use createAction on WalletClient, and to read the network, use getNetwork().
If you come from another chain, use @bsv/wallet-helper (beta) to describe outputs, scripts and change explicitly while the wallet still holds the keys and signs. It runs in the browser and in Node.
import { WalletClient } from '@bsv/sdk'
import { TransactionBuilder } from '@bsv/wallet-helper'
const recipientAddress = '<testnet address>'
const wallet = new WalletClient('auto', 'example.com')
const { txid } = await new TransactionBuilder(wallet, 'Pay a testnet address')
.addP2PKHOutput({ address: recipientAddress, satoshis: 1000 })
.build()
console.log(txid)Sample output #
1713a693288b5f9669ee48ca6fc471156e2d5dc6f9d47131f8a77610bb8d4dafThe wallet asks the user to approve the spend before the transaction ID prints.
A single transaction is simpler with @bsv/simple, and full low-level control comes from @bsv/sdk.
A service, bot or test harness that owns its key, with no person approving each transaction, starts from @bsv/simple/server. The server entry point is part of the @bsv/simple package, so install that package:
npm install @bsv/simpleimport { ServerWallet } from '@bsv/simple/server'
const wallet = await ServerWallet.create({
privateKey: process.env.SERVER_PRIVATE_KEY!,
network: 'testnet',
storageUrl: 'https://go-wallet-testnet-us-1.bsvblockchain.tech'
})
console.log(await wallet.getBalance())Sample output #
{
totalSatoshis: 0,
totalOutputs: 0,
spendableSatoshis: 0,
spendableOutputs: 0
}On testnet, storageUrl points at BSV’s testnet storage server, go-wallet-testnet-us-1.bsvblockchain.tech. The public Wallet Infra endpoints, such as store-us-1.bsvb.tech, store-eu-1.bsvb.tech and store-ap-1.bsvb.tech, store mainnet wallets. You can also point storageUrl at your own deployment.
BSV recommends keeping wallet storage local when you can, with Setup.createWalletSQLite from @bsv/wallet-toolbox. Funding a server wallet from BSV Desktop doesn’t work yet: the payment is rejected with The tx parameter must be valid AtomicBEEF. A fix is in progress.
If you are building the wallet itself, use @bsv/wallet-toolbox instead.
Implementing a wallet, extending its storage, building permission screens, or porting the wallet model to another language starts from @bsv/wallet-toolbox. The package ships the reference pieces: Wallet, WalletStorageManager, storage providers, WalletSigner, Services, Monitor, key managers, permissions, and test utilities such as MockChain. The BRC-100 Wallet Interface page explains the boundary between an app and a wallet.
import { PrivateKey } from '@bsv/sdk'
import { Setup } from '@bsv/wallet-toolbox'
const key = PrivateKey.fromRandom()
const identityKey = key.toPublicKey().toString()
const { wallet } = await Setup.createWalletSQLite({
env: {
chain: 'test',
identityKey,
identityKey2: identityKey,
filePath: 'wallet.sqlite',
taalApiKey: '',
devKeys: { [identityKey]: key.toHex() }
},
rootKeyHex: key.toHex(),
filePath: 'wallet.sqlite',
databaseName: 'my-wallet'
})
console.log(await wallet.getNetwork())Sample output #
{ network: 'testnet' }An ordinary web app, or a backend agent with a private key, starts from one of the first three tabs.
Code that works with the primitives themselves, with nothing built on top of them, uses @bsv/sdk directly. It covers secp256k1 and secp256r1 cryptography, hashing, Script, transactions, BEEF (BRC-62), Merkle paths (BRC-74), BRC-42 key derivation, ARC broadcasting, and the BRC-100 interface types with wallet substrates.
import { PrivateKey, P2PKH } from '@bsv/sdk'
const key = PrivateKey.fromRandom()
const address = key.toPublicKey().toAddress()
console.log(address, new P2PKH().lock(address).toASM())Sample output #
1AB4wscnziNS6euaxcF39VrWW77SZh485A OP_DUP OP_HASH160 64a095f0148483a9c603de9255bd98ce066f3ab6 OP_EQUALVERIFY OP_CHECKSIGFor a full wallet with persistent storage and signing, use @bsv/wallet-toolbox, and for token issuance and transfer, use @bsv/btms.
Services and Packages for Other Jobs
Some pieces are shared services you run or connect to, not packages you install:
| Service | What it does |
|---|---|
| Wallet Infra | JSON-RPC storage and management of wallet UTXOs |
| Message Box Server | Peer-to-peer messaging with real-time WebSocket delivery |
| Overlay Server | Topic managers and lookup services for an overlay network |
| UHRP Server | Production file storage on Google Cloud, addressed by content |
| Wallet Abstraction Backend (WAB) | Multi-factor user authentication and key recovery, with SMS, ID verification and one-time codes |
| Chaintracks Server | Block header chain and Merkle root validation over REST |
For work beyond the starting points above, add the package built for it:
| You are building | Add |
|---|---|
| Messaging between users | @bsv/message-box-client with a Message Box Server |
| A token system | @bsv/btms and @bsv/btms-permission-module |
| An overlay node | @bsv/overlay and @bsv/overlay-express |
| An authenticated API | @bsv/auth-express-middleware |
| A payment-gated API | @bsv/402-pay (beta), set up in Gate an API Behind Payments |
| File storage | @bsv/overlay-topics (experimental) with a UHRP Server |
Related Articles
To learn more about the BSV stack, review these articles:
- Send a payment from a web app
- Send a payment from a server
- BRC-100 Wallet Interface
- How the BSV Stack Fits Together
- Gate an API Behind Payments