@solana/kit Best Practices
A condensed summary of 25 practices for production @solana/kit 7.0.0 clients.
-
Pin @solana/kit@7.0.0: Lock the major version in package.json and CI - RPC typings drift across minors (@solana/kit Basics).
-
Import narrowly: Use subpath exports and program packages to keep bundles small.
-
Always
.send()RPC calls: Builders are lazy until sent. -
Use
bigintlamports: Never float SOL math in UI or servers. -
Separate HTTP and WSS URLs: Subscriptions need
wss://endpoints (RPC & Subscriptions). -
Abort WebSocket subscriptions: Clean up on React unmount and route changes.
-
Fetch fresh blockhashes per submit: Stale lifetimes are the top confirmation failure.
-
Simulate before wallet prompt: Save users from paying for predictable errors (Signing & Sending).
-
Set fee payer signers explicitly: Address strings alone do not sign (Keypairs & Signers).
-
Prepend compute budget instructions: Priority fees and CU limits belong first in the message.
-
Prefer version 0 messages: Default for ALTs and modern validators.
-
Generate codecs from IDL: Hand-rolled layouts drift from Anchor 0.32.1 programs (Codecs & Serialization).
-
Regenerate Codama clients in CI: Fail builds when IDL changes dirty generated folders.
-
Provider RPC for production: Public endpoints rate-limit; use keyed URLs.
-
Match commitment to risk:
confirmedfor UX;finalizedfor treasury reads. -
Never embed mainnet secrets in frontend: Browser code is public; use wallets or server sponsorship.
-
Log signatures and explorer links: Support tickets need traceable transaction IDs.
-
Handle wallet rejections gracefully: Users cancel connects and signs - surface clear retry UX.
-
Migrate off web3.js per route: Dual stacks double bundle size and bugs (Migrating from web3.js v1).
-
Use
sendAndConfirmTransactionFactorywith WSS: HTTP-only confirm loops are brittle under load. -
Compress with fresh ALT data: Reload lookup table accounts before
compressTransactionMessageUsingAddressLookupTables. -
Type addresses with
address(): Catch invalid base58 at construction. -
Test against Surfpool 0.12.0: Local Agave-compatible runs before devnet spend.
-
Document RPC capabilities: DAS, priority fee APIs, and simulation differ by vendor.
-
Keep wallet and kit versions aligned: create-solana-dapp templates track compatible adapter + kit pairs.
FAQs
Should new apps start with kit?
Yes - web3.js v1 is legacy for greenfield TypeScript.
Is gill required?
No - it accelerates bootstrap but kit is the core dependency.
One RPC client per app?
Typically one HTTP + one WSS factory reused via context.
How big should bundles be?
Audit with your bundler - tree-shaking only works with narrow imports.
Devnet vs mainnet config?
Environment variables per deployment; never hardcode mainnet URLs in shared components.
Related
- @solana/kit Basics - hands-on intro
- Wallet Integration Best Practices - browser signers
- Typed Clients Best Practices - IDL-driven clients
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.