Skip to content

toFunctionHash

Returns the hash (of the function signature) for a given function definition.

Install

import { toFunctionHash } from 'viem'

Usage

import { 
function toFunctionHash(fn: string | AbiFunction | AbiEvent): `0x${string}`

Returns the hash (of the function/event signature) for a given event or function definition.

toFunctionHash
} from 'viem'
const
const hash_1: `0x${string}`
hash_1
=
function toFunctionHash(fn: string | AbiFunction | AbiEvent): `0x${string}`

Returns the hash (of the function/event signature) for a given event or function definition.

toFunctionHash
('function ownerOf(uint256)')
Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
// or from an `AbiEvent` on your contract ABI const
const hash_2: `0x${string}`
hash_2
=
function toFunctionHash(fn: string | AbiFunction | AbiEvent): `0x${string}`

Returns the hash (of the function/event signature) for a given event or function definition.

toFunctionHash
({
name: string
name
: 'ownerOf',
type: "function"
type
: 'function',
inputs: readonly AbiParameter[]
inputs
: [{
name: string
name
: 'tokenId',
type: "uint256"
type
: 'uint256' }],
outputs: readonly AbiParameter[]
outputs
: [],
stateMutability: AbiStateMutability
stateMutability
: 'view',
})
Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

Returns

Hex

The hash of the function signature.

Parameters

function

The function to generate a hash for.