Skip to content
LogoLogo

Get Access Key Metadata

accessKey.getMetadata

Gets the metadata for an access key.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
 
.('Access key metadata:', )
Access key metadata: { address: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb', expiry: 1735689600n, isRevoked: false, keyType: 'secp256k1', spendPolicy: 'limited' }

Recipes

Confirm a Billing Key Before Charging

Check isRevoked and expiry on a stored key before a server-side charge, and re-authorize instead of submitting a transaction that will revert.

import {  } from './viem.config'
 
const  = await ..({
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb', // subscriber
  : '0x8ba1f109551bD432803012645Ac136ddd64DBA72', // billing key
})
 
const  = (.(.() / 1000))
if (. || . <= )
  throw new ('billing key inactive: re-authorize before charging')

Flag Keys Without Spending Limits

Use spendPolicy to surface active keys that have no spending cap during a periodic security review.

import {  } from './viem.config'
 
const  = [
  '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
  '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
] as 
 
const  = []
for (const  of ) {
  const  = await ..({  })
  if (. === 'unlimited' && !.)
    .(.)
}
 
.('Keys without limits:', )
Keys without limits: ['0x8ba1f109551bD432803012645Ac136ddd64DBA72']

Return Value

type ReturnType = {
  /** Access key address. */
  address: Address
  /** Unix timestamp when the key expires. */
  expiry: bigint
  /** Whether the key is revoked. */
  isRevoked: boolean
  /** Key type. */
  keyType: 'secp256k1' | 'p256' | 'webAuthn'
  /** Spending policy. */
  spendPolicy: 'limited' | 'unlimited'
}

The access key metadata.

Parameters

accessKey

  • Type: Address | AccessKeyAccount

Access key to read the metadata of. Pass an access key address or an access key account.

account

  • Type: Account | Address
  • Default: client.account

Account (or address) that owns the key.

blockNumber (optional)

  • Type: bigint

Block number to read the state from.

blockOverrides (optional)

  • Type: BlockOverrides

Block overrides to apply to the state.

blockTag (optional)

  • Type: BlockTag

Block tag to read the state from.

stateOverride (optional)

  • Type: StateOverride

State override to apply.