Onchain.ENS (onchain v0.5.4)

Copy Markdown View Source

ENS (Ethereum Name Service) resolution and namehash computation.

Does

  • Compute EIP-137 namehash for ENS names (namehash/1)
  • Normalize names (lowercase ASCII, strip trailing dot)
  • Validate name structure (reject empty labels, non-ASCII)
  • Forward resolution: ENS name → ETH address (resolve/2)
  • Reverse resolution: ETH address → ENS name (reverse/2)
  • Text record queries (text/3), contenthash, ABI, pubkey retrieval
  • Look up resolver contracts (resolver/2)
  • Configurable registry address via :registry opt

Does Not

  • CCIP-Read / EIP-3668 off-chain lookups (future enhancement)
  • Wildcard resolution (ENSIP-10)
  • ENS name registration or management (write operations)
  • Full UTS-46 / ENSIP-15 Unicode normalization (internationalized names)
  • Caching — consumers manage their own cache
  • Multi-coin address resolution (only ETH via addr(bytes32))

Functions

FunctionPurpose
namehash/1ENS name -> 32-byte EIP-137 node hash
namehash!/1Same, raises on error
resolver/2ENS name -> resolver contract address
resolver!/2Same, raises on error
resolve/2ENS name -> ETH address (forward resolution)
resolve!/2Same, raises on error
reverse/2ETH address -> ENS name (reverse resolution)
reverse!/2Same, raises on error
text/3Retrieve a text record (avatar, url, etc.)
text!/3Same, raises on error
contenthash/2Retrieve the contenthash record
contenthash!/2Same, raises on error
pubkey/2Retrieve the ECDSA public key
pubkey!/2Same, raises on error
abi/3Retrieve ABI data (ENSIP-7)
abi!/3Same, raises on error

API Functions

FunctionArityDescriptionParam Kinds
abi!3Retrieve ABI data. Raises on error.name: value, content_types: value, opts: value
abi3Retrieve ABI data from an ENS name's resolver (ENSIP-7).name: value, content_types: value, opts: value
pubkey!2Retrieve the ECDSA public key. Raises on error.name: value, opts: value
pubkey2Retrieve the ECDSA public key from an ENS name's resolver.name: value, opts: value
contenthash!2Retrieve the contenthash record. Raises on error.name: value, opts: value
contenthash2Retrieve the contenthash record from an ENS name's resolver.name: value, opts: value
text!3Retrieve a text record. Raises on error.name: value, key: value, opts: value
text3Retrieve a text record from an ENS name's resolver.name: value, key: value, opts: value
reverse!2Reverse-resolve an ETH address to an ENS name. Raises on error.address: value, opts: value
reverse2Reverse-resolve an ETH address to an ENS name.address: value, opts: value
resolve!2Resolve an ENS name to an ETH address. Raises on error.name: value, opts: value
resolve2Resolve an ENS name to an ETH address (forward resolution).name: value, opts: value
resolver!2Look up the resolver contract address. Raises on error.name: value, opts: value
resolver2Look up the resolver contract address for an ENS name.name: value, opts: value
namehash!1Compute the EIP-137 namehash. Raises on error.name: value
namehash1Compute the EIP-137 namehash for an ENS name.name: value

Summary

Functions

Retrieve ABI data from an ENS name's resolver (ENSIP-7).

Retrieve ABI data. Raises on error.

Retrieve the contenthash record from an ENS name's resolver.

Retrieve the contenthash record. Raises on error.

Compute the EIP-137 namehash for an ENS name.

Compute the EIP-137 namehash. Raises on error.

Retrieve the ECDSA public key from an ENS name's resolver.

Retrieve the ECDSA public key. Raises on error.

Resolve an ENS name to an ETH address (forward resolution).

Resolve an ENS name to an ETH address. Raises on error.

Look up the resolver contract address for an ENS name.

Look up the resolver contract address. Raises on error.

Reverse-resolve an ETH address to an ENS name.

Reverse-resolve an ETH address to an ENS name. Raises on error.

Retrieve a text record from an ENS name's resolver.

Retrieve a text record. Raises on error.

Functions

abi(name, content_types, opts \\ [])

@spec abi(String.t(), non_neg_integer(), keyword()) ::
  {:ok, {non_neg_integer(), binary()}} | {:error, term()}

Retrieve ABI data from an ENS name's resolver (ENSIP-7).

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • content_types - Bitmask of content types: 1=JSON, 2=zlib, 4=CBOR, 8=URI (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Tuple of {content_type, abi_data} ({:ok, {non_neg_integer(), binary()}} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    content_types: %{
      description: "Bitmask of content types: 1=JSON, 2=zlib, 4=CBOR, 8=URI",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, {non_neg_integer(), binary()}} | {:error, term()}",
    description: "Tuple of {content_type, abi_data}"
  }
}

abi!(name, content_types, opts \\ [])

@spec abi!(String.t(), non_neg_integer(), keyword()) :: {non_neg_integer(), binary()}

Retrieve ABI data. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • content_types - Bitmask of content types: 1=JSON, 2=zlib, 4=CBOR, 8=URI (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Tuple of {content_type, abi_data} ({non_neg_integer(), binary()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    content_types: %{
      description: "Bitmask of content types: 1=JSON, 2=zlib, 4=CBOR, 8=URI",
      kind: :value
    }
  },
  returns: %{
    type: "{non_neg_integer(), binary()}",
    description: "Tuple of {content_type, abi_data}"
  }
}

contenthash(name, opts \\ [])

@spec contenthash(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Retrieve the contenthash record from an ENS name's resolver.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Raw contenthash bytes (ENSIP-7 encoded) ({:ok, binary()} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, binary()} | {:error, term()}",
    description: "Raw contenthash bytes (ENSIP-7 encoded)"
  }
}

