Skip to content

AbiItem.getSelector

Computes the 4-byte selector for an AbiItem.AbiItem.

Useful for computing function selectors for calldata.

Imports

Named
import { AbiItem } from 'ox'

Examples

import { AbiItem } from 'ox'
 
const selector = AbiItem.getSelector('function ownerOf(uint256 tokenId)')
'0x6352211e'
import { AbiItem } from 'ox'
 
const selector = AbiItem.getSelector({
  inputs: [{ type: 'uint256' }],
  name: 'ownerOf',
  outputs: [],
  stateMutability: 'view',
  type: 'function'
})
'0x6352211e'

Definition

function getSelector(
  abiItem: string | AbiItem,
): Hex.Hex

Source: src/AbiItem.ts

Parameters

abiItem

  • Type: string | AbiItem

The ABI item to compute the selector for. Can be a signature or an ABI item for an error, event, function, etc.

Return Type

The first 4 bytes of the Hash.keccak256 hash of the function signature.

Hex.Hex

Error Type

AbiItem.getSelector.ErrorType