Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

EIP-7702

Stable 支持 EIP-7702,它允许 EOA 将其账户代码设置为现有的智能合约。EOA 在执行委托者的逻辑时保留其原始地址和私钥。

交易格式

EIP-7702 使用交易类型 0x04 和一个 authorizationList 字段。每个授权都指定了一个委托合约,EOA 在该交易中执行其代码。

{
  type: 4,
  to: eoa.address,
  data: delegateCallData,
  authorizationList: [signedAuthorization],
  maxPriorityFeePerGas: 0n, // always 0 on Stable
  // ... standard EIP-1559 fields
}

授权包含:

  • chainId:必须与目标链匹配。
  • address:委托合约地址。
  • nonce:授权账户的 nonce。如果该账户也发送交易,请使用其当前 nonce 加一,因为交易在处理授权之前会增加 nonce。

支持 EIP-7702 的钱包和库会自动处理授权格式。

工具

  • ethers.js (v6.14+):wallet.authorize({ chainId, address, nonce }) 生成用于包含在 authorizationList 中的签名授权。
  • viem:使用 signAuthorization 和一个 walletClient,然后将结果传递给 sendTransaction。当同一账户发送交易时,传递 executor: "self",viem 会为您设置 nonce。
  • Alchemy 钱包 API:委托给经过审计的智能账户并管理会话密钥,而无需自行构建授权。请参阅 使用 EIP-7702 的会话密钥。
  • Hardhat / Foundry:当您的工具链版本支持 Pectra 硬分叉时,标准的 EIP-7702 交易格式即可使用。

接下来推荐