toFunctionSelector
Returns the function selector (4 byte encoding) for a given function definition.
Install
import { toFunctionSelector } from 'viem'Usage
import { } from 'viem'
const = ('function ownerOf(uint256 tokenId)')
Output: 0x6352211e const = ('ownerOf(uint256)')
Output: 0x6352211e // or from an `AbiFunction` on your contract ABI
const = ({
: 'ownerOf',
: 'function',
: [{ : 'tokenId', : 'uint256' }],
: [],
: 'view',
})
Output: 0x6352211eReturns
The selector as a hex value.
Parameters
function
- Type:
string |AbiFunction
The function to generate a selector for.