@solana/kit Basics
9 examples to get you started with @solana/kit - 6 basic and 3 intermediate.
Search across all documentation pages
9 examples to get you started with @solana/kit - 6 basic and 3 intermediate.
Install kit 7.0.0 and the system program helpers:
npm install @solana/kit@7.0.0 @solana-program/systemSet RPC_URL to a devnet endpoint (provider URL recommended over public rate limits).
Typed JSON-RPC with .send() on every method.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const slot = await rpc.getSlot().send();
console.log(slot);createSolanaRpc returns a tree-shakable client - import only what you use..send() for explicit network I/O.Related: RPC & Subscriptions - subscriptions and providers
Addresses are branded strings - not byte arrays in app code.
import { createSolanaRpc, address, lamports } from "@solana/kit";
const rpc = createSolanaRpc(process.env.RPC_URL!);
const owner = address("YOUR_WALLET_PUBKEY");
const { value } = await rpc.getBalance(owner).send();
console.log(Number(value) / 1e9);address() validates base58 and returns a typed Address.Lamports (bigint) - convert carefully for display.Related: RPC & Subscriptions - HTTP vs WebSocket
Server scripts and tests use explicit signers.
import { generateKeyPairSigner } from "@solana/kit";
const signer = await generateKeyPairSigner();
console.log(signer.address);generateKeyPairSigner creates an Ed25519 key usable in transaction messages.Related: Keypairs & Signers - CryptoKey and file import
Match the solana-keygen array format.
import { createKeyPairSignerFromBytes } from "@solana/kit";
import { readFileSync } from "node:fs";
const secret = Uint8Array.from(
JSON.parse(readFileSync("./dev-wallet.json", "utf8"))
);
const signer = await createKeyPairSignerFromBytes(secret);Related: Keypairs & Signers - signer traits
Blockhashes expire - refresh per transaction batch.
const { value: blockhash } = await rpc.getLatestBlockhash().send();
console.log(blockhash.blockhash, blockhash.lastValidBlockHeight);lastValidBlockHeight - stale hashes fail confirmation.Related: Building Transaction Messages - lifetimes
Functional pipe composes immutable message transforms.
import {
createTransactionMessage,
pipe,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstruction,
} from "@solana/kit";
import { getTransferSolInstruction } from "@solana-program/system";
const message = pipe(
createTransactionMessage({ version: 0 }),
(m) => setTransactionMessageFeePayerSigner(signer, m),
(m) => setTransactionMessageLifetimeUsingBlockhash(blockhash, m),
(m) =>
appendTransactionMessageInstruction(
getTransferSolInstruction({
source: signer,
destination: recipient,
amount: 10_000_000n,
}),
m
)
);@solana-program/* packages, not string program IDs.bigint lamports.Related: Building Transaction Messages - full pipeline
Signers are resolved from the message, then RPC submits the wire transaction.
import {
signTransactionMessageWithSigners,
getSignatureFromTransaction,
sendAndConfirmTransactionFactory,
} from "@solana/kit";
const signed = await signTransactionMessageWithSigners(message);
const signature = getSignatureFromTransaction(signed);
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
await sendAndConfirm(signed, { commitment: "confirmed" });signTransactionMessageWithSigners collects required signers from the message.Related: Signing & Sending - confirmation strategies
Push updates beat polling for wallet UIs.
import { createSolanaRpcSubscriptions, address } from "@solana/kit";
const rpcSubscriptions = createSolanaRpcSubscriptions("wss://api.devnet.solana.com");
const abort = new AbortController();
const notifications = await rpcSubscriptions
.accountNotifications(address("YOUR_ACCOUNT"), { commitment: "confirmed" })
.subscribe({ abortSignal: abort.signal });
for await (const n of notifications) {
console.log(n.value.lamports);
}wss:// endpoints - HTTP URLs fail for subscriptions.Related: RPC & Subscriptions - subscription types
Kit codecs replace hand-rolled Buffer layouts.
import {
getU32Encoder,
getU32Decoder,
getStructEncoder,
getStructDecoder,
} from "@solana/kit";
const layout = getStructEncoder([["count", getU32Encoder()]]);
const bytes = layout.encode({ count: 42 });
const decoded = getStructDecoder([["count", getU32Decoder()]]).decode(bytes);Related: Codecs & Serialization - advanced layouts
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.
Reviewed by Chris St. John·Last updated Jul 19, 2026