|
| 1 | +--- |
| 2 | +name: Delegations |
| 3 | +description: API reference for creating delegations with scopes and caveat enforcers — ERC-7710 delegation framework |
| 4 | +--- |
| 5 | + |
| 6 | +# Delegations |
| 7 | + |
| 8 | +## When to use |
| 9 | + |
| 10 | +- You want to grant permissions from one account to another (delegator to delegate). |
| 11 | +- You want to set spending limits (ERC-20, native token, NFT). |
| 12 | +- You want to restrict function calls to specific contracts or methods. |
| 13 | +- You want to add time limits, call limits, or other restrictions via caveats. |
| 14 | +- You want to create delegation chains (redelegation). |
| 15 | + |
| 16 | +## API reference |
| 17 | + |
| 18 | +### `createDelegation` parameters |
| 19 | + |
| 20 | +| Name | Type | Required | Description | |
| 21 | +|------|------|----------|-------------| |
| 22 | +| `from` | `Hex` | Yes | The address granting the delegation | |
| 23 | +| `to` | `Hex` | Yes | The address receiving the delegation | |
| 24 | +| `scope` | `ScopeConfig` | Yes | Defines the initial authority of the delegation | |
| 25 | +| `environment` | `SmartAccountsEnvironment` | Yes | Contract addresses for framework interactions | |
| 26 | +| `caveats` | `Caveats` | No | Caveats that further refine the authority granted by the scope | |
| 27 | +| `parentDelegation` | `Delegation \| Hex` | No | Parent delegation for creating a chain (mutually exclusive with `parentPermissionContext`) | |
| 28 | +| `parentPermissionContext` | `PermissionContext` | No | Parent chain as hex or decoded values, leaf first (mutually exclusive with `parentDelegation`) | |
| 29 | +| `salt` | `Hex` | No | Salt for generating the delegation hash to prevent collisions | |
| 30 | + |
| 31 | +For more details, see the [delegation reference](https://docs.metamask.io/smart-accounts-kit/reference/delegation.md). |
| 32 | + |
| 33 | +### Scope types |
| 34 | + |
| 35 | +Use the `ScopeType` enum for type-safe scope configuration: |
| 36 | + |
| 37 | +| ScopeType | When to use | |
| 38 | +|-----------|-------------| |
| 39 | +| `Erc20TransferAmount` | You want to set a fixed cumulative ERC-20 transfer limit | |
| 40 | +| `Erc20PeriodTransfer` | You want a per-period ERC-20 limit that resets at the start of each new period | |
| 41 | +| `Erc20Streaming` | You want a linear streaming ERC-20 limit that accrues over time | |
| 42 | +| `NativeTokenTransferAmount` | You want to set a fixed cumulative native token transfer limit | |
| 43 | +| `NativeTokenPeriodTransfer` | You want a per-period native token limit that resets at the start of each new period | |
| 44 | +| `NativeTokenStreaming` | You want a linear streaming native token limit that accrues over time | |
| 45 | +| `Erc721Transfer` | You want to restrict the delegation to a specific NFT transfer | |
| 46 | +| `FunctionCall` | You want to restrict the delegation to specific methods, addresses, or calldata | |
| 47 | +| `OwnershipTransfer` | You want to restrict the delegation to ownership transfer calls only | |
| 48 | + |
| 49 | +For full scope parameters, see the [delegation scopes guide](https://docs.metamask.io/smart-accounts-kit/guides/delegation/use-delegation-scopes.md). |
| 50 | + |
| 51 | +### Caveat types |
| 52 | + |
| 53 | +| Type | When to use | |
| 54 | +|------|-------------| |
| 55 | +| `allowedTargets` | You want to restrict which contract addresses the delegate can call | |
| 56 | +| `allowedMethods` | You want to restrict which methods the delegate can call | |
| 57 | +| `allowedCalldata` | You want to validate specific calldata at a byte offset | |
| 58 | +| `exactCalldata` | You want to require an exact calldata match | |
| 59 | +| `exactCalldataBatch` | You want to require an exact calldata match for a batch of executions | |
| 60 | +| `exactExecution` | You want to require an exact match on target, value, and calldata | |
| 61 | +| `exactExecutionBatch` | You want to require an exact match for a batch of executions | |
| 62 | +| `valueLte` | You want to cap the native token value per call | |
| 63 | +| `erc20TransferAmount` | You want to set a max cumulative ERC-20 transfer amount | |
| 64 | +| `erc20BalanceChange` | You want to validate that an ERC-20 balance changes as expected | |
| 65 | +| `erc20PeriodTransfer` | You want a per-period ERC-20 limit that resets each period | |
| 66 | +| `erc20Streaming` | You want a linear streaming ERC-20 limit that accrues over time | |
| 67 | +| `erc721Transfer` | You want to restrict the delegation to a specific NFT transfer | |
| 68 | +| `erc721BalanceChange` | You want to validate that an ERC-721 balance changes as expected | |
| 69 | +| `erc1155BalanceChange` | You want to validate that an ERC-1155 balance changes as expected | |
| 70 | +| `nativeTokenPeriodTransfer` | You want a per-period native token limit that resets each period | |
| 71 | +| `nativeTokenStreaming` | You want a linear streaming native token limit that accrues over time | |
| 72 | +| `nativeBalanceChange` | You want to validate that a native token balance changes as expected | |
| 73 | +| `nativeTokenPayment` | You want to require the redeemer to pay a fee to redeem | |
| 74 | +| `timestamp` | You want to restrict redemption to a specific time window | |
| 75 | +| `blockNumber` | You want to restrict redemption to a specific block range | |
| 76 | +| `limitedCalls` | You want to limit how many times the delegation can be redeemed | |
| 77 | +| `redeemer` | You want to restrict which addresses can redeem the delegation | |
| 78 | +| `id` | You want a one-time delegation identified by a unique ID | |
| 79 | +| `nonce` | You want to enable bulk revocation of delegations sharing the same nonce | |
| 80 | +| `deployed` | You want to auto-deploy a contract before the delegation executes | |
| 81 | +| `ownershipTransfer` | You want to restrict the delegation to ownership transfer calls only | |
| 82 | +| `multiTokenPeriod` | You want to set per-period limits across multiple tokens at once | |
| 83 | +| `specificActionERC20TransferBatch` | You want to combine a specific action with an ERC-20 transfer in a batch | |
| 84 | +| `argsEqualityCheck` | You want to validate that function arguments match a specific value | |
| 85 | + |
| 86 | +For full caveat parameters, see the [caveats reference](https://docs.metamask.io/smart-accounts-kit/reference/delegation/caveats.md). |
| 87 | + |
| 88 | +## Important rules |
| 89 | + |
| 90 | +- The delegator must always be a MetaMask smart account created with `toMetaMaskSmartAccount`. |
| 91 | +- You must deploy the delegator before redeeming delegations — the DelegationManager reverts with `0xb9f0f171` for counterfactual accounts. |
| 92 | +- Always use caveats — without them, delegations have infinite authority. |
| 93 | +- Function call scope defaults to no native token — use `valueLte` to allow it. |
| 94 | +- Caveats are cumulative in chains — restrictions stack, and a delegate can only redelegate with equal or lesser authority. |
| 95 | +- Caveat order matters — place state-changing caveats (payment) before balance checks. |
| 96 | +- Use the `ScopeType` enum for type-safe scope configuration. |
| 97 | + |
| 98 | +## Workflows |
| 99 | + |
| 100 | +- [Create delegation](../workflows/create-delegation.md) — create, sign, and store a delegation |
| 101 | +- [Create redelegation](../workflows/create-redelegation.md) — delegation chains with attenuated authority |
| 102 | +- [Redeem delegation — smart account](../workflows/redeem-delegation-smart-account.md) — redeem when the delegate is a smart account |
| 103 | +- [Redeem delegation — EOA](../workflows/redeem-delegation-eoa.md) — redeem when the delegate is an EOA |
| 104 | + |
0 commit comments