Skip to content

AbiFunction.getSelector

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

Useful for computing function selectors for calldata.

Imports

Named
import { AbiFunction } from 'ox'

Examples

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

Definition

function getSelector(
  abiItem: AbiFunction.AbiFunction,
): Hex.Hex

Source: src/core/AbiFunction.ts

Parameters

abiItem

The ABI item to compute the selector for.

abiItem.hash

  • Type: 0x${string}
  • Optional

abiItem.overloads

  • Type: readonly any[]
  • Optional

Return Type

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

Hex.Hex