Skip to main content
Ephemeral accounts は Ephemeral Rollup 内にのみ存在するアカウントです。sponsor アカウント(ER に委任されている)が、32 lamports/byte で ephemeral accounts の rent を肩代わりします。これは Solana の基本 rent より約 109 倍安価です。 主な特性:
  • 生成から終了まで完全に ER 内で完結する
  • 呼び出し元プログラムが所有する(CPI コンテキストから推論)
  • sponsor アカウントの lamports で賄われる
  • 作成、リサイズ、クローズが可能

#[ephemeral_accounts] Macro

この proc-macro attribute は Anchor の Accounts struct に付けます。#[account(...)] 内の 2 つのカスタムマーカーを認識します。

検証ルール

  • eph フィールドが存在する場合、少なくとも 1 つの sponsor が必要
  • 各 struct で許可される sponsor1 つだけ
  • ephinit または init_if_needed と併用できない(代わりに生成されたメソッドを使用)
  • sponsor が PDA(Signer ではない)の場合、PDA 署名用の seeds が必要

生成されるメソッド

conversation という名前のフィールドに対して、macro は次を生成します。

署名要件

  • Sponsor: すべての操作(create、resize、close)で signer である必要がある
  • Ephemeral: create 時のみ signer が必要(pubkey squatting を防ぐ)。resize や close では不要。
  • PDA アカウントの場合、macro は find_program_address を使って signer seeds を自動導出する

Rent モデル

  • 拡張時: sponsor が追加 rent を vault に支払う
  • 縮小時: vault が余剰 rent を sponsor に返す
  • Close: すべての rent が vault から sponsor に返される

Ephemeral Account を作成する

create_ephemeral_* を呼んだ後は、データ struct を raw account data に手動でシリアライズする必要があります。macro は領域を確保するだけで、データの初期化までは行いません。

Ephemeral Account をリサイズする


Ephemeral Account を閉じる


Wallet を Sponsor として使う

PDA の代わりに Signer を sponsor として直接使うこともできます。

TypeScript クライアントでの使い方

ephemeral account のすべての操作は base layer ではなく ER connection に送られます。

よくある落とし穴

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