clawchain/viem/site/pages/docs/eip7702/getDelegation.md

1.6 KiB

description
description
Returns the address an account has delegated to via EIP-7702.

getDelegation

Returns the address that an account has delegated to via EIP-7702.

Usage

:::code-group

import { publicClient } from './client'

const delegation = await publicClient.getDelegation({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
})
// '0x1234...5678' or undefined
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})

:::

Return Value

Address | undefined

The address the account has delegated to, or undefined if the account is not delegated.

Parameters

address

The address to check for delegation.

const delegation = await publicClient.getDelegation({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', // [!code focus]
})

blockNumber (optional)

  • Type: bigint

The block number to check the delegation at.

const delegation = await publicClient.getDelegation({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockNumber: 15121123n, // [!code focus]
})

blockTag (optional)

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
  • Default: 'latest'

The block tag to check the delegation at.

const delegation = await publicClient.getDelegation({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockTag: 'safe', // [!code focus]
})