smart-accounts-kit
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.
What this skill does
## 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](./references/smart-accounts.md) - Account creation, implementations, signers - [Delegations Reference](./references/delegations.md) - Delegation lifecycle, scopes, caveats - [Advanced Permissions Reference](./references/advanced-permissions.md) - ERC-7715 permissions via MetaMask ## Package Installation ```bash npm install @metamask/[email protected] ``` For custom caveat enforcers: ```bash forge install metamask/[email protected] ``` ## 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 ```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 }, }) ``` ### Create Delegation ```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 }, ], }) ``` ### Sign Delegation ```typescript const signature = await smartAccount.signDelegation({ delegation }) const signedDelegation = { ...delegation, signature } ``` ### Redeem Delegation ```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]], }) // 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 ```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: 'Transfer 10 USDC daily', }, }, isAdjustmentAllowed: true, }, ]) ``` ### Redeem Advanced Permissions ```typescript // 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 account - `aggregateSignature()` - Combine multisig signatures - `signDelegation()` - Sign delegation - `signUserOperation()` - Sign user operation - `signMessage()` / `signTypedData()` - Standard signing ### Delegations - `createDelegation()` - Create delegation with delegate - `createOpenDelegation()` - Create open delegation - `createCaveatBuilder()` - Build caveats array - `createExecution()` - Create execution struct - `redeemDelegations()` - Encode redemption calldata - `signDelegation()` - Sign with private key - `getSmartAccountsEnvironment()` - Resolve environment - `deploySmartAccountsEnvironment()` - Deploy contracts - `overrideDeployedEnvironment()` - Override environment ### Advanced Permissions - `erc7715ProviderActions()` - Wallet client extension for requesting - `requestExecutionPermissions()` - Request permissions - `erc7710BundlerActions()` - Bundler client extension - `sendUserOperationWithDelegation()` - Redeem with smart account - `erc7710WalletActions()` - Wallet client extension - `sendTransactionWithDelegation()` - 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 | | `nativeT
Related in Web3
xaut-trade
IncludedBuy or sell XAUT (Tether Gold) on Ethereum. Supports market orders (Uniswap V3) and limit orders (UniswapX). Wallet modes: Foundry keystore or WDK. Delegates non-XAUT intents to registered skills (e.g. Polymarket prediction markets, Hyperliquid trading). Triggers: buy XAUT, XAUT trade, swap USDT for XAUT, sell XAUT, swap XAUT for USDT, limit order, limit buy XAUT, limit sell XAUT, check limit order, cancel limit order, XAUT when, create wallet, setup wallet, polymarket, prediction market, bet on, odds on, hyperliquid, perp, perpetual, long, short, open long, open short, close position, leverage.
qfc-openclaw-skill
IncludedQFC blockchain interaction โ wallet, faucet, chain queries, staking, epoch & finality, AI inference
gate-dex-trade
IncludedExecutes on-chain token swaps via Gate DEX. Use when user wants to swap, buy, sell, exchange, or convert tokens, or bridge cross-chain. Covers full swap flow: price quotes, transaction build, signing, and submission. Do NOT use for read-only data lookups or wallet account management.
hunch
IncludedDiscover, bet on, track, and settle Hunch prediction markets in natural language. Trigger when a user wants to bet, take a position, or get odds on a crypto outcome โ token market-cap milestones and flips, launchpad races (Bankr vs pump.fun volume / #1-days / launches over a cap), token head-to-head outperformance, mcap strike-ladders, and up/down price rounds. Also trigger on "what can I bet on about $TOKEN", "odds on โฆ", "take YES/NO on โฆ", "show my Hunch bets", "did my market resolve". Settles in USDC on Base via x402 (โค $10 / bet); every bet returns an on-chain proof.
opensea
IncludedQuery NFT data, trade on the Seaport marketplace, and swap ERC20 tokens across Ethereum, Base, Arbitrum, Optimism, Polygon, and more.
polymarket
IncludedTrade on Polymarket prediction markets (CLOB V2) from a Privy EOA wallet. Search markets, place/cancel orders, manage positions. No private key handling. Use when the user wants to bet on event outcomes (e.g. "buy YES at 0.65 on the ceasefire market", "what are my open positions", "close my Trump bet").