getAbiItem โ
Retrieves an item from the ABI.
Import โ
ts
import { getAbiItem } from 'viem'
Usage โ
ts
import { getAbiItem } from 'viem'
const encodedData = getAbiItem({
  abi: [
    { 
      name: 'x', 
      type: 'function', 
      inputs: [{ type: 'uint256' }], 
      outputs: [],
      stateMutability: 'payable'
    },
    { 
      name: 'y', 
      type: 'event', 
      inputs: [{ type: 'address' }], 
      outputs: [{ type: 'uint256' }],
      stateMutability: 'view'
    },
    { 
      name: 'z', 
      type: 'function', 
      inputs: [{ type: 'string' }],
      outputs: [{ type: 'uint256' }],
      stateMutability: 'view'
    }
  ],
  name: 'y',
})
/**
 * { 
 *  name: 'y', 
 *  type: 'event', 
 *  inputs: [{ type: 'address' }], 
 *  outputs: [{ type: 'uint256' }],
 *  stateMutability: 'view'
 * }
 */
Returns โ
AbiItem
The ABI item.
Parameters โ
abi โ
- Type: 
Abi 
The contract's ABI.
ts
const encodedData = getAbiItem({
  abi: [...], 
  name: 'x',
})
name โ
- Type: 
string 
Name of the ABI item to extract.
ts
const encodedData = getAbiItem({
  abi: [...],
  name: 'x', 
})
args (optional) โ
- Type: Inferred.
 
Optional arguments to identify function overrides.
ts
const encodedData = getAbiItem({
  abi: [...],
  name: 'y',
  args: ['0x0000000000000000000000000000000000000000'], 
})