services
Get a key

library / AI and blockchain / Plain-English chain queries / SI0066

Stuck wallet diagnosis

You get a script that tests a wallet in a fixed order and prints one JSON verdict per check: owner, fee cover, rent floor, frozen token accounts and delegates. An assistant phrases those lines for a user, and a failed read says so.

By Carbium · Plain-English chain queries · SI0066 · updated 2026-11-22

01

The checks in test order

A wallet that cannot send SOL or swap has one of a few causes, and each leaves a trace that one read can show. Every check prints one JSON line with check, status and evidence. A read that failed prints read failed in the status slot, so a model phrasing the line has nothing to guess.

CheckReadsStatus
ownergetAccountInfoblocked when no account exists, a program other than the System Program owns it, or it holds data
feegetBalanceblocked under 5000 lamports, the base fee for one signature
rentgetBalance and getMinimumBalanceForRentExemption(0)ok at or above the floor, warn under it, blocked at 0 lamports
frozen-token-accountsgetTokenAccountsByOwner for the Token program and Token-2022warn when any token account is frozen
delegatesthe same two token readswarn when a delegate holds a nonzero allowance

The owner check runs first because a system transfer only moves lamports out of an account that the System Program owns and that holds no data. A wallet owned by another program cannot send through the System Program at all, whatever its balance. The fee check comes next, since every transaction pays its fee from the first signer before anything else runs. A priority fee or a second signature raises the figure, so the test treats 5000 as a floor and getFeeForMessage gives the real price.

$Frozen token accounts and delegates cannot stop a SOL send. They explain why one token will not move or why a token balance changed, so they print warn and never blocked. A plain SOL wallet has no freeze: only a mint's freeze authority freezes a token account, and it freezes that token account alone.
02

The rent rule

After a send, the sender must be in a state the runtime accepts. There are three. The account holds 0 lamports, which closes it. It holds at least the floor for its size, which for a wallet with no data is what getMinimumBalanceForRentExemption(0) returns. Or it was already under the floor, keeps its size and only lost lamports. Any other result fails with InsufficientFundsForRent.

  • A send that leaves 0 lamports works, because the account closes. The most a wallet can send this way is its balance minus the fee.
  • A send that leaves the floor or more works. The most it can send and stay open is its balance minus the floor minus the fee.
  • A send that leaves 1 lamport up to the floor minus 1 fails. An account at 0 lamports does not stay open, and one with a sliver of lamports is not allowed to start there.
  • A wallet already under the floor can always be emptied, and can send any smaller amount too, because its balance only falls.

This is the usual cause behind a wallet that holds SOL and still refuses to send. The user types an amount a little under the full balance, the remainder lands between 1 and the floor minus 1, and the transaction is refused. An ok rent line prints both limits, maxSendKeepingOpen and maxSendEmptying, so an assistant can name an amount that works; a wallet already under the floor prints a single maxSend instead. Amounts between the two limits are the ones that fail. Rent-exempt minimum calculator shows where the floor comes from.

03

The script

Pass a wallet address as the first argument, or pass none. With no argument the script reads the newest signature of the Compute Budget program, reads that transaction and takes its first account key, the fee payer, as the wallet. That lookup sits in a try, so a failure there prints its message and exits before any check runs.

main.ts
// SI0066 · Stuck wallet diagnosis// https://carbium.sh/library/si/stuck-wallet-diagnosis// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Stuck wallet diagnosis. Run: CARBIUM_KEY=... node main.ts [wallet address]import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Address } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const SYSTEM = "11111111111111111111111111111111";const FEE = 5000n; // base fee for one signatureconst TOKEN_PROGRAMS = [  address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),  address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"),];type Info = { mint: string; state: string; delegate?: string; delegatedAmount?: { amount: string } };const say = (check: string, status: string, evidence: unknown) =>  console.log(JSON.stringify({ check, status, evidence }, (_, v) => (typeof v === "bigint" ? v.toString() : v)));const why = (r: PromiseSettledResult<unknown>) => (r.status === "rejected" ? String(r.reason?.message ?? r.reason) : "");const pos = (n: bigint) => (n > 0n ? n : 0n);// No argument: the fee payer of the Compute Budget program's newest transaction.async function pickWallet(): Promise<Address> {  const [sig] = await rpc.getSignaturesForAddress(address("ComputeBudget111111111111111111111111111111"), { limit: 1 }).send();  const tx = await rpc.getTransaction(sig.signature, { maxSupportedTransactionVersion: 1, encoding: "json" }).send();  if (!tx) throw new Error("newest transaction not readable");  return address(tx.transaction.message.accountKeys[0]);}let wallet: Address;try { wallet = process.argv[2] ? address(process.argv[2]) : await pickWallet(); }catch (e) { console.error(`no wallet to check: ${(e as Error).message}`); process.exit(1); }console.log(`wallet ${wallet}`);const [[acct, bal, floor], tokens] = await Promise.all([  Promise.allSettled([    rpc.getAccountInfo(wallet, { encoding: "base64", dataSlice: { offset: 0, length: 0 } }).send(),    rpc.getBalance(wallet).send(),    rpc.getMinimumBalanceForRentExemption(0n).send(),  ]),  Promise.allSettled(TOKEN_PROGRAMS.map((programId) =>    rpc.getTokenAccountsByOwner(wallet, { programId }, { encoding: "jsonParsed" }).send())),]);if (acct.status === "rejected") say("owner", "read failed", why(acct));else if (!acct.value.value) say("owner", "blocked", "no account on chain");else {  const a = acct.value.value;  say("owner", a.owner === SYSTEM && a.space === 0n ? "ok" : "blocked", { owner: a.owner, dataBytes: a.space, executable: a.executable });}if (bal.status === "rejected") say("fee", "read failed", why(bal));else say("fee", bal.value.value >= FEE ? "ok" : "blocked", { balance: bal.value.value, baseFee: FEE });if (bal.status === "rejected" || floor.status === "rejected") say("rent", "read failed", [bal, floor].map(why).filter(Boolean));else {  const b = bal.value.value, f = floor.value;  if (b === 0n) say("rent", "blocked", { balance: b, floor: f });  else if (b >= f) say("rent", "ok", { balance: b, floor: f, maxSendKeepingOpen: pos(b - f - FEE), maxSendEmptying: pos(b - FEE) });  else say("rent", "warn", { balance: b, floor: f, underFloor: true, maxSend: pos(b - FEE) });}const unread = tokens.filter((r) => r.status === "rejected").map(why);const infos = tokens.flatMap((r) => (r.status === "fulfilled"  ? r.value.value.map((a) => ({ pubkey: a.pubkey, ...(a.account.data as unknown as { parsed: { info: Info } }).parsed.info }))  : []));const frozen = infos.filter((i) => i.state === "frozen");const delegated = infos.filter((i) => i.delegate && i.delegatedAmount?.amount !== "0");const verdict = (hits: number) => (hits ? "warn" : unread.length ? "read failed" : "ok");say("frozen-token-accounts", verdict(frozen.length), { tokenAccounts: infos.length, frozen: frozen.slice(0, 5).map(({ pubkey, mint }) => ({ pubkey, mint })), unread });say("delegates", verdict(delegated.length), { delegated: delegated.slice(0, 5).map((i) => ({ mint: i.mint, delegate: i.delegate, allowance: i.delegatedAmount?.amount })), unread });

run: node main.ts

The five reads go out together under Promise.allSettled, and each check looks only at the results it needs. A rent line needs both of its reads, and prints read failed with the messages when either is missing. The token checks print read failed when no frozen account or delegate turned up and one of the two token programs did not answer, because an empty result from a failed read proves nothing. Lamports print as strings, so a model never meets a float.

