Skip to content

toEventHash

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

Install

import { toEventHash } from 'viem'

Usage

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

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

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

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

toEventHash
('event Transfer(address,address,uint256)')
Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
const
const hash_2: `0x${string}`
hash_2
=
function toEventHash(fn: string | AbiFunction | AbiEvent): `0x${string}`

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

toEventHash
({
name: string
name
: 'Transfer',
type: "event"
type
: 'event',
inputs: readonly AbiEventParameter[]
inputs
: [
{
name: string
name
: 'from',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: string
name
: 'to',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: string
name
: 'amount',
type: "uint256"
type
: 'uint256',
indexed: false
indexed
: false },
], })
Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

Returns

Hex

The hash of the event signature.

Parameters

event

The event to generate a hash for.