viem-goviem-go

normalizeSignature

Normalizes a function or event signature by removing parameter names and unnecessary whitespace

normalizeSignature

Normalizes a function or event signature by removing parameter names, indexed keywords, and unnecessary whitespace, keeping only the types.

Import

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

Usage

import "github.com/ChefBingbong/viem-go/utils/hash"
// Normalize function signature
sig, _ := hash.NormalizeSignature("function transfer(address to, uint256 amount)")
// "transfer(address,uint256)"
// Normalize event signature
sig, _ = hash.NormalizeSignature("event Transfer(address indexed from, address indexed to, uint256 amount)")
// "Transfer(address,address,uint256)"
// Normalize without function/event keyword
sig, _ = hash.NormalizeSignature("ownerOf(uint256 tokenId)")
// "ownerOf(uint256)"

Returns

  • Type: (string, error)

The normalized signature string with parameter names and whitespace removed.

Parameters

signature (required)

  • Type: string

The function or event signature to normalize.

sig, _ := hash.NormalizeSignature("function transfer(address to, uint256 amount)")
// "transfer(address,uint256)"
sig, _ = hash.NormalizeSignature("event Transfer(address indexed from, address indexed to, uint256 amount)")
// "Transfer(address,address,uint256)"

Notes

  • Removes the function and event keywords
  • Removes parameter names (keeps only types)
  • Removes indexed keywords from event parameters
  • Removes unnecessary whitespace
  • Used internally by ToFunctionSelector, ToEventSelector, and other hash functions