viem-goviem-go

toEventHash

Returns the full keccak256 hash of an event signature

toEventHash

Returns the full keccak256 hash of an event signature. This is an alias for ToSignatureHash specifically for event definitions.

Import

import "github.com/ChefBingbong/viem-go/utils/hash"

Usage

import "github.com/ChefBingbong/viem-go/utils/hash"
// Get full event hash
hash, _ := hash.ToEventHash("event Transfer(address indexed from, address indexed to, uint256 amount)")
// "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
// Get hash as bytes
hashBytes, _ := hash.ToEventHashBytes("event Transfer(address,address,uint256)")
// []byte{0xdd, 0xf2, 0x52, ...}

Returns

  • Type: (string, error) for ToEventHash, ([]byte, error) for ToEventHashBytes

The full 32-byte keccak256 hash of the event signature. ToEventHash returns a hex string with 0x prefix, ToEventHashBytes returns raw bytes.

Parameters

event (required)

  • Type: string

The event definition string.

hash, _ := hash.ToEventHash("event Transfer(address,address,uint256)")
// "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"

Functions

ToEventHash

Returns the full hash as a hex string:

hash, _ := hash.ToEventHash("event Transfer(address,address,uint256)")
// "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"

ToEventHashBytes

Returns the full hash as raw 32 bytes:

hashBytes, _ := hash.ToEventHashBytes("event Transfer(address,address,uint256)")
// []byte{0xdd, 0xf2, 0x52, ...}

Notes

  • This is equivalent to ToEventSelector and ToSignatureHash for event definitions
  • The event signature is normalized before hashing
  • This hash is used as topic0 in event logs