For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

Advanced Permissions reference

When executing on a MetaMask user's behalf, you can request the following permission types. Learn how to use Advanced Permissions types.

ERC-20 token permissions​

ERC-20 allowance permission​

Ensures a fixed ERC-20 token allowance. Transfers are allowed until the total transferred amount reaches the allowance amount.

Parameters​

NameTypeRequiredDescription
tokenAddressAddressYesThe ERC-20 token contract address.
allowanceAmountbigintYesThe maximum total amount of tokens that can be transferred.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseUnits } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'erc20-token-allowance',
data: {
tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
allowanceAmount: parseUnits('50', 6),
startTime: currentTime,
justification: 'Permission to transfer up to 50 USDC in total',
},
isAdjustmentAllowed: true,
}

ERC-20 periodic permission​

Ensures a per-period limit for ERC-20 token transfers. At the start of each new period, the allowance resets.

Parameters​

NameTypeRequiredDescription
tokenAddressAddressYesThe ERC-20 token contract address as a hex string.
periodAmountbigintYesThe maximum amount of tokens that can be transferred per period.
periodDurationnumberYesThe duration of each period in seconds.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseUnits } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'erc20-token-periodic',
data: {
tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
periodAmount: parseUnits('10', 6),
periodDuration: 86400,
justification: 'Permission to transfer 10 USDC every day',
},
isAdjustmentAllowed: true,
}

ERC-20 stream permission​

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​

NameTypeRequiredDescription
tokenAddressAddressYesThe ERC-20 token contract address.
initialAmountbigintNoThe initial amount that can be transferred at start time. The default is 0.
maxAmountbigintNoThe maximum total amount that can be unlocked. The default is no limit.
amountPerSecondbigintYesThe rate at which tokens accrue per second.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseUnits } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'erc20-token-stream',
data: {
tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
amountPerSecond: parseUnits('0.1', 6),
initialAmount: parseUnits('1', 6),
maxAmount: parseUnits('2', 6),
startTime: currentTime,
justification: 'Permission to use 0.1 USDC per second',
},
isAdjustmentAllowed: true,
}

Native token permissions​

Native token allowance permission​

Ensures a fixed native token allowance. Transfers are allowed until the total transferred amount reaches the allowance amount.

Parameters​

NameTypeRequiredDescription
allowanceAmountbigintYesThe maximum total amount of tokens that can be transferred.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseEther } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'native-token-allowance',
data: {
allowanceAmount: parseEther('0.05'),
startTime: currentTime,
justification: 'Permission to transfer up to 0.05 ETH in total',
},
isAdjustmentAllowed: true,
}

Native token periodic permission​

Ensures a per-period limit for native token transfers. At the start of each new period, the allowance resets.

Parameters​

NameTypeRequiredDescription
periodAmountbigintYesThe maximum amount of tokens that can be transferred per period.
periodDurationnumberYesThe duration of each period in seconds.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseEther } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'native-token-periodic',
data: {
periodAmount: parseEther('0.001'),
periodDuration: 86400,
startTime: currentTime,
justification: 'Permission to use 0.001 ETH every day',
},
isAdjustmentAllowed: true,
}

Native token stream permission​

Ensures a linear streaming transfer limit for native 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​

NameTypeRequiredDescription
initialAmountbigintNoThe initial amount that can be transferred at start time. The default is 0.
maxAmountbigintNoThe maximum total amount that can be unlocked. The default is no limit.
amountPerSecondbigintYesThe rate at which tokens accrue per second.
startTimenumberNoThe start timestamp in seconds. The default is the current time.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

import { parseEther } from 'viem'

const currentTime = Math.floor(Date.now() / 1000)
const expiry = currentTime + 604800

const permission = {
type: 'native-token-stream',
data: {
amountPerSecond: parseEther('0.0001'),
initialAmount: parseEther('0.1'),
maxAmount: parseEther('1'),
startTime: currentTime,
justification: 'Permission to use 0.0001 ETH per second',
},
isAdjustmentAllowed: true,
}

Token approval revocation permission​

Enables revoking an existing token approvals on behalf of the user.

Parameters​

NameTypeRequiredDescription
erc20ApprovebooleanYesWhether to allow revoking ERC-20 allowances.
erc721ApprovebooleanYesWhether to allow revoking ERC-721 per-token approvals.
erc721SetApprovalForAllbooleanYesWhether to allow revoking ERC-721 and ERC-1155 operator approvals.
permit2ApprovebooleanYesWhether to allow revoking Permit2 approvals.
permit2LockdownbooleanYesWhether to allow locking down Permit2.
permit2InvalidateNoncesbooleanYesWhether to allow invalidating Permit2.
justificationstringNoA human-readable explanation of why the permission is being requested.

Example​

const permission = {
type: 'token-approval-revocation',
data: {
erc20Approve: true,
erc721Approve: true,
erc721SetApprovalForAll: true,
permit2Approve: false,
permit2Lockdown: false,
permit2InvalidateNonces: false,
justification: 'Permission to revoke ERC-20, ERC-721, and ERC-115 token approvals',
},
isAdjustmentAllowed: false,
}