Delegation scopes
When creating a delegation, you can configure the following scopes to define the delegation's initial authority. Learn how to use delegation scopes.
Spending limit scopes
ERC-20 periodic scope
Ensures a per-period limit for ERC-20 token transfers. At the start of each new period, the allowance resets.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-20 token contract address as a hex string. |
periodAmount | bigint | Yes | The maximum amount of tokens that can be transferred per period. |
periodDuration | number | Yes | The duration of each period in seconds. |
startDate | number | Yes | The timestamp when the first period begins in seconds. |
Example
import { createDelegation, getSmartAccountsEnvironment } from "@metamask/smart-accounts-kit";
import { sepolia } from "viem/chains";
import { parseUnits } from "viem";
// Since current time is in seconds, convert milliseconds to seconds.
const startDate = Math.floor(Date.now() / 1000);
const delegation = createDelegation({
scope: {
type: "erc20PeriodTransfer",
tokenAddress: "0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da",
// 10 ERC-20 token with 6 decimals
periodAmount: parseUnits("10", 6),
periodDuration: 86400,
startDate,
},
// Address that is granting the delegation
from: "0x7E48cA6b7fe6F3d57fdd0448B03b839958416fC1",
// Address to which the delegation is being granted
to: "0x2B2dBd1D5fbeB77C4613B66e9F35dBfE12cB0488",
// Alternatively you can use environment property of MetaMask smart account.
environment: getSmartAccountsEnvironment(sepolia.id);
});
ERC-20 streaming scope
Ensures a linear streaming transfer limit for ERC-20 tokens. Token transfers are blocked until the defined start timestamp. At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tokenAddress | Address | Yes | The ERC-20 token contract address. |
initialAmount | bigint | Yes | The initial amount that can be transferred at start time. |
maxAmount | bigint | Yes | The maximum total amount that can be unlocked. |
amountPerSecond | bigint | Yes | The rate at which tokens accrue per second. |
startTime | number | Yes | The start timestamp in seconds. |