x402agent/SolanaOS / skills/solana-dev
solana-dev
FlaggedUse when user asks to "build a Solana dapp", "write an Anchor program", "create a token", "debug Solana errors", "set up wallet connection", "test my Solana program", "deploy to devnet", or "explain Solana concepts" (rent, accounts, PDAs, CPIs, etc.). End-to-end Solana development playbook covering wallet connection, Anchor/Pinocchio programs, Codama client generation, LiteSVM/Mollusk/Surfpool testing, and security checklists. Integrates with the Solana MCP server for live documentation search. Prefers framework-kit (@solana/client + @solana/react-hooks) for UI, wallet-standard-first connection (incl. ConnectorKit), @solana/kit for client/RPC code, and @solana/web3-compat for legacy boundaries.
references/kit/accounts.md
View on GitHub---
title: Accounts Reference
description: Account fetching, decoding, batch operations, PDA derivation, subscriptions, and token account queries using @solana/kit.
---
# Solana Kit Accounts Reference
## Fetch Single Account
```ts
import { fetchEncodedAccount, assertAccountExists, decodeAccount } from '@solana/kit';
const account = await fetchEncodedAccount(rpc, myAddress);
assertAccountExists(account); // Throws if account doesn't exist
const decoded = decodeAccount(account, myDecoder);
```
### Check Existence Without Throwing
```ts
const account = await fetchEncodedAccount(rpc, myAddress);
if (!account.exists) {
// Handle missing account
}
```
## Fetch Multiple Accounts
```ts
const { value: accounts } = await rpc.getMultipleAccounts(
[address1, address2, address3],
{ encoding: 'base64' },
).send();
```
## Typed Account Fetching (Codama)
Codama-generated clients provide typed fetch helpers:
```ts
import { fetchMint, fetchMaybeMint } from '@solana-program/token';
// Throws if not found
const mint = await fetchMint(rpc, mintAddress);
// mint.data.decimals, mint.data.supply — fully typed
// Returns null if not found
const maybeMint = await fetchMaybeMint(rpc, mintAddress);
```
## Account Decoding
See [codecs.md](./codecs.md) for more information.
### With Codama Decoder
```ts
import { decodeMint } from '@solana-program/token';
const account = await fetchEncodedAccount(rpc, mintAddress);
assertAccountExists(account);
const mint = decodeMint(account);
```
### With Custom Codec
```ts
import { decodeAccount } from '@solana/kit';
import { getStructDecoder, getU64Decoder, fixDecoderSize, getBytesDecoder } from '@solana/kit';
const myDecoder = getStructDecoder([
['authority', fixDecoderSize(getBytesDecoder(), 32)],
['amount', getU64Decoder()],
]);
const decoded = decodeAccount(account, myDecoder);
```
## PDA Derivation
```ts
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
const [ata] = await findAssociatedTokenPda({
owner: walletAddress,
mint: mintAddress,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
});
```
### Custom PDA
```ts
import { getProgramDerivedAddress, getAddressEncoder } from '@solana/kit';
const [pda, bump] = await getProgramDerivedAddress({
programAddress: myProgramAddress,
seeds: [
getAddressEncoder().encode(userAddress),
new TextEncoder().encode('vault'),
],
});
```
## Account Subscriptions
```ts
const sub = await rpcSubs.accountNotifications(address, {
encoding: 'base64',
commitment: 'confirmed',
}).subscribe();
for await (const notif of sub) {
console.log('Account changed:', notif);
}
```
## Token Account Queries
```ts
// All token accounts for an owner
const { value: tokenAccs } = await rpc.getTokenAccountsByOwner(
ownerAddress,
{ programId: TOKEN_PROGRAM_ADDRESS },
{ encoding: 'jsonParsed' },
).send();
// Filter by mint
const { value: tokenAccs } = await rpc.getTokenAccountsByOwner(
ownerAddress,
{ mint: mintAddress },
{ encoding: 'jsonParsed' },
).send();
// Token balance
const { value: balance } = await rpc.getTokenAccountBalance(tokenAccountAddress).send();
// balance.amount (string), balance.decimals, balance.uiAmount
```
## Program Account Queries
```ts
const accounts = await rpc.getProgramAccounts(programAddress, {
encoding: 'base64',
filters: [
{ memcmp: { offset: 0, bytes: 'base58discriminator...' } },
{ dataSize: 165n },
],
}).send();
```
## Account Existence Pattern
Always check existence before decoding raw accounts:
```ts
import { fetchEncodedAccount, assertAccountExists, decodeAccount } from '@solana/kit';
async function getAccountData<T>(rpc, address, decoder): Promise<T> {
const account = await fetchEncodedAccount(rpc, address);
assertAccountExists(account);
return decodeAccount(account, decoder).data;
}
```
For Codama-generated clients, use `fetchMaybe*` variants to handle missing accounts gracefully.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |