Skip to content

toEventSelector

Returns the event selector for a given event definition.

Install

import { toEventSelector } from 'viem'

Usage

import { 
const toEventSelector: (fn: string | AbiFunction | AbiEvent) => `0x${string}`

Returns the event selector for a given event definition.

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

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

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

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

toEventSelector
('Transfer(address indexed from, address indexed to, uint256 amount)')
Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
// or from an `AbiEvent` on your contract ABI const
const selector_3: `0x${string}`
selector_3
=
function toEventSelector(fn: string | AbiFunction | AbiEvent): `0x${string}`

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

toEventSelector
({
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 selector as a hex value.

Parameters

event

The event to generate a selector for.