Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Proposal: Account Codec Program

Given that it is kind of tricky to know how to read data from accounts, it would be really useful to have an "Account Codec Program" as a central repository of Program Accounts type schemas.

I'm thinking with this program you could register Program Account schemas to know what format to use to Decode them. As an analogy, its like storing the Anchor's IDL on chain, or also akin to how the Metaplex Metadata Token program is the standard where you define metadata for an NFT Mint


Some program's account:

struct Person {
  name: [u8; 100],
  age: u8,

struct Pet {
  legs: u8,
  owner: Pubkey

The owner of the private key of that program address could

  1. Register a list of Account names

PDA seed = ["SomeProgramPubkey987654321", "AccountCodecProgramPubkey1234567890"]

Encoded data:

  1. The owner of the private key of that program address could register multiple associated PDAs for each account using the Codec program

PDA seed = ["Person", "SomeProgramPubkey987654321", "AccountCodecProgramPubkey1234567890"]

Encoded data:

    Field {name: "name", type: "[u8; 100]"},
    Field {name: "age", type: "u8"},

PDA seed = ["Animal", "SomeProgramPubkey987654321", "AccountCodecProgramPubkey1234567890"]

Encoded data:

    Field {name: "legs", type: "u8"},
    Field {name: "owner", type: "u32"},

Additional thoughts

  • The encoded data would have to support nested data structures
  • Perhaps account codecs could be registered by the community, instead of just allowing program signers to be able to do so, to increase its usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment