Skip to content
LogoLogo

grantPermissions

Request permissions from a wallet to perform actions on behalf of a user.

Read more.

Usage

import {  } from 'viem'
import { ,  } from './config'
 
const  = await .({ 
  ,
  : 1716846083638,
  : [
    {
      : 'native-token-transfer',
      : {
        : 'ETH',
      },
      : [
        {
          : 'token-allowance',
          : {
            : ('1'),
          },
        },
      ],
    },
  ],
})

Returns

GrantPermissionsReturnType

Response from the wallet after issuing permissions.

Parameters

account

  • Type: Account | Address | undefined

The Account to scope the permissions to.

import {  } from 'viem'
import { ,  } from './config'
 
const  = await .({
  , 
  : 1716846083638,
  : [
    {
      : 'native-token-transfer',
      : {
        : 'ETH',
      },
      : [
        {
          : 'token-allowance',
          : {
            : ('1'),
          },
        },
      ],
    },
  ],
})

expiry

  • Type: number

The timestamp (in seconds) when the permissions will expire.

import {  } from 'viem'
import { ,  } from './config'
 
const  = await .({
  ,
  : 1716846083638, 
  : [
    {
      : 'native-token-transfer',
      : {
        : 'ETH',
      },
      : [
        {
          : 'token-allowance',
          : {
            : ('1'),
          },
        },
      ],
    },
  ],
})

permissions

  • Type: Permission[]

Set of Permissions & Policies to grant to the user.

import {  } from 'viem'
import { ,  } from './config'
 
const  = await .({
  ,
  : 1716846083638,
  : [ 
    {
      : 'native-token-transfer',
      : {
        : 'ETH',
      },
      : [
        {
          : 'token-allowance',
          : {
            : ('1'),
          },
        },
      ],
    },
    { 
      : '  
    } 
  ], 
})

signer

  • Type: Signer | undefined

Custom signer type to scope the permissions to.

// @filename: config.ts
import 'viem/window'
// ---cut---
import { createWalletClient, custom } from 'viem'
import { mainnet } from 'viem/chains'
import { erc7715Actions } from 'viem/experimental'
 
export const walletClient = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum!),
}).extend(erc7715Actions())
 
export const [account] = await walletClient.getAddresses()
// @filename: example.ts
// ---cut---
import { parseEther } from 'viem'
import { account, walletClient } from './config'
 
const result = await walletClient.grantPermissions({
  expiry: 1716846083638,
  permissions: [ 
    { 
      type: 'native-token-limit', 
      data: { 
        amount: parseEther('0.5'), 
      }, 
      required: true, 
    }, 
  ], 
  signer: { 
    type: 'key', 
    data: { 
      id: '...'
    } 
  } 
})