Skip to main content
@thru/token-program is the root package for building and reading Thru token-program data. Use it when you need to create token instructions, derive token addresses, parse mint or token account state, or format token amounts for display.

Install

npm install @thru/token-program

Root export

The package exposes a single root entrypoint. Import everything you need from @thru/token-program.

When to use it

Use @thru/token-program when you are working at the token-program layer. If you need the full RPC client and transaction workflows around tokens, use @thru/thru-sdk. If you only need generated request/response types, use @thru/proto.

Main entrypoints

Instruction builders

These helpers return an async InstructionData function that accepts an AccountLookupContext and resolves to serialized instruction bytes.
  • createInitializeMintInstruction
  • createInitializeAccountInstruction
  • createMintToInstruction
  • createTransferInstruction
  • buildTokenInstructionBytes
Use createInitializeMintInstruction and createInitializeAccountInstruction when you are setting up a new mint or token account. Use createMintToInstruction and createTransferInstruction when you are moving balances after accounts already exist.

Address derivation

  • deriveMintAddress
  • deriveTokenAccountAddress
  • deriveWalletSeed
These helpers derive deterministic token addresses from mint, owner, wallet, and seed inputs. deriveMintAddress expects a 32-byte hex seed, and deriveTokenAccountAddress defaults to a 32-byte zero seed.

Account parsing

  • parseMintAccountData
  • parseTokenAccountData
  • isAccountNotFoundError
Use these when you already have an Account from @thru/thru-sdk and want typed mint or token account details back. The parsers return MintAccountInfo and TokenAccountInfo.

Formatting and helpers

  • formatRawAmount
  • bytesToHex
  • hexToBytes
  • PUBKEY_LENGTH
  • TICKER_MAX_LENGTH
  • ZERO_PUBKEY
These are useful for display, byte conversion, and working with token-program constants.

Common flow

For a mint setup flow, the package typically looks like this:
  1. Derive the mint or token account address.
  2. Build the initialization instruction.
  3. Serialize the instruction bytes with AccountLookupContext.
  4. Parse the resulting account data later with the account helpers.
For transfers, you usually need the source account, destination account, and amount, then call createTransferInstruction.

Example

import {
  createInitializeMintInstruction,
} from "@thru/token-program";

const buildInstruction = createInitializeMintInstruction({
  mintAccountBytes: new Uint8Array(32),
  decimals: 9,
  mintAuthorityBytes: new Uint8Array(32),
  ticker: "TKN",
  seedHex: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
  stateProof: new Uint8Array(),
});

const bytes = await buildInstruction({
  getAccountIndex: () => 0,
});