# SDKs overview

import StackChooser from '/snippets/StackChooser.jsx';

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.

<StackChooser />

Shared services such as wallet storage, messaging or overlay lookup are not packages. They are covered in [Services and Packages for Other Jobs](#services-and-packages-for-other-jobs).

## See Each Package in Code

<Tabs>
<Tab title="WalletClient">

Your app asks a local <Hint tip="The standard interface between an app and a wallet">BRC-100</Hint> 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.

```typescript
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())
```

<Accordion title="Sample output">

```text
{ network: 'testnet' }
```

</Accordion>

<Callout type="info">
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()`.
</Callout>

</Tab>
<Tab title="Wallet helper">

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.

```typescript
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)
```

<Accordion title="Sample output">

```text
1713a693288b5f9669ee48ca6fc471156e2d5dc6f9d47131f8a77610bb8d4daf
```

The wallet asks the user to approve the spend before the transaction ID prints.

</Accordion>

A single transaction is simpler with `@bsv/simple`, and full low-level control comes from `@bsv/sdk`.

</Tab>
<Tab title="Server wallet">

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:

```bash
npm install @bsv/simple
```

```typescript
import { 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())
```

<Accordion title="Sample output">

```text
{
  totalSatoshis: 0,
  totalOutputs: 0,
  spendableSatoshis: 0,
  spendableOutputs: 0
}
```

</Accordion>

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.

<Callout type="warning">
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.
</Callout>

If you are building the wallet itself, use `@bsv/wallet-toolbox` instead.

</Tab>
<Tab title="Wallet toolbox">

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](/docs/concepts/wallet-model/) page explains the boundary between an app and a wallet.

```typescript
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())
```

<Accordion title="Sample output">

```text
{ network: 'testnet' }
```

</Accordion>

An ordinary web app, or a backend agent with a private key, starts from one of the first three tabs.

</Tab>
<Tab title="SDK primitives">

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](/docs/concepts/spv/) (BRC-62), Merkle paths (BRC-74), BRC-42 key derivation, ARC broadcasting, and the BRC-100 interface types with wallet substrates.

```typescript
import { PrivateKey, P2PKH } from '@bsv/sdk'

const key = PrivateKey.fromRandom()
const address = key.toPublicKey().toAddress()
console.log(address, new P2PKH().lock(address).toASM())
```

<Accordion title="Sample output">

```text
1AB4wscnziNS6euaxcF39VrWW77SZh485A OP_DUP OP_HASH160 64a095f0148483a9c603de9255bd98ce066f3ab6 OP_EQUALVERIFY OP_CHECKSIG
```

</Accordion>

For a full wallet with persistent storage and signing, use `@bsv/wallet-toolbox`, and for token issuance and transfer, use `@bsv/btms`.

</Tab>
</Tabs>

## 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](/docs/wallet-dev/infrastructure/) | JSON-RPC storage and management of wallet UTXOs |
| [Message Box Server](https://bsv-blockchain.github.io/ts-stack/infrastructure/message-box-server/) | Peer-to-peer messaging with real-time WebSocket delivery |
| [Overlay Server](https://bsv-blockchain.github.io/ts-stack/infrastructure/overlay-server/) | Topic managers and lookup services for an overlay network |
| [UHRP Server](https://bsv-blockchain.github.io/ts-stack/infrastructure/uhrp-server-cloud-bucket/) | Production file storage on Google Cloud, addressed by content |
| [Wallet Abstraction Backend (WAB)](/docs/wallet-dev/infrastructure/) | Multi-factor user authentication and key recovery, with SMS, ID verification and one-time codes |
| [Chaintracks Server](https://bsv-blockchain.github.io/ts-stack/infrastructure/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](/docs/guides/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](/docs/get-started/quick-start-browser/)
- [Send a payment from a server](/docs/get-started/quick-start-server/)
- [BRC-100 Wallet Interface](/docs/concepts/wallet-model/)
- [How the BSV Stack Fits Together](/docs/concepts/architecture/)
- [Gate an API Behind Payments](/docs/guides/payments/)