Skip to main content
Ephemeral accounts are accounts that exist only within the Ephemeral Rollup. A sponsor account (which is delegated to the ER) pays rent on behalf of ephemeral accounts at 32 lamports/byte — 109x cheaper than Solana’s base rent. Key properties:
  • Born, live, and die entirely on the ER
  • Owned by the calling program (inferred from CPI context)
  • Funded by a sponsor account’s lamports
  • Can be created, resized, and closed

The #[ephemeral_accounts] Macro

This proc-macro attribute goes on an Anchor Accounts struct. It recognizes two custom markers inside #[account(...)]:

Validation Rules

  • At least one sponsor is required if any eph fields exist
  • Only one sponsor is allowed per struct
  • eph cannot be combined with init or init_if_needed (use the generated methods instead)
  • If the sponsor is a PDA (not a Signer), it must have seeds for PDA signing

Generated Methods

For a field named conversation, the macro generates:

Signing Requirements

  • Sponsor: Must be a signer for all operations (create, resize, close)
  • Ephemeral: Must be a signer only on create (prevents pubkey squatting). Not required for resize or close.
  • For PDA accounts, the macro auto-derives signer seeds via find_program_address

Rent Model

  • Growing: sponsor pays additional rent to vault
  • Shrinking: vault refunds excess rent to sponsor
  • Close: all rent refunded from vault to sponsor

Create an Ephemeral Account

After calling create_ephemeral_*, you must manually serialize your data struct into the raw account data. The macro allocates space but does not initialize the data.

Resize an Ephemeral Account


Close an Ephemeral Account


Using a Wallet as Sponsor

A Signer can be used directly as the sponsor instead of a PDA:

TypeScript Client Usage

All ephemeral account operations are sent to the ER connection, not the base layer:

Common Gotchas

eph fields must use AccountInfo<'info>, not Account<'info, T>. The account doesn’t exist yet at validation time, so Anchor cannot deserialize it.
After calling create_ephemeral_*, you must serialize your data struct into the raw account data yourself. The macro allocates space but does not write any data.
The macro enforces this at compile time. Use the generated create_ephemeral_* method instead of Anchor’s init constraint.
Transfer extra SOL to the sponsor account before delegating it, so it has enough lamports to fund ephemeral accounts on the ER.
You don’t need to declare them in your struct, but they appear in the IDL and must be passed from the client. Anchor resolves them automatically if named correctly.

Learn More

Ephemeral Accounts Demo

Full example program on GitHub

Delegation & Undelegation

How delegation and state synchronization work

Quickstart

Build your first program with Ephemeral Rollups