library / How to use Solana / Build, sign and send transactions / HS0143
Fee payer eligibility check
One read-only TypeScript file reads the fee payer account and reports whether its owner and data allow it to pay fees. It finds a candidate from a busy program when you pass no address, and sends nothing.
Why the runtime refuses a payer
Every transaction names a fee payer as its first signer. Before it runs any instruction, the runtime loads that account and checks it. The account must be owned by the System Program and hold no data. A plain wallet meets both conditions, which is why a wallet can pay fees for any program. The error This account may not be used to pay transaction fees means the account failed that check when the transaction ran.
Calling instructions one after another is where this usually shows up. An earlier call can change the state of the account that pays later. The System Program's assign instruction moves an account to another owner, and allocate gives it data. Either can happen inside a program you call, not only in your own code. The next call still names the same address as fee payer, and the runtime refuses it.
The fix is to choose a fee payer that is still a plain wallet at the moment the transaction runs. The check in this file reads the account and reports its owner and data length separately, so you can see which test failed and which program holds the account.
The code
Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24. Pass a fee payer address as the argument to check one account. With no argument, the file reads the newest signatures of the token program, takes the first account key of up to three successful transactions, and checks each of those payers.
The first account key is the fee payer, because the runtime reads it in that position. getSignaturesForAddress returns the newest signatures first, and the file skips any signature that carries an error. getTransaction runs with maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and an absent or 0 value answers -32015 for them. A null answer is skipped, since the signature index can list an older signature that the ledger no longer holds.
// HS0143 · Fee payer eligibility check// https://carbium.sh/library/howsolana/fee-payer-eligibility-check// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport,} 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_PROGRAM = "11111111111111111111111111111111";const TOKEN_PROGRAM = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");type TxLike = { transaction: { message: { accountKeys: string[] } } } | null;// The first static account key of a transaction is its fee payer.async function newestPayers(count: number): Promise<string[]> { const sigs = await rpc .getSignaturesForAddress(TOKEN_PROGRAM, { limit: 10, commitment: "confirmed" }) .send(); const payers: string[] = []; for (const s of sigs) { if (s.err !== null) continue; let tx: TxLike; try { tx = (await rpc .getTransaction(s.signature, { encoding: "json", maxSupportedTransactionVersion: 1, commitment: "confirmed", }) .send()) as unknown as TxLike; } catch { continue; } if (tx) payers.push(tx.transaction.message.accountKeys[0]); if (payers.length === count) break; } return payers;}async function check(who: string): Promise<void> { const { value } = await rpc .getAccountInfo(address(who), { encoding: "base64", commitment: "confirmed" }) .send(); if (!value) { console.log(`${who}: no account at this address, so it cannot pay fees`); return; } const [b64] = value.data as unknown as [string, string]; const dataBytes = Buffer.from(b64, "base64").length; const owner = String(value.owner); const eligible = owner === SYSTEM_PROGRAM && dataBytes === 0; console.log( `${who}: owner=${owner} dataBytes=${dataBytes} lamports=${value.lamports} eligible=${eligible}`, ); if (!eligible) { console.log(" refused as fee payer: it must be owned by the System Program and hold no data"); }}const arg = process.argv[2];const payers = arg ? [arg] : await newestPayers(3).catch((e: Error) => { console.error(`candidate search failed: ${e.message}`); return [] as string[]; });if (payers.length === 0) { console.error("No fee payer candidates in the newest signatures."); process.exit(1);}for (const p of payers) { try { await check(p); } catch (e) { console.log(`${p}: read failed: ${(e as Error).message}`); }}
run: node main.ts [fee-payer-address]
The check itself is one getAccountInfo call per payer, in base64 so the data length comes out in bytes. The file never builds, signs or sends anything. A missing account gets a line of its own, because a payer that does not exist cannot pay either. Each payer runs in its own try, so one failed read does not hide the others.
Reading the output
| Field | Meaning |
|---|---|
| owner | The program that owns the account. A plain wallet shows the System Program address, 11111111111111111111111111111111. |
| dataBytes | The length of the account data in bytes. A plain wallet holds 0. |
| lamports | The balance in lamports, where 1 SOL is 1,000,000,000. |
| eligible | true when both tests pass at confirmed commitment. |
When eligible prints false, the owner line names the program that holds the account, and the next line says which test failed. A zero balance does not affect the eligibility test, but a payer with too few lamports fails the transaction at the fee step instead.
On Carbium
Each payer costs one getAccountInfo call at 10 cells. Account reads run at 0.5 per second on Free, 15 on Dev, 50 on Business and 400 on Pro. The candidate search adds one getSignaturesForAddress at 50 cells and up to three getTransaction calls at 50 cells each. A run with no argument therefore costs about 210 cells, and a run with one address costs 10.
Signatures come from an address index that keeps up to 30 days, so the search only sees recent activity. A call over its rate waits once, and past that it gets a 429 with a retry-after hint. The file prints the payer that failed and moves on, so a rerun after the hint is the fix.
Where it ends
A passing check is not a dry run. It reads one account at confirmed commitment and nothing else. The transaction you send can still fail on its own instructions, on the fee balance, or on a payer that an earlier instruction in the same transaction changes. Simulating the exact transaction is the test for those.
The file cannot tell which instruction changed the account. It shows the state now. To find the step, read the payer before and after each call in your own sequence, and keep the reads at the same commitment.
The candidate search reaches back 30 days at most. An address that changed its owner months ago will not appear as a candidate, so pass that address as the argument instead. Older signatures can also return null from getTransaction, and the file skips them without an error.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Error: This account may not be used to pay transaction fees, on a payer the check reports as eligible. | Read the payer again after each earlier step. The owner or data may have changed in a call you did not write. Simulate the exact transaction to see which step changes it. |
| eligible=false with an owner that is a program address. | That program owns the account. Pick a fee payer that is a plain wallet keypair, and keep program-owned accounts out of the fee payer position. |
| eligible=false with dataBytes above zero and the System Program as owner. | The account holds data, usually after an allocate or a program write. Use a payer with no data. A nonce account is the exception, and this file does not test for it. |
| Error -32015 from getTransaction during the candidate search. | Set maxSupportedTransactionVersion to 1 in the call, as the file does. An absent or 0 value answers -32015 for a v1 transaction. |
| HTTP 429 with a retry-after hint. | The file prints the payer that failed and moves on. Wait the number of seconds in the hint and run it again. |
Questions
Why can an address that paid fees earlier fail after one instruction?
The instruction changed its owner or its data. The System Program's assign and allocate instructions do this, and a program the sequence calls can do it too. Read the account again after each step to find the change.
Does a passing check mean my transaction will succeed?
No. It proves only the payer's owner and data length at confirmed commitment. Simulate the transaction you send to check the rest.
Which commitment does the file use?
It passes confirmed to every call. The client in @solana/kit 8.6.0 also defaults to confirmed when a call leaves commitment out, so the choice is explicit either way.
Can I check a wallet from a month ago?
Only through getTransaction on a signature you already hold. The candidate search reaches back 30 days at most, and older signatures can return null.