@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
Section titled “Install”npm install @thru/sdkFor TypeScript, use modern module resolution:
{ "compilerOptions": { "moduleResolution": "bundler", "module": "ESNext", "target": "ES2020" }}Use "moduleResolution": "nodenext" if your app runs directly on Node ESM without a bundler.
Entry Points
Section titled “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
Section titled “Basic Usage”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
Section titled “Domain Models”The root package exports domain classes for the objects most apps pass around:
Account,AccountMeta, andAccountDataBlock,BlockHeader, andBlockFooterTransaction,TransactionBuilder, andTransactionStatusSnapshotChainEventStateProofHeightSnapshotVersionInfoPubkeyandSignatureFilterandFilterParamValue
These classes wrap protobuf data with validation, defensive byte copies, and conversion helpers.
Client Modules
Section titled “Client Modules”The bound client groups common workflows under stable modules:
thru.accountsthru.blocksthru.chainthru.consensusthru.eventsthru.heightthru.keysthru.nodethru.noncethru.proofsthru.slotsthru.streamingthru.transactionsthru.version
Use @thru/sdk/client when you only need the client constructor and its types:
import { createThruClient, type Thru } from "@thru/sdk/client";
const thru: Thru = createThruClient({ baseUrl: "https://grpc-web.alphanet.thruput.org",});Transaction Flow
Section titled “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.
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
Section titled “Protobufs”Use @thru/sdk/proto when you need generated message schemas or service definitions directly:
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
Section titled “Helpers”Use @thru/sdk/helpers for lightweight encoding and byte utilities:
import { decodeAddress, encodeAddress, encodeSignature } from "@thru/sdk/helpers";
const bytes = decodeAddress("taExampleAddress...");const address = encodeAddress(bytes);const signature = encodeSignature(signatureBytes);Crypto
Section titled “Crypto”Use @thru/sdk/crypto for mnemonic and HD wallet flows:
import { MnemonicGenerator, ThruHDWallet } from "@thru/sdk/crypto";
const mnemonic = MnemonicGenerator.generate();const wallet = await ThruHDWallet.fromMnemonic(mnemonic);ABI Reflection
Section titled “ABI Reflection”Use @thru/sdk/abi when explorers, debuggers, or tests need to decode raw account, instruction, or event bytes from ABI YAML.
import { ensureWasmLoaded, formatReflection, reflectInstruction } from "@thru/sdk/abi";
await ensureWasmLoaded();const reflected = await reflectInstruction(abiYaml, instructionBytes);console.log(formatReflection(reflected));Related
Section titled “Related”@thru/programsfor token and passkey-manager program bindings.@thru/walletfor embedded wallet integration.@thru/replayand@thru/indexerfor chain data pipelines.