Ephemeral accounts は Ephemeral Rollup 内にのみ存在するアカウントです。sponsor アカウント(ER に委任されている)が、32 lamports/byte で ephemeral accounts の rent を肩代わりします。これは Solana の基本 rent より約 109 倍安価です。 主な特性:Documentation Index
Fetch the complete documentation index at: https://docs.magicblock.gg/llms.txt
Use this file to discover all available pages before exploring further.
- 生成から終了まで完全に ER 内で完結する
- 呼び出し元プログラムが所有する(CPI コンテキストから推論)
- sponsor アカウントの lamports で賄われる
- 作成、リサイズ、クローズが可能
#[ephemeral_accounts] Macro
この proc-macro attribute は Anchor の Accounts struct に付けます。#[account(...)] 内の 2 つのカスタムマーカーを認識します。
| マーカー | 目的 |
|---|---|
sponsor | ephemeral accounts の rent を支払うアカウントを示す |
eph | アカウントを ephemeral(ER 専用)として示す |
検証ルール
ephフィールドが存在する場合、少なくとも 1 つのsponsorが必要- 各 struct で許可される
sponsorは 1 つだけ ephはinitまたはinit_if_neededと併用できない(代わりに生成されたメソッドを使用)- sponsor が PDA(
Signerではない)の場合、PDA 署名用のseedsが必要
生成されるメソッド
conversation という名前のフィールドに対して、macro は次を生成します。
| メソッド | シグネチャ | 説明 |
|---|---|---|
create_ephemeral_conversation | (data_len: u32) -> Result<()> | ephemeral account を作成する |
init_if_needed_ephemeral_conversation | (data_len: u32) -> Result<()> | data_len == 0 の場合のみ作成する |
resize_ephemeral_conversation | (new_data_len: u32) -> Result<()> | アカウントを拡張または縮小する |
close_ephemeral_conversation | () -> Result<()> | アカウントを閉じ、rent を sponsor に返す |
署名要件
- 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 を作成する
Ephemeral Account をリサイズする
Ephemeral Account を閉じる
Wallet を Sponsor として使う
PDA の代わりにSigner を sponsor として直接使うこともできます。
TypeScript クライアントでの使い方
ephemeral account のすべての操作は base layer ではなく ER connection に送られます。よくある落とし穴
eph fields must use AccountInfo, not Account
eph fields must use AccountInfo, not Account
eph fields must use AccountInfo<'info>, not Account<'info, T>. The account doesn’t exist yet at validation time, so Anchor cannot deserialize it.Manual serialization is required after create
Manual serialization is required after create
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.Cannot combine eph with init
Cannot combine eph with init
The macro enforces this at compile time. Use the generated
create_ephemeral_* method instead of Anchor’s init constraint.Sponsor must be delegated first
Sponsor must be delegated first
The sponsor account needs lamports on the ER to pay ephemeral rent. It must be delegated before creating ephemeral accounts.
Top up the sponsor before delegation
Top up the sponsor before delegation
Transfer extra SOL to the sponsor account before delegating it, so it has enough lamports to fund ephemeral accounts on the ER.
vault and magic_program are auto-injected
vault and magic_program are auto-injected
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

