---
title: "@thru/sdk"
description: Typed JavaScript and TypeScript SDK for Thru RPC, domain models,
  protobufs, helpers, crypto, and ABI reflection.
source_url:
  html: https://thru.org/docs/sdks/web-packages/sdk/
  md: https://thru.org/docs/sdks/web-packages/sdk.md
---

# @thru/sdk

Use `@thru/sdk` as the default TypeScript package for Thru applications and backend services. It contains the bound RPC client, domain models, transaction helpers, generated protobuf types, address/signature helpers, wallet crypto utilities, and ABI reflection tools.

## Install

```bash
npm install @thru/sdk
```

For TypeScript, use modern module resolution:

```json
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "module": "ESNext",
    "target": "ES2020"
  }
}
```

Use `"moduleResolution": "nodenext"` if your app runs directly on Node ESM without a bundler.

## Entry Points

| Import | What it provides |
| - | - |
| `@thru/sdk` | Main SDK surface: `createThruClient`, domain models, modules, filters, transaction helpers, and stream helpers. |
| `@thru/sdk/client` | Minimal bound-client setup: `createThruClient`, `Thru`, and `ThruClientConfig`. |
| `@thru/sdk/proto` | Generated protobuf schemas, service definitions, view enums, and `create` from `@bufbuild/protobuf`. |
| `@thru/sdk/helpers` | Address, signature, base64, hex, byte, and Web Crypto helpers. |
| `@thru/sdk/crypto` | Mnemonic and HD wallet utilities for wallet onboarding. |
| `@thru/sdk/abi` | WASM-backed ABI reflection, formatting, manifest handling, and import resolution. |

## Basic Usage

```ts
import { AccountView, createThruClient } from "@thru/sdk";

const thru = createThruClient({
  baseUrl: "https://grpc-web.alphanet.thruput.org",
});

const height = await thru.blocks.getBlockHeight();
const block = await thru.blocks.get({ slot: height.finalized });

const account = await thru.accounts.get("taExampleAddress...", {
  view: AccountView.FULL,
});

console.log(block.header.blockHash, account.meta?.balance);
```

## Domain Models

The root package exports domain classes for the objects most apps pass around:

- `Account`, `AccountMeta`, and `AccountData`
- `Block`, `BlockHeader`, and `BlockFooter`
- `Transaction`, `TransactionBuilder`, and `TransactionStatusSnapshot`
- `ChainEvent`
- `StateProof`
- `HeightSnapshot`
- `VersionInfo`
- `Pubkey` and `Signature`
- `Filter` and `FilterParamValue`

These classes wrap protobuf data with validation, defensive byte copies, and conversion helpers.

## Client Modules

The bound client groups common workflows under stable modules:

- `thru.accounts`
- `thru.blocks`
- `thru.chain`
- `thru.consensus`
- `thru.events`
- `thru.height`
- `thru.keys`
- `thru.node`
- `thru.nonce`
- `thru.proofs`
- `thru.slots`
- `thru.streaming`
- `thru.transactions`
- `thru.version`

Use `@thru/sdk/client` when you only need the client constructor and its types:

```ts
import { createThruClient, type Thru } from "@thru/sdk/client";

const thru: Thru = createThruClient({
  baseUrl: "https://grpc-web.alphanet.thruput.org",
});
```

## Transaction Flow

Use `transactions.build(...)` when another wallet or custody layer signs the payload. Use `transactions.buildAndSign(...)` when your app owns the fee-payer key material directly.

```ts
import { decodeAddress } from "@thru/sdk/helpers";

const tx = await thru.transactions.build({
  feePayer: { publicKey: decodeAddress(feePayerAddress) },
  program: programAddress,
  accounts: {
    readWrite: readWriteAccounts,
    readOnly: readOnlyAccounts,
  },
  instructionData,
});

const signingPayload = tx.toWireForSigning();
const signedWire = await externalSigner.signTransaction(signingPayload);
const result = await thru.transactions.sendAndTrack(signedWire);
```

## Protobufs

Use `@thru/sdk/proto` when you need generated message schemas or service definitions directly:

```ts
import { create, GetBlockRequestSchema, QueryService } from "@thru/sdk/proto";

const request = create(GetBlockRequestSchema, {
  selector: { case: "slot", value: 100n },
});
```

Most apps should prefer the domain SDK unless they are writing low-level RPC middleware, test harnesses, or protocol tooling.

## Helpers

Use `@thru/sdk/helpers` for lightweight encoding and byte utilities:

```ts
import { decodeAddress, encodeAddress, encodeSignature } from "@thru/sdk/helpers";

const bytes = decodeAddress("taExampleAddress...");
const address = encodeAddress(bytes);
const signature = encodeSignature(signatureBytes);
```

## Crypto

Use `@thru/sdk/crypto` for mnemonic and HD wallet flows:

```ts
import { MnemonicGenerator, ThruHDWallet } from "@thru/sdk/crypto";

const mnemonic = MnemonicGenerator.generate();
const wallet = await ThruHDWallet.fromMnemonic(mnemonic);
```

## ABI Reflection

Use `@thru/sdk/abi` when explorers, debuggers, or tests need to decode raw account, instruction, or event bytes from ABI YAML.

```ts
import { ensureWasmLoaded, formatReflection, reflectInstruction } from "@thru/sdk/abi";

await ensureWasmLoaded();
const reflected = await reflectInstruction(abiYaml, instructionBytes);
console.log(formatReflection(reflected));
```

## Related

- [`@thru/programs`](https://thru.org/docs/sdks/web-packages/programs.md) for token and passkey-manager program bindings.
- [`@thru/wallet`](https://thru.org/docs/sdks/web-packages/wallet.md) for embedded wallet integration.
- [`@thru/replay`](https://thru.org/docs/sdks/web-packages/replay.md) and [`@thru/indexer`](https://thru.org/docs/sdks/web-packages/indexer.md) for chain data pipelines.
