How to Use the Solana SDK to Interact with the Blockchain
The Solana SDK connects your app to the chain through RPC: read accounts, check balances, send transactions and listen for changes. Here is how the pieces fit.
On this page
Short answer
The Solana SDK is the client library that lets your code read accounts, send transactions and subscribe to changes on Solana. For new TypeScript work use @solana/kit, or @solana/web3.js v3 if you prefer the classic Connection and Transaction classes. You connect to an RPC endpoint, fetch a recent blockhash, sign your instructions and confirm at the commitment level you need.
What is the Solana SDK?
The Solana SDK is the client library your code uses to talk to the Solana blockchain. It connects to an RPC node, reads accounts, builds transactions, signs them and sends them to the network, so your app never has to speak the raw JSON-RPC protocol itself.
There are two current choices for TypeScript. @solana/kit is the recommended SDK for new code: it is a small, composable set of packages from Anza that covers RPC, transactions, codecs and signers. @solana/web3.js v3 rebuilds the familiar class-based API (Connection, Keypair, Transaction, PublicKey) on top of Kit internals, and it is the right pick when you are upgrading an existing web3.js app or you prefer classes.
The older @solana/web3.js 1.x is legacy. It receives critical fixes only, and new features land in Kit instead. Start new work on Kit or web3.js v3, and treat v1 as a migration source.
| SDK | Best for | API style | Status |
|---|---|---|---|
| @solana/kit | New TypeScript apps | Functions and plugins | Recommended |
| @solana/web3.js v3 | Upgrades, class fans | Connection, Transaction | Recommended |
| @solana/web3.js 1.x | Old code only | Connection, Transaction | Legacy |
All three speak the same JSON-RPC protocol underneath. Picking one is about the shape of your code, not about what the chain can do. The rest of this guide uses Kit names first and web3.js v3 names in brackets, so you can follow it with either one.
What do you need before you start?
You need four things before you write your first call: a current Node.js LTS release with npm, the SDK installed, an RPC endpoint, and a keypair for signing.
Install the SDK with npm install @solana/kit for Kit, or npm install @solana/web3.js for web3.js v3. A plain install of @solana/web3.js now gives you v3; you only get the legacy 1.x line if you ask for it by version. TypeScript is the normal choice, since both SDKs are typed end to end.
For the RPC endpoint, start on devnet at https://api.devnet.solana.com. Devnet behaves like mainnet but its SOL has no value, and you can request test SOL from a faucet with an airdrop call. Keep mainnet for later, when your code already works.
A keypair is your identity on the chain. Generate one in code with generateKeyPairSigner() in Kit or Keypair.generate() in web3.js v3, and keep the secret key in a file or environment variable that never reaches source control. A wallet such as Phantom or Solflare can sign for a browser app instead, through the wallet adapter.
If you are starting from scratch rather than adding Solana to an existing product, the practical build order is covered in how to build on Solana.
How do you connect to the network?
You connect by creating an RPC client pointed at a cluster URL, then choosing a commitment level that says how final a result must be before you trust it.
Solana has three public clusters: mainnet-beta for real value, devnet for development, and testnet for testing validator releases. In Kit you create the client with createSolanaRpc(url); in web3.js v3 you use new Connection(url). Both return a client that can read accounts, fetch the latest blockhash and send transactions.
Commitment is a promise about how deep a result sits in the chain. The three levels are:
| Commitment | What it means | When to use it |
|---|---|---|
| processed | A leader has run the transaction | Live displays, fast feedback |
| confirmed | A supermajority has voted on it | Most app reads and writes |
| finalized | It cannot be rolled back | Settlement, accounting, audits |
Public endpoints are shared and rate-limited, so a production app needs a dedicated RPC provider such as Helius, QuickNode or Triton. A dedicated endpoint gives you higher limits, better uptime and a WebSocket feed for live updates. The app-side steps for wiring Solana into an existing product are covered in how to implement Solana.
How do you read accounts and balances?
Reading is the simplest part of the SDK: you ask the RPC node for an account by its address and get back its lamport balance, its owner program and its data bytes.
Balances come back in lamports, the smallest unit of SOL. One SOL equals 1,000,000,000 lamports, so divide by a billion to show a human-readable amount. In Kit you call rpc.getBalance(address).send(); in web3.js v3 it is connection.getBalance(publicKey). Both return a plain number.
For the full account, getAccountInfo returns the owner program, the lamport balance, whether the account is executable, and the raw data. Token balances need one more step: a token account holds its amount in a packed format, so decode it with the helpers in @solana-program/token rather than reading the bytes by hand.
To find many accounts at once, use getProgramAccounts with a filter on the owner program. It is the standard way to list, for example, every token account owned by one wallet. Keep these calls cheap: read only the accounts your screen needs, cache results for a few seconds, and prefer a subscription over repeated polling when data changes often.
How do you send a transaction?
You send a transaction by building a message, signing it and submitting it to the network. The SDK handles the wire format; your job is to get the steps and the order right.
- Load a signer. Use your keypair, or ask the connected wallet to sign.
- Fetch a recent blockhash. Every transaction carries one, and it expires after roughly a minute, so fetch it fresh for each transaction.
- Build the instruction. A SOL transfer is SystemProgram.transfer with a source, a destination and a lamport amount.
- Set the fee payer. The fee payer is usually the signer, and the base fee is 5,000 lamports per signature.
- Sign the message. Kit signs with signTransactionMessageWithSigners; web3.js v3 signs the Transaction object.
- Send and confirm. Submit the signed transaction and wait for confirmation at the commitment level you chose.
Confirmation is not instant. Send the transaction, then poll or subscribe for its signature status until it reaches your commitment level. If the blockhash expires before the transaction lands, build it again with a fresh blockhash and resend. Never reuse a signed transaction after its blockhash has expired.
For token transfers, the same flow applies with a token instruction from @solana-program/token instead of a system transfer. The recipient needs an associated token account, which the SDK can create idempotently in the same transaction. When the transfer is part of a program you deploy yourself, see how to build and deploy Solana smart contracts.
How do you listen for changes?
You listen for changes with a WebSocket subscription instead of polling. Subscriptions push updates to your app the moment an account, a program log or a slot changes.
For one account, connection.onAccountChange in web3.js v3 (or createSolanaRpcSubscriptions in Kit) calls your handler with the new account data each time it changes. It is the right tool for a balance display, a wallet view or an order status that must stay current.
For program activity, subscribe to logs with onLogs and filter by program id. You see every instruction your program runs, including errors, which makes it a good debugging aid during development and a good alert source in production.
WebSockets drop, so plan for it. Reconnect with a short backoff, re-subscribe after each reconnect, and re-read the accounts you watch so you do not miss a change that happened while the socket was down. For data that changes rarely, such as a token mint, polling every few seconds is simpler and often good enough.
Example (hypothetical): a tip jar that sends SOL
Example (hypothetical): a small creator site runs a tip jar. A visitor tips 0.5 SOL from a wallet that holds 2.5 SOL, and the app builds and sends the transfer with the SDK.
The app fetches a fresh blockhash, builds a SystemProgram.transfer instruction for 500,000,000 lamports, signs with the visitor's wallet and sends the transaction. The base fee is 5,000 lamports per signature, which is 0.000005 SOL.
The maths is simple. The wallet starts at 2.5 SOL. The tip removes 0.5 SOL and the fee removes 0.000005 SOL, so the wallet ends at 1.999995 SOL. The creator's wallet gains exactly 0.5 SOL.
A second visitor then tips 0.25 SOL from the same wallet. The fee is another 0.000005 SOL, so the wallet ends at 1.74999 SOL: 1.999995 minus 0.25 minus 0.000005. Each tip is its own transaction with its own blockhash and fee, and the app confirms each one before it shows a success message.
If you want to turn this tip jar into a full browser app with wallet connection, the steps are in how to build a dApp on Solana.
What are the common mistakes?
The most common Solana SDK mistakes are using the wrong cluster, mishandling keys, and trusting a transaction before it is confirmed.
- Testing against mainnet. Develop and test on devnet first. Mainnet mistakes cost real SOL, and there is no undo.
- Storing secret keys in code. A keypair file or a private key pasted into source control is a leak waiting to happen. Use environment variables or a secrets store.
- Reusing an old blockhash. A blockhash expires after roughly a minute. Fetch a fresh one per transaction or your send will fail.
- Skipping confirmation. A submitted transaction is not a finished one. Wait for your commitment level before you update balances or mark an order paid.
- Polling instead of subscribing. Hitting a public RPC endpoint in a tight loop burns your rate limit. Use a subscription for live data.
- Mixing SDK versions. Kit, web3.js v3 and legacy v1 look similar but do not mix. Pick one line per project and keep its imports consistent.
Key takeaways
- Use @solana/kit for new code or @solana/web3.js v3 for the class-based API; v1 is legacy
- Connect through an RPC endpoint and pick a commitment level: processed, confirmed or finalized
- Balances are in lamports: 1 SOL equals 1,000,000,000 lamports
- Every transaction needs a fresh blockhash, a fee payer and a signature
- Subscribe over WebSocket for live data instead of polling a public endpoint
Frequently asked questions
Which Solana SDK should I use for a new project?
@solana/kit is the recommended SDK for new TypeScript projects. If you are upgrading an existing app or you prefer classes, @solana/web3.js v3 rebuilds the familiar Connection and Transaction API on Kit internals. Avoid starting new work on web3.js 1.x, which only receives critical fixes.
What is an RPC endpoint?
An RPC endpoint is a server that speaks Solana's JSON-RPC protocol on behalf of your app. You send it read requests and signed transactions, and it forwards them to validators. Public endpoints are shared and rate-limited, so production apps usually pay for a dedicated RPC provider.
How much does a Solana transaction cost?
The base fee is 5,000 lamports per signature, which is 0.000005 SOL. Priority fees can raise the cost when the network is busy, and some programs add rent for the accounts they create. For a plain SOL transfer the cost is a fraction of a cent.
What is a blockhash and why does it expire?
A recent blockhash is a time-bound value included in every transaction, so the network can tell a fresh transaction from a replayed one. It expires after roughly a minute, so you fetch a new one for each transaction. If it expires before your transaction lands, rebuild and resend.
Can I use the SDK in a browser app?
Yes. The SDKs run in browsers as well as Node.js. In a browser you normally let the user's wallet sign, through the wallet adapter, instead of holding a keypair in your own code. Never put a private key in client-side code.
Do I need SOL to develop on Solana?
You need test SOL on devnet, which you can request free from a faucet with an airdrop call. Devnet SOL has no value, so mistakes cost nothing. You only need real SOL once you move to mainnet-beta.