Quick Reference
This skill file provides quick access to the MetaMask Smart Accounts Kit v0.3.0. For detailed information, refer to the specific reference files.
📚 Detailed References:
Package Installation
CODEBLOCK0
For custom caveat enforcers:
CODEBLOCK1
Core Concepts Summary
1. Smart Accounts (ERC-4337)
Three implementation types:
- - Hybrid (
Implementation.Hybrid) - EOA + passkey signers - Multisig (
Implementation.MultiSig) - Multiple signers with threshold - Stateless7702 (
Implementation.Stateless7702) - EIP-7702 upgraded EOA
2. Delegation Framework (ERC-7710)
Grant permissions from delegator to delegate:
- - Scopes - Initial authority (spending limits, function calls)
- Caveats - Restrictions enforced by smart contracts
- Types - Root, open root, redelegation, open redelegation
- Lifecycle - Create → Sign → Store → Redeem
3. Advanced Permissions (ERC-7715)
Request permissions via MetaMask extension:
- - Human-readable UI confirmations
- ERC-20 and native token permissions
- Requires MetaMask Flask 13.5.0+
- User must have smart account
Quick Code Examples
Create Smart Account
CODEBLOCK2
Create Delegation
CODEBLOCK3
Sign Delegation
CODEBLOCK4
Redeem Delegation
CODEBLOCK5
Request Advanced Permissions
CODEBLOCK6
Redeem Advanced Permissions
CODEBLOCK7
Key API Methods
Smart Accounts
- -
toMetaMaskSmartAccount() - Create smart account - INLINECODE4 - Combine multisig signatures
- INLINECODE5 - Sign delegation
- INLINECODE6 - Sign user operation
- INLINECODE7 /
signTypedData() - Standard signing
Delegations
- -
createDelegation() - Create delegation with delegate - INLINECODE10 - Create open delegation
- INLINECODE11 - Build caveats array
- INLINECODE12 - Create execution struct
- INLINECODE13 - Encode redemption calldata
- INLINECODE14 - Sign with private key
- INLINECODE15 - Resolve environment
- INLINECODE16 - Deploy contracts
- INLINECODE17 - Override environment
Advanced Permissions
- -
erc7715ProviderActions() - Wallet client extension for requesting - INLINECODE19 - Request permissions
- INLINECODE20 - Bundler client extension
- INLINECODE21 - Redeem with smart account
- INLINECODE22 - Wallet client extension
- INLINECODE23 - Redeem with EOA
Supported ERC-7715 Permission Types
ERC-20 Token Permissions
| Permission Type | Description |
|---|
| INLINECODE24 | Per-period limit that resets at each period |
| INLINECODE25 |
Linear streaming with amountPerSecond rate |
Native Token Permissions
| Permission Type | Description |
|---|
| INLINECODE26 | Per-period ETH limit that resets |
| INLINECODE27 |
Linear ETH streaming with amountPerSecond rate |
Common Delegation Scopes
Spending Limits
| Scope | Description |
|---|
| INLINECODE28 | Fixed ERC-20 limit |
| INLINECODE29 |
Per-period ERC-20 limit |
|
erc20Streaming | Linear streaming ERC-20 |
|
nativeTokenTransferAmount | Fixed native token limit |
|
nativeTokenPeriodTransfer | Per-period native token limit |
|
nativeTokenStreaming | Linear streaming native |
|
erc721Transfer | ERC-721 (NFT) transfer |
Function Calls
| Scope | Description |
|---|
| INLINECODE35 | Specific methods/addresses allowed |
| INLINECODE36 |
Ownership transfers only |
Common Caveat Enforcers
Target & Method
- -
allowedTargets - Limit callable addresses - INLINECODE38 - Limit callable methods
- INLINECODE39 - Validate specific calldata
- INLINECODE40 /
exactCalldataBatch - Exact calldata match - INLINECODE42 /
exactExecutionBatch - Exact execution match
Value & Token
- -
valueLte - Limit native token value - INLINECODE45 - Limit ERC-20 amount
- INLINECODE46 - Validate ERC-20 balance change
- INLINECODE47 /
erc721BalanceChange - ERC-721 restrictions - INLINECODE49 - ERC-1155 validation
Time & Frequency
- -
timestamp - Valid time range (seconds) - INLINECODE51 - Valid block range
- INLINECODE52 - Limit redemption count
- INLINECODE53 /
erc20Streaming - Time-based ERC-20 - INLINECODE55 /
nativeTokenStreaming - Time-based native
Security & State
- -
redeemer - Limit redemption to specific addresses - INLINECODE58 - One-time delegation with ID
- INLINECODE59 - Bulk revocation via nonce
- INLINECODE60 - Auto-deploy contract
- INLINECODE61 - Ownership transfer only
- INLINECODE62 - Require payment
- INLINECODE63 - Validate native balance
- INLINECODE64 - Multi-token period limits
Execution Modes
| Mode | Chains | Processing | On Failure |
|---|
| INLINECODE65 | One | Sequential | Revert |
| INLINECODE66 |
One | Sequential | Continue |
|
BatchDefault | Multiple | Interleaved | Revert |
|
BatchTry | Multiple | Interleaved | Continue |
Contract Addresses (v1.3.0)
Core
| Contract | Address |
|---|
| EntryPoint | INLINECODE69 |
| SimpleFactory |
0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c |
| DelegationManager |
0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3 |
| MultiSigDeleGatorImpl |
0x56a9EdB16a0105eb5a4C54f4C062e2868844f3A7 |
| HybridDeleGatorImpl |
0x48dBe696A4D990079e039489bA2053B36E8FFEC4 |
Critical Rules
Always Required
- 1. Always use caveats - Never create unrestricted delegations
- Deploy delegator first - Account must be deployed before redeeming
- Check smart account status - ERC-7715 requires user has smart account
Behavior
- 4. Caveats are cumulative - In delegation chains, restrictions stack
- Function call default - v0.3.0 defaults to NO native token (use
valueLte) - Batch mode caveat - No compatible caveat enforcers available
Requirements
- 7. ERC-7715 requirements - MetaMask Flask 13.5.0+, smart account
- Multisig threshold - Need at least threshold signers
- 7702 upgrade - Stateless7702 requires EIP-7702 upgrade first
Common Patterns
Pattern 1: ERC-20 with Time Limit
CODEBLOCK8
Pattern 2: Function Call with Value
CODEBLOCK9
Pattern 3: Periodic Native Token
CODEBLOCK10
Pattern 4: Redelegation Chain
CODEBLOCK11
Troubleshooting Quick Fixes
| Issue | Solution |
|---|
| Account not deployed | Use bundlerClient.sendUserOperation() to deploy |
| Invalid signature |
Verify chain ID, delegation manager, signer permissions |
| Caveat enforcer reverted | Check caveat parameters match execution, verify order |
| Redemption failed | Check delegator balance, calldata validity, target contracts |
| ERC-7715 not working | Upgrade to Flask 13.5.0+, ensure user has smart account |
| Permission denied | Handle gracefully, provide manual fallback |
| Threshold not met | Add more signers for multisig |
| 7702 not working | Confirm EOA upgraded via EIP-7702 first |
Resources
- - NPM: INLINECODE76
- Contracts: INLINECODE77
- ERC Standards: ERC-4337, ERC-7710, ERC-7715, ERC-7579
- MetaMask Flask: https://metamask.io/flask
Version Info
- - Toolkit: 0.3.0
- Delegation Framework: 1.3.0
- Breaking Change: Function call scope defaults to no native token transfer
For detailed documentation, see the reference files in the /references directory.
快速参考
本技能文件提供对 MetaMask 智能账户工具包 v0.3.0 的快速访问。有关详细信息,请参阅特定的参考文件。
📚 详细参考:
包安装
bash
npm install @metamask/smart-accounts-kit@0.3.0
对于自定义限制条件执行器:
bash
forge install metamask/delegation-framework@v1.3.0
核心概念摘要
1. 智能账户 (ERC-4337)
三种实现类型:
- - 混合型 (Implementation.Hybrid) - EOA + 通行密钥签名者
- 多签型 (Implementation.MultiSig) - 多个签名者,带阈值
- 无状态7702型 (Implementation.Stateless7702) - EIP-7702 升级的 EOA
2. 委托框架 (ERC-7710)
从委托方授予权限给被委托方:
- - 范围 - 初始权限(支出限额、函数调用)
- 限制条件 - 由智能合约强制执行的限制
- 类型 - 根委托、开放根委托、再委托、开放再委托
- 生命周期 - 创建 → 签名 → 存储 → 赎回
3. 高级权限 (ERC-7715)
通过 MetaMask 扩展请求权限:
- - 人类可读的 UI 确认
- ERC-20 和原生代币权限
- 需要 MetaMask Flask 13.5.0+
- 用户必须拥有智能账户
快速代码示例
创建智能账户
typescript
import { Implementation, toMetaMaskSmartAccount } from @metamask/smart-accounts-kit
import { privateKeyToAccount } from viem/accounts
const account = privateKeyToAccount(0x...)
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [account.address, [], [], []],
deploySalt: 0x,
signer: { account },
})
创建委托
typescript
import { createDelegation } from @metamask/smart-accounts-kit
import { parseUnits } from viem
const delegation = createDelegation({
to: delegateAddress,
from: delegatorSmartAccount.address,
environment: delegatorSmartAccount.environment,
scope: {
type: erc20TransferAmount,
tokenAddress: 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238,
maxAmount: parseUnits(10, 6),
},
caveats: [
{ type: timestamp, afterThreshold: now, beforeThreshold: expiry },
{ type: limitedCalls, limit: 5 },
],
})
签名委托
typescript
const signature = await smartAccount.signDelegation({ delegation })
const signedDelegation = { ...delegation, signature }
赎回委托
typescript
import { createExecution, ExecutionMode } from @metamask/smart-accounts-kit
import { DelegationManager } from @metamask/smart-accounts-kit/contracts
import { encodeFunctionData, erc20Abi } from viem
const callData = encodeFunctionData({
abi: erc20Abi,
args: [recipient, parseUnits(1, 6)],
functionName: transfer,
})
const execution = createExecution({ target: tokenAddress, callData })
const redeemCalldata = DelegationManager.encode.redeemDelegations({
delegations: [[signedDelegation]],
modes: [ExecutionMode.SingleDefault],
executions: [[execution]],
})
// 通过智能账户
const userOpHash = await bundlerClient.sendUserOperation({
account: delegateSmartAccount,
calls: [{ to: delegateSmartAccount.address, data: redeemCalldata }],
})
// 通过 EOA
const txHash = await delegateWalletClient.sendTransaction({
to: environment.DelegationManager,
data: redeemCalldata,
})
请求高级权限
typescript
import { erc7715ProviderActions } from @metamask/smart-accounts-kit/actions
const walletClient = createWalletClient({
transport: custom(window.ethereum),
}).extend(erc7715ProviderActions())
const grantedPermissions = await walletClient.requestExecutionPermissions([
{
chainId: chain.id,
expiry: now + 604800,
signer: {
type: account,
data: { address: sessionAccount.address },
},
permission: {
type: erc20-token-periodic,
data: {
tokenAddress,
periodAmount: parseUnits(10, 6),
periodDuration: 86400,
justification: 每日转账 10 USDC,
},
},
isAdjustmentAllowed: true,
},
])
赎回高级权限
typescript
// 智能账户
import { erc7710BundlerActions } from @metamask/smart-accounts-kit/actions
const bundlerClient = createBundlerClient({
client: publicClient,
transport: http(bundlerUrl),
}).extend(erc7710BundlerActions())
const permissionsContext = grantedPermissions[0].context
const delegationManager = grantedPermissions[0].signerMeta.delegationManager
const userOpHash = await bundlerClient.sendUserOperationWithDelegation({
publicClient,
account: sessionAccount,
calls: [
{
to: tokenAddress,
data: calldata,
permissionsContext,
delegationManager,
},
],
})
// EOA
import { erc7710WalletActions } from @metamask/smart-accounts-kit/actions
const walletClient = createWalletClient({
account: sessionAccount,
chain,
transport: http(),
}).extend(erc7710WalletActions())
const txHash = await walletClient.sendTransactionWithDelegation({
to: tokenAddress,
data: calldata,
permissionsContext,
delegationManager,
})
关键 API 方法
智能账户
- - toMetaMaskSmartAccount() - 创建智能账户
- aggregateSignature() - 合并多签签名
- signDelegation() - 签名委托
- signUserOperation() - 签名用户操作
- signMessage() / signTypedData() - 标准签名
委托
- - createDelegation() - 创建带被委托方的委托
- createOpenDelegation() - 创建开放委托
- createCaveatBuilder() - 构建限制条件数组
- createExecution() - 创建执行结构体
- redeemDelegations() - 编码赎回调用数据
- signDelegation() - 使用私钥签名
- getSmartAccountsEnvironment() - 解析环境
- deploySmartAccountsEnvironment() - 部署合约
- overrideDeployedEnvironment() - 覆盖环境
高级权限
- - erc7715ProviderActions() - 用于请求的钱包客户端扩展
- requestExecutionPermissions() - 请求权限
- erc7710BundlerActions() - Bundler 客户端扩展
- sendUserOperationWithDelegation() - 使用智能账户赎回
- erc7710WalletActions() - 钱包客户端扩展
- sendTransactionWithDelegation() - 使用 EOA 赎回
支持的 ERC-7715 权限类型
ERC-20 代币权限
| 权限类型 | 描述 |
|---|
| erc20-token-periodic | 每周期限额,每个周期重置 |
| erc20-token-streaming |
线性流式传输,按 amountPerSecond 速率 |
原生代币权限
| 权限类型 | 描述 |
|---|
| native-token-periodic | 每周期 ETH 限额,会重置 |
| native-token-streaming |
线性 ETH 流式传输,按 amountPerSecond 速率 |
常见委托范围
支出限额
| 范围 | 描述 |
|---|
| erc20TransferAmount | 固定 ERC-20 限额 |
| erc20PeriodTransfer |
每周期 ERC-20 限额 |
| erc20Streaming | 线性流式传输 ERC-20 |
| nativeTokenTransferAmount | 固定原生代币限额 |
| nativeTokenPeriodTransfer | 每周期原生代