Skip to main content

Try it Live

Run ENS examples in the interactive playground

ENS Usage Patterns

All examples import the module as a namespace:

Parse user input

Normalize once, reject empty input, and keep the normalized value for everything downstream.

Validate a form field

Use isValid() for a yes/no check, such as enabling a submit button. It accepts names that are valid but not normalized.
Normalize the value again on submit; isValid() does not return the canonical form.

Compute a registry node

The ENS registry and resolvers key records by namehash.
Pass node as the bytes32 node argument of resolver(node), addr(node), or text(node, key). The ENS Resolution skill shows the contract calls.

Compute a labelhash

The .eth registrar uses the labelhash of the second-level label as the ERC-721 token ID.
labelhash does not split on dots. Pass one label, not a full name.

Verify the namehash recursion

namehash(label.parent) = keccak256(namehash(parent) ‖ labelhash(label)):

Reverse record node

Reverse records live under <address-hex-without-0x, lowercase>.addr.reverse.
After reading the name from the reverse resolver, normalize it and resolve it forward. Accept it only if the forward address matches.

Display a name

Hash normalize() output. Show beautify() output.

Compare names

Compare normalized strings. Raw strings give false negatives.

Narrow unknown input

is() narrows unknown to Ens when the value is a non-empty string. Normalize afterwards; is() does not validate.

Inject a keccak256 implementation

The Namehash and Labelhash factories take keccak256 as a dependency. Use them to share one hash implementation across your app or to swap in WASM.
See WASM for the WASM keccak256 variant.

See Also