ERC-7769 · Draft(草案) · ERC · 2024-08-23
ERC-7769: JSON-RPC API for ERC-4337
ウォレットが ERC-4337 の Bundler と通信するための JSON-RPC メソッド(UserOperation の送信、見積もり、検索)と、Bundler をテストするためのデバッグメソッドを標準化する。
何を解決するのか
ERC-4337 のアカウント抽象化では、ユーザーは通常のトランザクションを送りません。UserOperation オブジェクトに署名し、それが Bundler の運用する別の mempool に送られ、Bundler が多数をまとめて EntryPoint コントラクトへの 1 回の handleOps 呼び出しにします。eth_sendRawTransaction や eth_estimateGas のような標準メソッドは、この流れには合いません。
ERC-7769 は、すべての Bundler が公開すべき RPC の範囲を定義します。これにより、ウォレットや SDK はコードを変えずに Bundler プロバイダーを切り替えられます。
仕組み
eth 名前空間(公開):
| メソッド | 役割 |
|---|---|
eth_sendUserOperation |
UserOperation を検証・シミュレーションして mempool に追加し、userOpHash を返す |
eth_estimateUserOperationGas |
preVerificationGas、verificationGasLimit、callGasLimit(および Paymaster の検証ガス)を返す。署名はスタブでもよく、state override セットを受け付ける |
eth_getUserOperationByHash |
UserOperation と、blockNumber、transactionHash などを返す |
eth_getUserOperationReceipt |
success、actualGasCost、actualGasUsed、この op 自身のログ、バンドルのトランザクションレシートを返す |
eth_supportedEntryPoints |
Bundler が受け付ける EntryPoint のアドレス(優先するものが先頭) |
eth_chainId |
EIP-155 のチェーン ID |
エラーには専用のコードが使われます。たとえば -32602 はフィールドが無効、-32500 は EntryPoint の検証による拒否(メッセージに AAxx コードが含まれる)、-32501 は Paymaster による拒否、-32502 は ERC-7562 の opcode ルール違反、-32503 は時間範囲外、-32507 は署名不正です。
EIP-7702 があるチェーンでは、UserOperation に eip7702Auth タプルを含められます。factory にマーカー 0x7702 を設定すると、送信元が 7702 で委任された EOA であることを EntryPoint に伝え、その場合 factoryData は初期化のために送信元に渡されます。
debug 名前空間(テスト専用): debug_bundler_clearState、dumpMempool、sendBundleNow、setBundlingMode、setReputation、dumpReputation、addUserOps。これらは、共通の互換性テストスイートがどの Bundler も操作できるようにするために存在します。
サンプルコード
UserOperation を送信し、レシートをポーリングする(TypeScript、素の fetch):
async function rpc(method: string, params: unknown[]) {
const res = await fetch(BUNDLER_URL, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
});
const json = await res.json();
if (json.error) throw new Error(`${json.error.code}: ${json.error.message}`);
return json.result;
}
const [entryPoint] = await rpc("eth_supportedEntryPoints", []);
const gas = await rpc("eth_estimateUserOperationGas", [userOp, entryPoint]);
Object.assign(userOp, gas);
userOp.signature = await signUserOp(userOp, entryPoint); // wallet-specific
const userOpHash = await rpc("eth_sendUserOperation", [userOp, entryPoint]);
let receipt = null;
while (!receipt) {
await new Promise((r) => setTimeout(r, 2000));
receipt = await rpc("eth_getUserOperationReceipt", [userOpHash]);
}
console.log(receipt.success, receipt.actualGasCost);
知っておくべきこと
- ステータス: Draft。 フィールド名やエラーコードはまだ変わる可能性があります。
- 数値フィールドはすべて 16 進数の文字列で、空のバイト列は
"0x"でなければなりません。 eth_getUserOperationReceiptのreceiptはバンドル全体を対象としています。自分の operation のログにはトップレベルのlogsを使ってください。- Paymaster の
postOpGasLimitは確実に見積もることができません。Paymaster 側が指定すべきです。 debug_*メソッドを本番のエンドポイントで公開してはいけません。