Skip to content

grantPermissions

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

Read more.

Usage

example.ts
import { parseEther } from 'viem'
import { account, walletClient } from './config'
 
const result = await walletClient.grantPermissions({ 
  account,
  expiry: 1716846083638,
  permissions: [
    {
      type: 'native-token-transfer',
      data: {
        ticker: 'ETH',
      },
      policies: [
        {
          type: 'token-allowance',
          data: {
            allowance: parseEther('1'),
          },
        },
      ],
    },
  ],
})

Returns

GrantPermissionsReturnType

Response from the wallet after issuing permissions.

Parameters

account

  • Type: Account | Address | undefined

The Account to scope the permissions to.

import { parseEther } from 'viem'
import { account, walletClient } from './config'
 
const result = await walletClient.grantPermissions({
  account, 
  expiry: 1716846083638,
  permissions: [
    {
      type: 'native-token-transfer',
      data: {
        ticker: 'ETH',
      },
      policies: [
        {
          type: 'token-allowance',
          data: {
            allowance: parseEther('1'),
          },
        },
      ],
    },
  ],
})

expiry

  • Type: number

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

import { parseEther } from 'viem'
import { account, walletClient } from './config'
 
const result = await walletClient.grantPermissions({
  account,
  expiry: 1716846083638, 
  permissions: [
    {
      type: 'native-token-transfer',
      data: {
        ticker: 'ETH',
      },
      policies: [
        {
          type: 'token-allowance',
          data: {
            allowance: parseEther('1'),
          },
        },
      ],
    },
  ],
})

permissions

  • Type: Permission[]

Set of Permissions & Policies to grant to the user.

import { parseEther } from 'viem'
import { account, walletClient } from './config'
 
const result = await walletClient.grantPermissions({
  account,
  expiry: 1716846083638,
  permissions: [ 
    {
      type: 'native-token-transfer',
      data: {
        ticker: 'ETH',
      },
      policies: [
        {
          type: 'token-allowance',
          data: {
            allowance: parseEther('1'),
          },
        },
      ],
    },
    { 
      type: '
native-token-transfer
erc20-token-transfer
contract-call
} ], })

signer

  • Type: Signer | undefined

Custom signer type to scope the permissions to.

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: '...'
    } 
  } 
})