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 { Abi, AbiItem } from 'ox'
const erc20Abi = Abi.from([...])
const selector = AbiItem.getSelector(erc20Abi, 'ownerOf')
'0x6352211e'
import { AbiItem } from 'ox'
const selector = AbiItem.getSelector({
inputs: [{ type: 'uint256' }],
name: 'ownerOf',
outputs: [],
stateMutability: 'view',
type: 'function'
})
'0x6352211e'
Definition
function getSelector<abi, name>(
abi: abi | Abi.Abi | readonly unknown[],
name: name,
): Hex.Hex
Source: src/core/AbiItem.ts
Parameters
abi
- Type:
abi | Abi.Abi | readonly unknown[]
name
- Type:
name
Return Type
The first 4 bytes of the Hash.keccak256
hash of the function signature.
Hex.Hex