Inventory Solana program accounts before a layout migration

Suppose a program has a 96-byte record with an eight-byte type tag. A filtered account scan can identify migration candidates without downloading each full buffer.

Filter by size and read the prefix

Replace the program key and adapt the size and slice to your deployed schema. The filter is evaluated on the full account. The slice controls the bytes delivered to the client, so dataSize remains 96 even though only eight bytes are requested.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getProgramAccounts",
  "params": [
    "PROGRAM_PUBLIC_KEY",
    {
      "encoding": "base64",
      "commitment": "finalized",
      "withContext": true,
      "filters": [
        {
          "dataSize": 96
        }
      ],
      "dataSlice": {
        "offset": 0,
        "length": 8
      }
    }
  ]
}

Separate candidate records from confirmed matches

Decode each returned prefix from base64 and compare all eight bytes to your known type tag. If 900 accounts have the expected size but only 840 carry the tag, queue those 840 and inspect the other 60 separately. Different types can occupy the same number of bytes.

Save the context slot with the list. Before modifying any account later, reread its current layout because the program could have changed it since the inventory.

Documentation