---
id: HS0080
title: "PDA existence check"
url: https://carbium.sh/library/howsolana/pda-existence-check
collection: How to use Solana
category: Accounts and balances
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# PDA existence check

You get a three-way answer for any program derived address: absent, funded but never initialized, or initialized by its program. The script derives token addresses for wallets seen in the newest USDC transactions and checks many of them in one read.

## Deriving the address and bump

A program derived address comes from a program id and a list of seeds. The derivation hashes them together with a one-byte counter called the bump, starts the counter at 255 and counts down, and keeps the first result that falls off the ed25519 curve. No private key exists for such an address, which is why only the owning program can sign for it. The client and the program run the same function and land on the same address, so deriving takes no network call and tells you nothing about what lives there.

The script below derives associated token addresses, which are program derived addresses of the associated token account program with the wallet, the token program and the mint as seeds. [Associated token address lookup](https://carbium.sh/library/howsolana/associated-token-address-lookup) walks through those seeds. Any other address works the same way once you swap the program id and the seeds. In Rust the call is `Pubkey::find_program_address(&seeds, &program_id)`. In `@solana/kit` it is `getProgramDerivedAddress`. Both return the address and its bump.

## The three states and their tests

An address on Solana has three possible conditions, and a read tells them apart by the lamport balance, the owner and the data length. The call that reads many of them at once is `getMultipleAccounts`, which answers `null` for an address with no account and an object for the rest.

| State | What the read returns | Test |
|---|---|---|
| Absent | value is null | The slot in the result array is null |
| Funded, never initialized | lamports above 0, data empty, owner is the System program | Owner is 11111111111111111111111111111111 and data length is 0 |
| Initialized | owner is the program that made it, usually with data | Owner is any other program |

Lamports alone mislead. Anyone can transfer lamports to any address, including a program derived address that no program has created. That address then shows a positive balance, and a check that only looks at lamports calls it present. It still belongs to the System program and holds no data, so the owning program has never touched it.

The reverse holds as well. An account whose balance drops to zero is removed when the transaction ends, so a closed account and one that never existed both read as null. The check cannot separate those two, and [Closed account detection](https://carbium.sh/library/howsolana/closed-account-detection) covers the ways to tell them apart from history.

> A funded but uninitialized address blocks a plain `create_account`, which fails when the target already holds lamports. A program that must create its own address handles that case by transferring the missing rent, then calling `allocate` and `assign` in place of `create_account`.

## The same test inside a Rust program

On chain a program cannot call an RPC method. It sees only the accounts the transaction passed in, so the caller must include the address in the instruction's account list. The program then does two things. It derives the address again with `find_program_address` and compares it to the key it received, so a caller cannot pass in a different account. After that it inspects the account it was handed.

The test mirrors the table. An account that is uninitialized has `lamports()` equal to zero or an owner equal to `system_program::ID`, together with an empty `data` slice. An initialized one has its own program as owner and data of the length its layout needs. Anchor's `init` constraint and `Account` type run these checks for you, and a hand-written program adds them next to the seed check.

One more check belongs with those two. Owned by your program with data present still does not mean the data has the layout you expect, so read the discriminator or the first field before trusting the rest.

## The script

The script takes two mints, defaulting to USDC and USDT. It reads the five newest signatures that touch the first mint, fetches each transaction, and collects the wallets that hold that token after it. For each of up to eight wallets it derives the associated address under both mints, then reads all of them in one `getMultipleAccounts` call and prints the address, the bump and the state.

`main.ts` (run: `node main.ts`)

```ts
// HS0080 · PDA existence check
// https://carbium.sh/library/howsolana/pda-existence-check
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  getAddressEncoder,
  getProgramDerivedAddress,
  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 rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);

const ATA_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
const TOKEN_PROGRAM = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
const SYSTEM = "11111111111111111111111111111111";
const mintA = address(process.argv[2] ?? "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const mintB = address(process.argv[3] ?? "Es9vMFrzaCERmJfrF4H2FYD4KCoNyFvNQVdqSkrqzNnE");

type Acct = { lamports: bigint; owner: string; data: readonly [string, string] } | null;

function classify(a: Acct): string {
  if (!a) return "absent";
  const len = Buffer.from(a.data[0], "base64").length;
  if (a.owner === SYSTEM && len === 0) return `funded only, owned by System program (${a.lamports} lamports)`;
  return `initialized by ${a.owner}, ${len} data bytes`;
}

const enc = getAddressEncoder();
const derive = (wallet: Address, mint: Address) =>
  getProgramDerivedAddress({
    programAddress: ATA_PROGRAM,
    seeds: [enc.encode(wallet), enc.encode(TOKEN_PROGRAM), enc.encode(mint)],
  });

const owners = new Set<Address>();
const sigs = await rpc.getSignaturesForAddress(mintA, { limit: 5 }).send();
for (const { signature, err } of sigs) {
  if (err) continue;
  try {
    const tx = await rpc
      .getTransaction(signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1 })
      .send();
    for (const b of tx?.meta?.postTokenBalances ?? []) {
      if (b.mint === mintA && b.owner) owners.add(b.owner);
    }
  } catch (err) {
    console.error("skipped", signature, String(err));
  }
}
const wallets = [...owners].slice(0, 8);
if (wallets.length === 0) {
  console.error("No token owners found in the newest signatures; rerun in a moment.");
  process.exit(1);
}

const targets = [];
for (const wallet of wallets) {
  for (const mint of [mintA, mintB]) {
    const [addr, bump] = await derive(wallet, mint);
    targets.push({ wallet, mint, addr, bump });
  }
}

try {
  const res = await rpc
    .getMultipleAccounts(targets.map((t) => t.addr), { encoding: "base64" })
    .send();
  targets.forEach((t, i) => {
    console.log(`${t.wallet} mint ${t.mint.slice(0, 4)} ${t.addr} bump ${t.bump}: ${classify(res.value[i] ?? null)}`);
  });
} catch (err) {
  console.error("getMultipleAccounts failed:", String(err));
  process.exit(1);
}
```

Run it with `node main.ts`, optionally followed by two mint addresses. Node 24 strips the types on load, so nothing needs building. Both mints here belong to the legacy token program, so the script uses that program id as a seed. A Token-2022 mint needs its own program id in that slot.

Most USDC lines print as initialized and owned by the token program. A holder whose USDC sits outside its associated address, a pool vault say, prints absent there. The second mint is where the difference shows. Some wallets have a USDT account and print as initialized, and the rest print as absent. A line reading funded with the System program as owner is rare for associated token addresses, but it is the state a lamport check would have called present.

The read runs at confirmed commitment, which is what `@solana/kit` 8.6.0 applies when a call names none. The [getMultipleAccounts](https://carbium.sh/docs/rpc) call costs 10 cells per pubkey, so sixteen addresses cost 160 cells in one call.

## Where it ends

A read is a picture of one slot. With slots near 200 ms, the answer can be stale by the next one: another transaction can create the address, fund it or close it before yours lands. A client uses the result to decide whether to build a create instruction. The program must still run its own check inside the instruction, because that is the only place the answer cannot change underneath it.

One call carries at most 100 pubkeys on plans below Pro, where the 1024-cell burst caps it. Pro takes up to 300. The script sends 16, so a larger list needs chunks of 100. A full chunk of 100 costs 1000 cells, or 1001 once its request body passes 4 KiB, which 100 base58 pubkeys can do. A shorter last chunk costs 10 cells per pubkey.

The wallet discovery uses `getSignaturesForAddress`, which reaches back 30 days at most from its own address index. Its pages can list signatures older than the validator's ledger floor, so `getTransaction` may answer null for one of them, and the loop skips it. The transaction request asks for version 1 so a v1 transaction in the list is returned instead of refused.

The result says who owns the account and how many bytes it holds. It says nothing about when the account was made or who made it. To keep a record of addresses and the seeds behind them, see [SQLite PDA seed registry](https://carbium.sh/library/integrate/sqlite-pda-seed-registry).

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every address prints absent, including ones that should exist. | The seeds or their order differ from the program's. Check the order wallet, token program, mint, and that the program id is the associated token account program. A Token-2022 mint needs the Token-2022 program id as the second seed. |
| An address prints funded with the System program as owner and the create instruction fails. | Someone sent lamports to the address before it was created. Send the remaining rent, then allocate space and assign the owner, in place of calling create_account. |
| getMultipleAccounts is refused for a long list. | Send at most 100 pubkeys per call below Pro and split a longer list into chunks. |
| getTransaction answers -32015 while the script looks for wallets. | Pass maxSupportedTransactionVersion: 1 with the encoding. Mainnet carries v1 transactions, and a lower value is refused for them. |
| getTransaction returns null for a signature the list just gave you. | The list reaches below the validator's ledger floor, so an older signature can have no stored transaction. Skip it and move to a newer one. |
| The request answers 401 with UNKNOWN_KEY. | Send the whole key in the x-api-key header. A shortened or mistyped CARBIUM_KEY reads as an unknown key. |

## Questions

### Is a zero lamport balance enough to call an address absent?

Yes. The runtime removes an account that ends a transaction with no lamports, so a read of such an address returns null. The reverse is where lamports fail: a positive balance can sit on an address that was never initialized.

### Can I check a PDA from inside an on-chain program with an RPC call?

No. A program sees only the accounts passed in the instruction. The caller includes the address, and the program checks its lamports, data length and owner.

### Why print the bump?

The bump is part of the derivation and programs often store it in the account data. Printing it shows which counter value produced the address, and it is what a program passes to sign for the address.

### Should I use getAccountInfo for a single address?

Yes, it takes the same test. It costs 10 cells, like each pubkey in getMultipleAccounts, and the null, owner and data length checks work the same way.

## Related

- [Closed account detection](https://carbium.sh/library/howsolana/closed-account-detection) (How to use Solana, HS0038)
- [SQLite PDA seed registry](https://carbium.sh/library/integrate/sqlite-pda-seed-registry) (Integrations, I0023)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
