Skip to content
On this page

getEventSelector โ€‹

Returns the event selector for a given event definition.

Install โ€‹

ts
import { getEventSelector } from 'viem'

Usage โ€‹

ts
import { getEventSelector } from 'viem'

const selector = getEventSelector('Transfer(address,address,uint256)')
// 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

const selector = getEventSelector('Transfer(address indexed from, address indexed to, uint256 amount)')
// 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

// or from an `AbiEvent` on your contract ABI
const selector = getEventSelector({
  name: 'Transfer',
  type: 'event',
  inputs: [
    { name: 'from', type: 'address', indexed: true },
    { name: 'to', type: 'address', indexed: true },
    { name: 'amount', type: 'uint256', indexed: false },
  ],
})
// 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

Returns โ€‹

Hex

The selector as a hex value.

Parameters โ€‹

event โ€‹

The event to generate a selector for.

Released under the MIT License.