💼 スマートAccountsKit
MetaMask Smart Accounts Kit を活用し、ERC-4337スマートアカウントでのdApps開発、ユーザー操作の送信、トランザクションのバッチ処理、多様な署名者の設定、ガス抽象化、委任、高度な権限要求などを実現するためのSkill。
📜 元の英語説明(参考)
Web3 development using MetaMask Smart Accounts Kit. Use when the user wants to build dApps with ERC-4337 smart accounts, send user operations, batch transactions, configure signers (EOA, passkey, multisig), implement gas abstraction with paymasters, create delegations, or request advanced permissions (ERC-7715). Supports Viem integration, multiple signer types (Dynamic, Web3Auth, Wagmi), gasless transactions, and the Delegation Framework.
🇯🇵 日本人クリエイター向け解説
MetaMask Smart Accounts Kit を活用し、ERC-4337スマートアカウントでのdApps開発、ユーザー操作の送信、トランザクションのバッチ処理、多様な署名者の設定、ガス抽象化、委任、高度な権限要求などを実現するためのSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o smart-accounts-kit.zip https://jpskill.com/download/5404.zip && unzip -o smart-accounts-kit.zip && rm smart-accounts-kit.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5404.zip -OutFile "$d\smart-accounts-kit.zip"; Expand-Archive "$d\smart-accounts-kit.zip" -DestinationPath $d -Force; ri "$d\smart-accounts-kit.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
smart-accounts-kit.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
smart-accounts-kitフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 4
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
クイックリファレンス
このスキルファイルは、MetaMask Smart Accounts Kit v0.3.0 へのクイックアクセスを提供します。詳細については、特定の参照ファイルをご参照ください。
📚 詳細リファレンス:
- Smart Accounts Reference - アカウント作成、実装、署名者
- Delegations Reference - デリゲーションのライフサイクル、スコープ、注意点
- Advanced Permissions Reference - MetaMask を介した ERC-7715 パーミッション
パッケージのインストール
npm install @metamask/smart-accounts-kit@0.3.0
カスタムの Caveat Enforcer の場合:
forge install metamask/delegation-framework@v1.3.0
コアコンセプトの概要
1. スマートアカウント (ERC-4337)
3つの実装タイプがあります。
| 実装 | 最適な用途 | 主要機能 |
|---|---|---|
Hybrid (Implementation.Hybrid) |
標準的な dApp ユーザー | EOA + パスキー署名者、最も柔軟 |
MultiSig (Implementation.MultiSig) |
財務/DAO 運用 | 閾値ベースのセキュリティ、Safe 互換 |
Stateless7702 (Implementation.Stateless7702) |
既存の EOA を持つパワーユーザー | 同じアドレスを維持し、EIP-7702 を介してスマートアカウント機能を追加 |
決定ガイド:
- 一般ユーザー向けに構築する場合 → Hybrid
- 財務管理や複数当事者による管理を行う場合 → MultiSig
- アドレスを変更せずに既存の EOA をアップグレードする場合 → Stateless7702
2. デリゲーションフレームワーク (ERC-7710)
デリゲーターからデリゲートにパーミッションを付与します。
- Scopes - 初期権限 (支出制限、関数呼び出し)
- Caveats - スマートコントラクトによって強制される制限
- Types - Root、Open Root、Redelegation、Open Redelegation
- Lifecycle - 作成 → 署名 → 保存 → 償還
3. 高度なパーミッション (ERC-7715)
MetaMask 拡張機能を介してパーミッションをリクエストします。
- 人間が読める UI 確認
- ERC-20 およびネイティブトークンのパーミッション
- MetaMask Flask 13.5.0+ が必要です
- ユーザーはスマートアカウントを持っている必要があります
クイックコード例
スマートアカウントの作成
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 },
})
デリゲーションの作成
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 },
],
})
デリゲーションの署名
const signature = await smartAccount.signDelegation({ delegation })
const signedDelegation = { ...delegation, signature }
デリゲーションの償還
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]],
})
// Via smart account
const userOpHash = await bundlerClient.sendUserOperation({
account: delegateSmartAccount,
calls: [{ to: delegateSmartAccount.address, data: redeemCalldata }],
})
// Via EOA
const txHash = await delegateWalletClient.sendTransaction({
to: environment.DelegationManager,
data: redeemCalldata,
})
高度なパーミッションのリクエスト
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: 'Transfer 10 USDC daily',
},
},
isAdjustmentAllowed: true,
},
])
高度なパーミッションの償還
// Smart account
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()- 結合します
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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:
- Smart Accounts Reference - Account creation, implementations, signers
- Delegations Reference - Delegation lifecycle, scopes, caveats
- Advanced Permissions Reference - ERC-7715 permissions via MetaMask
Package Installation
npm install @metamask/smart-accounts-kit@0.3.0
For custom caveat enforcers:
forge install metamask/delegation-framework@v1.3.0
Core Concepts Summary
1. Smart Accounts (ERC-4337)
Three implementation types:
| Implementation | Best For | Key Feature |
|---|---|---|
Hybrid (Implementation.Hybrid) |
Standard dApp users | EOA + passkey signers, most flexible |
MultiSig (Implementation.MultiSig) |
Treasury/DAO operations | Threshold-based security, Safe-compatible |
Stateless7702 (Implementation.Stateless7702) |
Power users with existing EOA | Keep same address, add smart account features via EIP-7702 |
Decision Guide:
- Building for general users? → Hybrid
- Managing treasuries or multi-party control? → MultiSig
- Upgrading existing EOAs without address change? → Stateless7702
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
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 },
})
Create Delegation
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 },
],
})
Sign Delegation
const signature = await smartAccount.signDelegation({ delegation })
const signedDelegation = { ...delegation, signature }
Redeem Delegation
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]],
})
// Via smart account
const userOpHash = await bundlerClient.sendUserOperation({
account: delegateSmartAccount,
calls: [{ to: delegateSmartAccount.address, data: redeemCalldata }],
})
// Via EOA
const txHash = await delegateWalletClient.sendTransaction({
to: environment.DelegationManager,
data: redeemCalldata,
})
Request Advanced Permissions
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: 'Transfer 10 USDC daily',
},
},
isAdjustmentAllowed: true,
},
])
Redeem Advanced Permissions
// Smart account
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,
})
Key API Methods
Smart Accounts
toMetaMaskSmartAccount()- Create smart accountaggregateSignature()- Combine multisig signaturessignDelegation()- Sign delegationsignUserOperation()- Sign user operationsignMessage()/signTypedData()- Standard signing
Delegations
createDelegation()- Create delegation with delegatecreateOpenDelegation()- Create open delegationcreateCaveatBuilder()- Build caveats arraycreateExecution()- Create execution structredeemDelegations()- Encode redemption calldatasignDelegation()- Sign with private keygetSmartAccountsEnvironment()- Resolve environmentdeploySmartAccountsEnvironment()- Deploy contractsoverrideDeployedEnvironment()- Override environment
Advanced Permissions
erc7715ProviderActions()- Wallet client extension for requestingrequestExecutionPermissions()- Request permissionserc7710BundlerActions()- Bundler client extensionsendUserOperationWithDelegation()- Redeem with smart accounterc7710WalletActions()- Wallet client extensionsendTransactionWithDelegation()- Redeem with EOA
Supported ERC-7715 Permission Types
ERC-20 Token Permissions
| Permission Type | Description |
|---|---|
erc20-token-periodic |
Per-period limit that resets at each period |
erc20-token-stream |
Linear streaming with amountPerSecond rate |
Native Token Permissions
| Permission Type | Description |
|---|---|
native-token-periodic |
Per-period ETH limit that resets |
native-token-stream |
Linear ETH streaming with amountPerSecond rate |
Common Delegation Scopes
Spending Limits
| Scope | Description |
|---|---|
erc20TransferAmount |
Fixed ERC-20 limit |
erc20PeriodTransfer |
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 |
|---|---|
functionCall |
Specific methods/addresses allowed |
ownershipTransfer |
Ownership transfers only |
Common Caveat Enforcers
Target & Method
allowedTargets- Limit callable addressesallowedMethods- Limit callable methodsallowedCalldata- Validate specific calldataexactCalldata/exactCalldataBatch- Exact calldata matchexactExecution/exactExecutionBatch- Exact execution match
Value & Token
valueLte- Limit native token valueerc20TransferAmount- Limit ERC-20 amounterc20BalanceChange- Validate ERC-20 balance changeerc721Transfer/erc721BalanceChange- ERC-721 restrictionserc1155BalanceChange- ERC-1155 validation
Time & Frequency
timestamp- Valid time range (seconds)blockNumber- Valid block rangelimitedCalls- Limit redemption counterc20PeriodTransfer/erc20Streaming- Time-based ERC-20nativeTokenPeriodTransfer/nativeTokenStreaming- Time-based native
Security & State
redeemer- Limit redemption to specific addressesid- One-time delegation with IDnonce- Bulk revocation via noncedeployed- Auto-deploy contractownershipTransfer- Ownership transfer onlynativeTokenPayment- Require paymentnativeBalanceChange- Validate native balancemultiTokenPeriod- Multi-token period limits
Execution Modes
| Mode | Chains | Processing | On Failure |
|---|---|---|---|
SingleDefault |
One | Sequential | Revert |
SingleTry |
One | Sequential | Continue |
BatchDefault |
Multiple | Interleaved | Revert |
BatchTry |
Multiple | Interleaved | Continue |
Contract Addresses (v1.3.0)
Core
| Contract | Address |
|---|---|
| EntryPoint | 0x0000000071727De22E5E9d8BAf0edAc6f37da032 |
| SimpleFactory | 0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c |
| DelegationManager | 0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3 |
| MultiSigDeleGatorImpl | 0x56a9EdB16a0105eb5a4C54f4C062e2868844f3A7 |
| HybridDeleGatorImpl | 0x48dBe696A4D990079e039489bA2053B36E8FFEC4 |
Critical Rules
Always Required
- 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
- 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
- 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
Advanced Patterns
Parallel User Operations (Nonce Keys)
Smart accounts use a 256-bit nonce structure: 192-bit key + 64-bit sequence. Each unique key has its own independent sequence, enabling parallel execution. This is critical for backend services processing multiple delegations concurrently.
Installation
For proper nonce handling, install the permissionless SDK alongside the Smart Accounts Kit:
npm install permissionless
How Parallel Nonces Work
ERC-4337 uses a single uint256 nonce where:
- 192 bits = key identifier (allows parallel streams)
- 64 bits = sequence number (increments per key)
Each key has an independent sequence, so UserOps with different keys execute in parallel without ordering constraints.
Getting Nonce with Permissionless
import { getAccountNonce } from 'permissionless'
import { entryPoint07Address } from 'viem/account-abstraction'
// Get nonce for a specific key
const parallelNonce = await getAccountNonce(publicClient, {
address: smartAccount.address,
entryPointAddress: entryPoint07Address,
key: BigInt(Date.now()), // Unique key for parallel execution
})
const userOpHash = await bundlerClient.sendUserOperation({
account: smartAccount,
calls: [redeemCalldata],
nonce: parallelNonce, // Properly encoded 256-bit nonce
})
Parallel Execution Pattern
import { getAccountNonce } from 'permissionless'
import { entryPoint07Address } from 'viem/account-abstraction'
// Execute multiple redemption UserOps in parallel
const redeems = await Promise.all(
delegations.map(async (delegation, index) => {
// Generate unique key for this operation
const nonceKey = BigInt(Date.now()) + BigInt(index * 1000)
// Get properly encoded nonce for this key
const nonce = await getAccountNonce(publicClient, {
address: backendSmartAccount.address,
entryPointAddress: entryPoint07Address,
key: nonceKey,
})
const redeemCalldata = DelegationManager.encode.redeemDelegations({
delegations: [[delegation]],
modes: [ExecutionMode.SingleDefault],
executions: [[execution]],
})
return bundlerClient.sendUserOperation({
account: backendSmartAccount,
calls: [{ to: backendSmartAccount.address, data: redeemCalldata }],
nonce, // Parallel execution enabled via unique key
})
})
)
Without Permissionless (Manual Approach)
The EntryPoint contract encodes nonce as: sequence | (key << 64)
If not using permissionless, encode manually:
// EntryPoint: nonceSequenceNumber[sender][key] | (uint256(key) << 64)
const key = BigInt(Date.now())
const sequence = 0n // New key starts at sequence 0
const nonce = sequence | (key << 64n)
// Or equivalently: (key << 64n) | sequence
However, getAccountNonce from permissionless is recommended as it:
- Fetches the current sequence for the key from the EntryPoint
- Properly encodes the 256-bit value
- Handles edge cases and validation
Key Points
- Different keys = parallel execution — no ordering guarantees between different keys
- Same key = sequential execution — sequence increments monotonically per key
- Use cases: Backend redemption services, DCA apps, high-frequency trading, batch operations
- Nonce generation:
getAccountNoncereturns the full 256-bit nonce properly encoded
Common Mistakes
| Mistake | Result |
|---|---|
| Reusing same nonce key | Sequential execution (defeats purpose) |
Using Date.now() without offset |
Potential collision if multiple ops fire simultaneously |
Not using getAccountNonce |
May miss current sequence, causing replacement instead of new op |
| Assuming ordering | Race conditions in dependent operations |
Error Handling
const results = await Promise.allSettled(redeems)
results.forEach((result, index) => {
if (result.status === 'rejected') {
// Check for specific errors
if (result.reason.message?.includes('AA25')) {
console.error(`Nonce collision for op ${index}`)
}
// Handle or retry
}
})
Backend Delegation Redemption
For server-side automation (DCA bots, keeper services, automated trading):
// 1. Backend creates its own smart account as delegate
const backendAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [backendOwner.address, [], [], []],
deploySalt: '0x',
signer: { account: backendOwner },
})
// 2. Backend redeems by sending UserOp FROM its account
const userOpHash = await bundlerClient.sendUserOperation({
account: backendAccount,
calls: [{
to: backendAccount.address,
data: DelegationManager.encode.redeemDelegations({
delegations: [[userDelegation]],
modes: [ExecutionMode.SingleDefault],
executions: [[swapExecution]],
})
}],
})
Use case: Automated dollar-cost averaging (DCA) bots that redeem swap delegations based on market signals or scheduled intervals.
Counterfactual Account Deployment
Delegator accounts must be deployed before delegations can be redeemed. The DelegationManager reverts with 0xb9f0f171 for counterfactual accounts.
Solution: Deploy automatically via first UserOp:
// Build redemption calldata
const redeemCalldata = DelegationManager.encode.redeemDelegations({
delegations: [[signedDelegation]],
modes: [ExecutionMode.SingleDefault],
executions: [[execution]],
})
// First redemption deploys the account automatically via initCode
const userOpHash = await bundlerClient.sendUserOperation({
account: smartAccount, // Will deploy if counterfactual
calls: [{
to: smartAccount.address,
data: redeemCalldata,
value: 0n,
}],
})
Session Accounts for AI Agents
For automated services, session accounts act as isolated signers that can only operate within granted delegations. The private key can be generated ephemerally, stored in environment variables, or managed via HSM/server wallets:
// Session account created from various sources
const sessionAccount = privateKeyToAccount(
process.env.SESSION_KEY || generatePrivateKey() || hsmWallet.key
)
// Request delegation from user to session account
const delegation = createDelegation({
to: sessionAccount.address,
from: userSmartAccount.address,
environment,
scope: { type: 'erc20TransferAmount', tokenAddress, maxAmount: parseUnits('100', 6) },
caveats: [
{ type: 'timestamp', afterThreshold: now, beforeThreshold: expiry },
{ type: 'limitedCalls', limit: 10 },
],
})
// Session account can only act within delegation constraints
Common Patterns
Pattern 1: ERC-20 with Time Limit
const delegation = createDelegation({
to: delegate,
from: delegator,
environment,
scope: {
type: 'erc20TransferAmount',
tokenAddress,
maxAmount: parseUnits('100', 6),
},
caveats: [
{ type: 'timestamp', afterThreshold: now, beforeThreshold: expiry },
{ type: 'limitedCalls', limit: 10 },
{ type: 'redeemer', redeemers: [delegate] },
],
})
Pattern 2: Function Call with Value
const delegation = createDelegation({
to: delegate,
from: delegator,
environment,
scope: {
type: 'functionCall',
targets: [contractAddress],
selectors: ['transfer(address,uint256)'],
valueLte: { maxValue: parseEther('0.1') },
},
caveats: [{ type: 'allowedMethods', selectors: ['transfer(address,uint256)'] }],
})
Pattern 3: Periodic Native Token
const delegation = createDelegation({
to: delegate,
from: delegator,
environment,
scope: {
type: 'nativeTokenPeriodTransfer',
periodAmount: parseEther('0.01'),
periodDuration: 86400,
startDate: now,
},
})
Pattern 4: Redelegation Chain
// Alice → Bob (100 USDC)
const aliceToBob = createDelegation({
to: bob,
from: alice,
environment,
scope: { type: 'erc20TransferAmount', tokenAddress, maxAmount: parseUnits('100', 6) },
})
// Bob → Carol (50 USDC, subset of authority)
const bobToCarol = createDelegation({
to: carol,
from: bob,
environment,
scope: { type: 'erc20TransferAmount', tokenAddress, maxAmount: parseUnits('50', 6) },
parentDelegation: aliceToBob,
caveats: [{ type: 'timestamp', afterThreshold: now, beforeThreshold: expiry }],
})
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 |
Error Code Reference
Error codes from the MetaMask Delegation Framework contracts (v1.3.0). Use a decoder like calldata.swiss-knife.xyz to identify error signatures.
DelegationManager Errors (Verified)
| Error Code | Error Name | Meaning |
|---|---|---|
0xb5863604 |
InvalidDelegate() |
Caller is not the delegate — Most common error |
0xb9f0f171 |
InvalidDelegator() |
Caller is not the delegator |
0x05baa052 |
CannotUseADisabledDelegation() |
Attempting to redeem a disabled delegation |
0xded4370e |
InvalidAuthority() |
Delegation chain authority validation failed |
0x1bcaf69f |
BatchDataLengthMismatch() |
Array lengths don't match in batch |
0x005ecddb |
AlreadyDisabled() |
Delegation has already been disabled |
0xf2a5f75a |
AlreadyEnabled() |
Delegation is already enabled |
0xf645eedf |
ECDSAInvalidSignature() |
Invalid ECDSA signature format |
0xfce698f7 |
ECDSAInvalidSignatureLength(uint256) |
Signature length is incorrect |
0xd78bce0c |
ECDSAInvalidSignatureS(bytes32) |
Signature S value is invalid |
0xac241e11 |
EmptySignature() |
Signature is empty |
0xd93c0665 |
EnforcedPause() |
Contract is paused |
0x3db6791c |
InvalidEOASignature() |
EOA signature verification failed |
0x155ff427 |
InvalidERC1271Signature() |
Smart contract signature (ERC1271) failed |
0x118cdaa7 |
OwnableUnauthorizedAccount(address) |
Unauthorized account attempted owner-only action |
0x1e4fbdf7 |
OwnableInvalidOwner(address) |
Invalid owner address in ownership transfer |
0xf6b6ef5b |
InvalidShortString() |
String parameter too short |
0xaa0ea2d8 |
StringTooLong(string) |
String parameter exceeds maximum length |
DeleGatorCore Errors (Verified)
| Error Code | Error Name | Meaning |
|---|---|---|
0xd663742a |
NotEntryPoint() |
Caller is not the EntryPoint contract |
0x0796d945 |
NotEntryPointOrSelf() |
Caller is neither EntryPoint nor this contract |
0x1a4b3a04 |
NotDelegationManager() |
Caller is not the DelegationManager |
0xb96fcfe4 |
UnsupportedCallType(bytes1) |
Execution call type not supported |
0x1187dc06 |
UnsupportedExecType(bytes1) |
Execution type not supported |
0x29c3b7ee |
NotSelf() |
Caller is not this contract itself |
Common Caveat Enforcer Errors (Revert Strings)
| Error String | Meaning |
|---|---|
AllowedTargetsEnforcer:target-address-not-allowed |
Target contract not in allowed list |
AllowedTargetsEnforcer:invalid-terms-length |
Terms length not multiple of 20 bytes |
ERC20TransferAmountEnforcer:invalid-terms-length |
Terms must be 52 bytes |
ERC20TransferAmountEnforcer:invalid-contract |
Target doesn't match allowed token |
ERC20TransferAmountEnforcer:invalid-method |
Method is not transfer |
ERC20TransferAmountEnforcer:allowance-exceeded |
Transfer exceeds delegated limit |
CaveatEnforcer:invalid-call-type |
Must use single call type |
CaveatEnforcer:invalid-execution-type |
Must use default execution type |
Most Common Errors in Production
0xb5863604 — InvalidDelegate()
- Cause: Caller doesn't match the delegate address in delegation
- Fix: Verify
msg.senderequals thetoaddress in the delegation
0xb9f0f171 — InvalidDelegator()
- Cause: Attempting to enable/disable from wrong address, or counterfactual account
- Fix: Only delegator can enable/disable; for counterfactual, first UserOp auto-deploys
0x05baa052 — CannotUseADisabledDelegation()
- Cause: Delegation was disabled by delegator
- Fix: Ask delegator to re-enable, or use different delegation
0xded4370e — InvalidAuthority()
- Cause: Broken delegation chain (redelegation parent mismatch)
- Fix: Ensure redelegation chains are properly ordered (leaf → root)
0x1bcaf69f — BatchDataLengthMismatch()
- Cause: Array lengths don't match in
redeemDelegationscall - Fix: Ensure
permissionContexts,modes,executionCallDatashave equal length
0x3db6791c — InvalidEOASignature()
- Cause: EOA signature invalid, wrong chain, or wrong delegation manager
- Fix: Verify signature was created with correct chain ID and delegation manager
Resources
- NPM:
@metamask/smart-accounts-kit - Contracts:
metamask/delegation-framework@v1.3.0 - 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.
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (26,187 bytes)
- 📎 references/advanced-permissions.md (18,972 bytes)
- 📎 references/delegations.md (23,207 bytes)
- 📎 references/smart-accounts.md (12,806 bytes)