namehash
Computes the namehash of an ENS name according to EIP-137
Computes the namehash of an ENS name according to EIP-137
Computes the namehash of an ENS name according to EIP-137. The namehash algorithm recursively hashes each label from right to left, starting with 32 zero bytes as the initial hash.
:::warning[Warning]
ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules. You likely want to normalize ENS names with UTS-46 normalization before passing them to namehash. You can use the Normalize function for this.
:::
import "github.com/ChefBingbong/viem-go/utils/ens"import "github.com/ChefBingbong/viem-go/utils/ens"
// Compute namehashhash := ens.Namehash("vitalik.eth")// "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
hash = ens.Namehash("eth")// "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"
// Get namehash as byteshashBytes := ens.NamehashBytes("vitalik.eth")// []byte{...}string for Namehash, []byte for NamehashBytesThe namehash as a hex string with 0x prefix (32 bytes) or raw bytes.
stringThe ENS name to compute the namehash for. Should be normalized before hashing.
// Normalize first (recommended)normalized, _ := ens.Normalize("Vitalik.ETH")hash := ens.Namehash(normalized)// "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
// Direct namehash (if already normalized)hash = ens.Namehash("vitalik.eth")The namehash algorithm:
.)Computes namehash and returns a hex string:
hash := ens.Namehash("vitalik.eth")
Computes namehash and returns raw bytes:
hashBytes := ens.NamehashBytes("vitalik.eth")
[<64 hex chars>])