← Protocols
Solana Web3.js / Solana Kit
Other Chain·Solana

Solana Web3.js / Solana Kit

01Description

Official JavaScript/TypeScript SDK for Solana. The legacy `@solana/web3.js` v1 (Solana Labs) is being superseded by `@solana/kit` (web3.js v2, maintained by Anza) — a tree-shakeable, functional, codec-driven rebuild that ships smaller bundles, native BigInt support, and first-class TypeScript types. New apps should target `@solana/kit`; the legacy `Connection`/`Transaction`/`PublicKey` classes still work for migration but receive only critical fixes.

02Best for
  • 01Solana dapps and program (smart contract) interaction
  • 02wallet adapter integrations (Phantom, Backpack, Solflare)
  • 03transaction construction and simulation
  • 04RPC reads (account state, token balances, program logs)
  • 05migrations from web3.js v1 to @solana/kit (v2)
03Install
  • pnpm add @solana/kit @solana/wallet-adapter-react @solana/wallet-adapter-wallets
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_SOLANA_CLUSTERClientCluster identifier — `mainnet-beta`, `devnet`, or `testnet`.
NEXT_PUBLIC_SOLANA_RPC_URLClientJSON-RPC endpoint URL (e.g. https://api.mainnet-beta.solana.com, or a Helius/QuickNode/Triton URL). Public RPC is heavily rate-limited; use a paid provider in production.
05Prompt snippet
Use `@solana/kit` (web3.js v2) for new code: `const rpc = createSolanaRpc(process.env.NEXT_PUBLIC_SOLANA_RPC_URL!); const balance = await rpc.getBalance(address('...')).send();`. Build transactions functionally via `pipe(createTransactionMessage({ version: 0 }), m => setTransactionMessageFeePayer(payer, m), m => appendTransactionMessageInstructions([ix], m))` then `signTransactionMessageWithSigners` and `sendAndConfirmTransaction`. For legacy code: `const connection = new Connection(rpcUrl, 'confirmed'); const tx = new Transaction().add(SystemProgram.transfer({ fromPubkey: new PublicKey(from), toPubkey: new PublicKey(to), lamports }));` then `sendAndConfirmTransaction(connection, tx, [payer])`. Wrap React apps in `<ConnectionProvider><WalletProvider><WalletModalProvider>` and read `useWallet()` (`publicKey`, `signTransaction`, `sendTransaction`).
06Gotchas
  • `@solana/web3.js` v2 is rebranded as `@solana/kit` — it is NOT a drop-in upgrade. Class APIs (`Connection`, `Transaction`, `PublicKey`, `Keypair`) are replaced by tree-shakeable functional modules; v1 imports must be migrated piecemeal or kept side-by-side.
  • Solana accounts pay rent unless funded above the rent-exempt minimum (~0.00089 SOL per 128 bytes); under-funded accounts are silently garbage-collected and on-chain state vanishes.
  • Versioned transactions (v0) are required for using Address Lookup Tables — using a legacy `Transaction` with an LUT throws `Transaction does not support address lookup tables`.
  • Compute units default to 200k per instruction (1.4M per tx) — heavy programs need `ComputeBudgetProgram.setComputeUnitLimit`/`setComputeUnitPrice` to land during congestion.
  • Public RPC (`api.mainnet-beta.solana.com`) is throttled to ~40 req/10s and refuses `getProgramAccounts` without filters — use Helius, QuickNode, or Triton for any production load.
  • Priority fees are mandatory during congestion: a confirmed signature can still fail to land. Always set a priority fee from a recent percentile (e.g. via `getRecentPrioritizationFees`) and resend on `BlockhashNotFound`.
  • BigInt return types: `@solana/kit` returns lamports/balances as BigInt — JSON-serializing them without a replacer throws `Do not know how to serialize a BigInt`.
07Alternatives