contenthash!(name, opts \\ [])

@spec contenthash!(
  String.t(),
  keyword()
) :: binary()

Retrieve the contenthash record. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Raw contenthash bytes (binary())

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{type: "binary()", description: "Raw contenthash bytes"}
}

namehash(name)

@spec namehash(String.t()) :: {:ok, binary()} | {:error, {:invalid_name, String.t()}}

Compute the EIP-137 namehash for an ENS name.

Parameters

  • name - ENS name, e.g. "vitalik.eth" (value)

Returns

32-byte keccak256 node hash per EIP-137 ({:ok, <<_::256>>} | {:error, term})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name, e.g. \"vitalik.eth\"", kind: :value}
  },
  returns: %{
    type: "{:ok, <<_::256>>} | {:error, term}",
    description: "32-byte keccak256 node hash per EIP-137"
  }
}

namehash!(name)

@spec namehash!(String.t()) :: binary()

Compute the EIP-137 namehash. Raises on error.

Parameters

  • name - ENS name, e.g. "vitalik.eth" (value)

Returns

32-byte keccak256 node hash (<<_::256>>)

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name, e.g. \"vitalik.eth\"", kind: :value}
  },
  returns: %{type: "<<_::256>>", description: "32-byte keccak256 node hash"}
}

pubkey(name, opts \\ [])

@spec pubkey(
  String.t(),
  keyword()
) :: {:ok, {binary(), binary()}} | {:error, term()}

Retrieve the ECDSA public key from an ENS name's resolver.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Tuple of {x, y} 32-byte coordinates ({:ok, {binary(), binary()}} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, {binary(), binary()}} | {:error, term()}",
    description: "Tuple of {x, y} 32-byte coordinates"
  }
}

pubkey!(name, opts \\ [])

@spec pubkey!(
  String.t(),
  keyword()
) :: {binary(), binary()}

Retrieve the ECDSA public key. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Tuple of {x, y} 32-byte coordinates ({binary(), binary()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "{binary(), binary()}",
    description: "Tuple of {x, y} 32-byte coordinates"
  }
}

resolve(name, opts \\ [])

@spec resolve(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Resolve an ENS name to an ETH address (forward resolution).

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

EIP-55 checksummed ETH address ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "EIP-55 checksummed ETH address"
  }
}

resolve!(name, opts \\ [])

@spec resolve!(
  String.t(),
  keyword()
) :: String.t()

Resolve an ENS name to an ETH address. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

EIP-55 checksummed ETH address (String.t())

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{type: "String.t()", description: "EIP-55 checksummed ETH address"}
}

resolver(name, opts \\ [])

@spec resolver(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Look up the resolver contract address for an ENS name.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

EIP-55 checksummed resolver address ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "EIP-55 checksummed resolver address"
  }
}

resolver!(name, opts \\ [])

@spec resolver!(
  String.t(),
  keyword()
) :: String.t()

Look up the resolver contract address. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

EIP-55 checksummed resolver address (String.t())

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    }
  },
  returns: %{
    type: "String.t()",
    description: "EIP-55 checksummed resolver address"
  }
}

reverse(address, opts \\ [])

@spec reverse(
  String.t() | binary(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Reverse-resolve an ETH address to an ENS name.

Parameters

  • address - ETH address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

ENS name (e.g., "vitalik.eth") ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    address: %{
      description: "ETH address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "ENS name (e.g., \"vitalik.eth\")"
  }
}

reverse!(address, opts \\ [])

@spec reverse!(
  String.t() | binary(),
  keyword()
) :: String.t()

Reverse-resolve an ETH address to an ENS name. Raises on error.

Parameters

  • address - ETH address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

ENS name (e.g., "vitalik.eth") (String.t())

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    address: %{
      description: "ETH address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{
    type: "String.t()",
    description: "ENS name (e.g., \"vitalik.eth\")"
  }
}

text(name, key, opts \\ [])

@spec text(String.t(), String.t(), keyword()) :: {:ok, String.t()} | {:error, term()}

Retrieve a text record from an ENS name's resolver.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • key - Text record key (e.g., "avatar", "url", "com.twitter") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Text record value ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    key: %{
      description: "Text record key (e.g., \"avatar\", \"url\", \"com.twitter\")",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Text record value"
  }
}

text!(name, key, opts \\ [])

@spec text!(String.t(), String.t(), keyword()) :: String.t()

Retrieve a text record. Raises on error.

Parameters

  • name - ENS name (e.g., "vitalik.eth") (value)
  • key - Text record key (e.g., "avatar", "url", "com.twitter") (value)
  • opts - Options: :rpc_url, :timeout, :registry (default: [], value)

Returns

Text record value (String.t())

# descripex:contract
%{
  params: %{
    name: %{description: "ENS name (e.g., \"vitalik.eth\")", kind: :value},
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :registry",
      kind: :value
    },
    key: %{
      description: "Text record key (e.g., \"avatar\", \"url\", \"com.twitter\")",
      kind: :value
    }
  },
  returns: %{type: "String.t()", description: "Text record value"}
}