You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
639 B

import type { AbiFunction } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import { type SliceErrorType, slice } from '../data/slice.js'
import {
type ToSignatureHashErrorType,
toSignatureHash,
} from './toSignatureHash.js'
export type ToFunctionSelectorErrorType =
| ToSignatureHashErrorType
| SliceErrorType
| ErrorType
/**
* Returns the function selector for a given function definition.
*
* @example
* const selector = toFunctionSelector('function ownerOf(uint256 tokenId)')
* // 0x6352211e
*/
export const toFunctionSelector = (fn: string | AbiFunction) =>
slice(toSignatureHash(fn), 0, 4)