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: stringname: 'Transfer',
type: "event"type: 'event',
inputs: readonly AbiEventParameter[]inputs: [
{ name: stringname: 'from', type: "address"type: 'address', indexed: trueindexed: true },
{ name: stringname: 'to', type: "address"type: 'address', indexed: trueindexed: true },
{ name: stringname: 'amount', type: "uint256"type: 'uint256', indexed: falseindexed: false },
],
})Output: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
Returns
The selector as a hex value.
Parameters
event
- Type:
string |
AbiEvent
The event to generate a selector for.