Skip to main content

Use approval revocation permission

Advanced Permissions (ERC-7715) supports the token approval revocation permission type that allows you to request permission to revoke existing token approvals on behalf of the user.

Prerequisites

Token approval revocation permission

This permission type enables revoking existing token approvals on behalf of the user.

For example, a user signs an ERC-7715 permission that lets a dapp revoke any ERC-20 token allowances periodically, or during an ongoing exploit.

See the token approval revocation permission API reference for more information.

import { sepolia as chain } from 'viem/chains'
import { walletClient } from './client.ts'

// Since current time is in seconds, convert milliseconds to seconds.
const currentTime = Math.floor(Date.now() / 1000)

// 30 days from now.
const expiry = currentTime + 60 * 60 * 24 * 30

const grantedPermissions = await walletClient.requestExecutionPermissions([
{
chainId: chain.id,
expiry,
// The requested permissions will be granted to the
// session account.
to: sessionAccount.address,
permission: {
type: 'token-approval-revocation',
data: {
erc20Approve: true,
erc721Approve: false,
erc721SetApprovalForAll: false,
permit2Approve: true,
permit2Lockdown: false,
permit2InvalidateNonces: false,
justification: 'Permission to revoke ERC-20 token approvals',
},
isAdjustmentAllowed: false,
},
},
])