Skip to content
On this page

getFunctionSelector โ€‹

Returns the function selector (4 byte encoding) for a given function definition.

Install โ€‹

ts
import { getFunctionSelector } from 'viem'

Usage โ€‹

ts
import { getFunctionSelector } from 'viem'

const selector = getFunctionSelector('function ownerOf(uint256 tokenId)')
// 0x6352211e

const selector = getFunctionSelector('ownerOf(uint256)')
// 0x6352211e

Returns โ€‹

Hex

The selector as a hex value.

Parameters โ€‹

function โ€‹

  • Type: string

The function to generate a selector for.

Released under the MIT License.