solana-token-toolkit
Token account workflow primitives for Solana applications.
Status: v0.2. API is stable within minor versions.
What this is
solana-token-toolkit provides three tiers of token-account utilities:
- State (
fetch_token_account_state,assemble_token_account_state) — query the on-chain state of an owner's ATAs across a set of mints - Mint extensions (
get_token_mint_metadata,detect_transfer_hooks,reject_transfer_hook_mints) — parse Token-2022 transfer fees and transfer hooks - ATA workflow (
prepare_token_accounts) — produce instructions to prepare token accounts for a transaction, including wSOL wrapping paths and non-SOL balance validation
It is independent of any DEX or wallet abstractions. No global mutable state. No anyhow in public API.
Installation
[]
= "0.2"
= "3"
= "3"
= "4"
= "3"
= "2" # for native_mint::ID in examples
Compatible with stable Solana SDK 3.x split crates. MSRV: Rust 1.89.
Usage
End-to-end example: ensure two token accounts exist (one regular SPL token, one wSOL wrapped from native SOL), then build a transaction.
use HashMap;
use RpcClient;
use Keypair;
use Pubkey;
use Signer;
use *;
use native_mint;
# async
For non-SOL token-balance assertions:
let mut intent = TokenAccountIntent ;
intent.mints.insert;
// prepare_token_accounts returns Err(InsufficientBalance { ... }) if balance is too low.
For byte-compat with legacy non-idempotent ATA create:
let plan = prepare_token_accounts?;
For full v0.1 → v0.2 migration steps, see CHANGELOG.md.
Key design decisions
- No global mutable state — wrapping and ATA create modes are per-call config.
- Caller-provided rent — the library stays synchronous in Tier 3.
- Deterministic instruction order —
prepare_token_accountssorts intents by mint pubkey. - Typed errors — no
anyhowin public API. - No Seed strategy — protocol-specific wrapping is intentionally out of scope.
- Temporary wSOL when created by the toolkit —
MintIntent::WithBalance+WrapSolStrategy::Atacreates a wSOL ATA if missing, uses it for the main transaction, and includes a cleanup close instruction for that newly-created ATA. Existing user wSOL ATAs are never auto-closed.
License
Dual-licensed under MIT or Apache-2.0.