# Use the TypeScript SDK

> For the complete documentation index, see [llms.txt](https://bsvblockchain.com/docs/llms.txt).

@bsv/sdk is the TypeScript library for BSV blockchain apps, used to call the user's wallet through WalletClient or to build keys, scripts and transactions directly, in Node, browsers and React.

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

Use `@bsv/sdk` to connect a TypeScript app to the user's wallet, or to build keys, scripts and transactions yourself, in Node, in the browser or in a React app. It is the base library of the BSV blockchain TypeScript stack. `@bsv/simple` and `@bsv/wallet-toolbox` are built on it. It has no runtime dependencies. This page was written against `@bsv/sdk` 4.0.1.

To compare `@bsv/sdk` with the other packages before you choose, see the [SDKs overview](https://bsvblockchain.com/docs/sdk/).

## Two ways to use the SDK

An app uses the SDK in one of two ways, depending on who holds the private key:

<BlueTable>

| Task | Through the user's wallet | By hand |
| --- | --- | --- |
| Hold the keys and sign | The wallet, under the user's control | Your code |
| Choose the coins and the fee | The wallet | Your code |
| Send the transaction to the network | The wallet | Your code, with a broadcaster |
| Choose the network | The wallet | Your code |
| Main classes | `WalletClient` | `PrivateKey`, `Transaction`, `P2PKH` (Pay to Public Key Hash, the standard script that locks coins to an address) |

</BlueTable>

### Through the user's wallet

`WalletClient` implements BRC-100 (BSV Request for Comments 100, the standard interface between apps and wallets) on the app side. It finds a compatible wallet, such as [BSV Desktop](https://bsvblockchain.com/docs/wallets/bsv-desktop/) on the user's computer, or [BSV Browser](https://bsvblockchain.com/docs/wallets/bsv-browser/) on the phone, where the app runs inside the wallet's browser. It calls methods such as `createAction` and `getPublicKey` on it. Your app never holds a private key, and the wallet asks the user to approve spends according to the permissions the user set. Most apps start here, and the [Quick Start](https://bsvblockchain.com/docs/get-started/quick-start-browser/) sends a first transaction this way.

### By hand

Your code holds the key and does the work a wallet would do. It builds each locking script (The part of a transaction output that sets the condition to spend it) and gives each input its source transaction. It also tracks which UTXOs (Unspent transaction output) it has already spent, since two transactions that spend the same output cannot both confirm. Build by hand when you need a custom script or transaction format, cryptography on its own, or SPV (Simplified Payment Verification) checks of transactions you receive.

> When your code holds the private key, it signs with no approval step, and a transaction it broadcasts cannot be undone. Keep the key out of your source code and out of version control, and test on testnet before you use Mainnet.

## What the SDK includes

The package covers both ways, from the wallet interface down to the primitives:

<BlueTable>

| Area | Main classes |
| --- | --- |
| Wallet interface | `WalletClient` to call a BRC-100 wallet, and `ProtoWallet` for key derivation, signatures and encryption without transactions |
| Keys and cryptography | `PrivateKey`, `PublicKey`, `Hash`, and `KeyDeriver` for BRC-42 (BSV Key Derivation Scheme) key derivation |
| Script | `Script`, and the templates `P2PKH`, `PushDrop` and `RPuzzle` |
| Transactions and fees | `Transaction` and the `SatoshisPerKilobyte` fee model |
| Proofs | `Beef` for BEEF (Background Evaluation Extended Format (BRC-62), a transaction sent with its proofs), `MerklePath`, and chain trackers such as `WhatsOnChain` |
| Broadcasting | `ARC` and `Teranode` |
| Authentication | `AuthFetch` and `Peer`, for requests signed with the wallet's identity key |
| [Overlay services](https://bsvblockchain.com/docs/concepts/overlays/) | `LookupResolver` and `TopicBroadcaster` |
| File storage | `StorageUploader` and `StorageDownloader` |

</BlueTable>

## Where it runs

In Node, `@bsv/sdk` needs Node.js 22 or newer. It is an ES module package that also ships a CommonJS build and a UMD bundle. Its TypeScript declarations cover both module formats, and it bundles for the browser with tools such as Vite.

## Pages in this section

Start with the setup, then connect to the user's wallet:

**[Install the SDK in Node or React](https://bsvblockchain.com/docs/sdk/typescript/setup/)**

Add `@bsv/sdk` to a Node project, with ES modules or CommonJS, or to a React app.

**[Connect to a wallet with WalletClient](https://bsvblockchain.com/docs/sdk/typescript/wallet-client/)**

Connect to the user's wallet and call its BRC-100 methods.

To build transactions yourself, start from [Build transactions by hand](https://bsvblockchain.com/docs/sdk/typescript/low-level/), then go to the task you need:

**[Build a transaction from inputs and outputs](https://bsvblockchain.com/docs/sdk/typescript/low-level/transactions/)**

Create a transaction with inputs, outputs and script templates.

**[Derive HD keys with BIP32](https://bsvblockchain.com/docs/sdk/typescript/low-level/hd-keys/)**

Derive a tree of keys from one master key with the `HD` class, as BIP32 wallets do.

**[Write a custom script template](https://bsvblockchain.com/docs/sdk/typescript/low-level/script-templates/)**

Write your own script template, with its locking and unlocking scripts.

## Related articles

To learn more about the TypeScript SDK on the BSV blockchain, review these articles:

- [How the BSV blockchain stack fits together](https://bsvblockchain.com/docs/concepts/architecture/)
- [BRC-100 Wallet Interface](https://bsvblockchain.com/docs/concepts/wallet-model/)
- [Broadcast transactions with BSV Broadcaster](https://bsvblockchain.com/docs/guides/services/broadcasting/)