Skip to content
LogoLogo

wallet_grantPermissions

Grant granular permissions to a spender address for delegated transaction execution with spending limits and call restrictions.

Authentication Required: No

Request

import { parseEther } from 'viem';
 
await jaw.provider.request({
  method: 'wallet_grantPermissions',
  params: [
    {
      expiry: 1735689600, // Unix timestamp
      spender: '0x5678...', // Who gets permissions
      permissions: {
        calls: [
          {
            target: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
            functionSignature: 'transfer(address,uint256)',
          },
        ],
        spends: [
          {
            token: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
            allowance: parseEther('0.1').toString(), // 0.1 ETH
            unit: 'day',
          },
        ],
      },
      note: 'Pays your 0.1 ETH daily subscription', // Optional - shown to the user, not signed
      // chainId: '0x1', // Optional - defaults to connected chain
    },
  ],
});

Parameters

NameTypeRequiredDescription
expirynumberYesExpiration timestamp (seconds)
spender0x${string}YesAddress receiving permissions
permissionsobjectYesPermission details
address0x${string}NoAccount address to grant permissions on
chainId0x${string}NoTarget chain ID (defaults to connected chain)
notestringNoWhat the permission is for (see below)
capabilitiesobjectNoAdditional capabilities (see below)

Note

note says what the permission is for, in your app's words, so the user and an agent can tell later why it exists. The grant and revoke screens show it, and wallet_getPermissions returns it.

  • Plain text on one line, at most 200 characters. Spaces around it are trimmed, and an empty note counts as none.
  • A note with a newline, a tab, a control character, or a character that doesn't show on screen (zero-width, bidi, variation and other default-ignorable characters) is refused with -32602. A single emoji selector is fine, so notes with emoji work.
  • It is not signed and not part of the permission hash. It is stored next to the permission, set once when it is granted, and never changed.

Capabilities

NameTypeDescription
capabilities.paymasterServiceobjectPaymaster service for gas sponsorship
capabilities.paymasterService.urlstringPaymaster service URL (ERC-7677 compliant)
capabilities.paymasterService.contextobjectOptional context (e.g., { sponsorshipPolicyId: '...' })

Permission Details

calls

Array of call permissions. Each permission:

NameTypeRequiredDescription
target0x${string}YesContract address
functionSignaturestringNo*Function signature (e.g., "transfer(address,uint256)")
selector0x${string}No*4-byte function selector (0x...)
checker0x${string}NoContract that must approve each matching call

*Either functionSignature or selector is required.

A checker is a contract the permission manager calls with canExecute before every call this rule matches, so it can check the call's arguments as well as the function. It is part of the permission hash and is shown on the grant screen. Leave it out for no checker. The response always includes it, as the zero address when none was set, so the permission can be rebuilt from the response alone.

spends (Optional*)

Array of spend limits. Each limit:

NameTypeRequiredDescription
token0x${string}YesToken address (0xEeee... for native token)
allowancestringYesSpending allowance in wei (decimal or hex string)
unitstringYesTime unit for allowance reset
multipliernumberNoMultiplier for the time unit (default: 1)

Valid Units:

  • minute - Resets every minute
  • hour - Resets every hour
  • day - Resets every day
  • week - Resets every week
  • month - Resets every month
  • year - Resets every year
  • forever - Never resets (one-time allowance)

*Spend Limits are required if moving funds.

Response

Returns permission grant result with generated permission ID.

{
  "account": "0x1234567890123456789012345678901234567890",
  "spender": "0x5678901234567890123456789012345678901234",
  "start": 1704067200,
  "end": 1735689600,
  "salt": "0x1a2b3c...",
  "calls": [
    {
      "target": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "selector": "0xa9059cbb",
      "checker": "0x0000000000000000000000000000000000000000"
    }
  ],
  "spends": [
    {
      "token": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
      "allowance": "0x16345785d8a0000",
      "unit": "day",
      "multiplier": 1
    }
  ],
  "permissionId": "0xabc123...",
  "chainId": "0x1",
  "note": "Pays your 0.1 ETH daily subscription"
}

note is the note as stored, and is left out when the request had none.

Behavior

  • Opens popup for user approval
  • Approves permission
  • Returns permission ID for future revocation

Errors

CodeDescription
4001User rejected the request
4100Unauthorized (not authenticated)
-32602Invalid params

Example

import { parseUnits } from 'viem';
 
// Allow DeFi protocol to swap USDC with daily limit
const permission = await jaw.provider.request({
  method: 'wallet_grantPermissions',
  params: [
    {
      expiry: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60, // 1 year
      spender: dexRouterAddress,
      permissions: {
        calls: [
          {
            target: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
            functionSignature: 'approve(address,uint256)',
          },
          {
            target: dexRouterAddress,
            functionSignature: 'swap(address,address,uint256,uint256)',
          },
        ],
        spends: [
          {
            token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
            allowance: parseUnits('1000', 6).toString(), // 1000 USDC per day
            unit: 'day',
          },
        ],
      },
      // chainId: '0x1', // Optional - defaults to connected chain
    },
  ],
});