Every call leaves commitment out, so @solana/kit fills in confirmed; the JSON-RPC server alone would use finalized. The finder reads its transaction with maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and a read without it answers -32015 for one of them.

With an address given, the owner read is one getAccountInfo at 10 cells. The finder adds one getSignaturesForAddress and one getTransaction at 50 cells each. The token reads are the call from Token accounts by owner, run once per token program.

04

Turning verdicts into sentences

Hand the lines to the model verbatim as a tool result and tell it in the system prompt to answer from status and evidence only. The first blocked line in test order is the answer. When none is blocked, the reply says every check passed and the cause sits in the send itself, so the user should copy the error the wallet app shows.

StatusWhat the assistant may say
okThe check passes, with the evidence figure beside it.
blockedThe check is the cause, with the figure that failed it.
warnA finding that leaves SOL sends alone: a wallet under the rent floor with its maxSend, a frozen token account with its pubkey and mint, or a delegate with its mint and allowance.
read failedThe check could not run, with the message. No figure from memory.

Convert lamports to SOL by dividing by 1,000,000,000 when speaking, and keep the lamport figure beside it. A reply for the rent line reads like this: the wallet holds the floor plus a little, a send of that little works, a send of nearly everything fails, and emptying it works. The numbers come from maxSendKeepingOpen and maxSendEmptying in the line, never from the model's arithmetic.

05

Where it ends

  • The reads happen at one moment. Run the script again after any fix, since a balance can change between two runs.
  • The script cannot prove a compromise. It shows a low balance and any delegates; who moved the funds needs the wallet's transaction history. Token delegate exposure scan goes further on the delegate side.
  • The fee check uses the base fee for one signature. A priority fee or more signers raise it, and getFeeForMessage prices a real message.
  • A swap needs more than the wallet's own floor, because a token the wallet has never held needs a new token account with its own rent. The script does not price that.
  • Token-2022 extensions can stop a transfer with no frozen state, and the script reads state and delegate only.
  • A wallet with thousands of token accounts makes the two token reads large and slow.
  • The script reads the chain. A wallet app bug or a wrong network setting leaves every check ok.
06

When it goes wrong

what goes wrongwhat to do
Every line prints read failed with a 401.The key is unknown at the door. Attach the whole key in the x-api-key header.
Some checks print read failed with a 429 while others print.The five reads went out together and passed the rate. Wait for the retry-after hint and run the script again before the assistant answers.
The finder exits with no wallet to check.The newest signature came back empty or its transaction was null. Run again, or pass the wallet address as the first argument.
The rent line says read failed while the fee line prints.One of the rent line's two reads failed. Rerun, and never let the assistant quote an older balance in its place.
Every check is ok and the send still fails.The cause is in the send. Read the error code from the failed transaction, and check the amount against maxSendKeepingOpen and maxSendEmptying from the rent line.
The finder answers -32015.The read left out maxSupportedTransactionVersion or set it to 0, and the transaction is v1. Pass 1.
07

Questions

Can a Solana wallet be frozen?

A plain SOL wallet cannot. Only a token account can freeze, and only the mint's freeze authority does it, which stops that one token and leaves SOL alone. The frozen-token-accounts check lists them.

Why does sending almost all my SOL fail?

The remainder after the send and the fee must be 0 or at least the rent floor. A remainder between those fails. Send the balance minus the fee to empty the wallet, or leave at least the floor.

Does a delegate mean my wallet is compromised?

No. A delegate can move one token account's tokens up to its allowance, and swap venues and apps set them up on purpose. Check who the delegate is and how much it may move, and revoke any you do not recognise.

Why can I send SOL but not swap?

A swap into a token the wallet has never held needs a new token account, and that account takes its own rent from the SOL balance, so a wallet near the floor can send SOL and still fail the swap. A frozen token account stops that one token while SOL sends go through. The frozen-token-accounts check lists any frozen account.