Skip to content

@thru/sdk

View as Markdown

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.

Terminal window
npm install @thru/sdk

For 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.

ImportWhat it provides
@thru/sdkMain SDK surface: createThruClient, domain models, modules, filters, transaction helpers, and stream helpers.
@thru/sdk/clientMinimal bound-client setup: createThruClient, Thru, and ThruClientConfig.
@thru/sdk/protoGenerated protobuf schemas, service definitions, view enums, and create from @bufbuild/protobuf.
@thru/sdk/helpersAddress, signature, base64, hex, byte, and Web Crypto helpers.
@thru/sdk/cryptoMnemonic and HD wallet utilities for wallet onboarding.
@thru/sdk/abiWASM-backed ABI reflection, formatting, manifest handling, and import resolution.
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);

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.

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:

import { createThruClient, type Thru } from "@thru/sdk/client";
const thru: Thru = createThruClient({
baseUrl: "https://grpc-web.alphanet.thruput.org",
});

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);

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.

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);

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);

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));