# `Ethers.NameService`
[🔗](https://github.com/ExWeb3/elixir_ethers/blob/v0.6.12/lib/ethers/name_service.ex#L1)

Name Service resolution implementation for ENS (Ethereum Name Service).
Supports both forward and reverse resolution plus reverse lookups.

This module implements [Cross Chain / Offchain Resolvers](https://docs.ens.domains/resolvers/ccip-read)
(is CCIP-Read aware), allowing it to resolve names that are stored:
- On-chain (traditional L1 ENS resolution on Ethereum)
- Off-chain (via CCIP-Read gateway servers)
- Cross-chain (on other L2s and EVM-compatible blockchains)

The resolution process automatically handles these different scenarios transparently,
following the ENS standards for name resolution including ENSIP-10 and ENSIP-11.

# `name_hash`

```elixir
@spec name_hash(String.t()) :: &lt;&lt;_::256&gt;&gt;
```

Implementation of namehash function in Elixir.

See https://docs.ens.domains/contract-api-reference/name-processing

## Examples

    iex> Ethers.NameService.name_hash("foo.eth")
    Ethers.Utils.hex_decode!("0xde9b09fd7c5f901e23a3f19fecc54828e9c848539801e86591bd9801b019f84f")

    iex> Ethers.NameService.name_hash("alisina.eth")
    Ethers.Utils.hex_decode!("0x1b557b3901bef3a986febf001c3b19370b34064b130d49ea967bf150f6d23dfe")

# `resolve`

```elixir
@spec resolve(String.t(), Keyword.t()) ::
  {:ok, Ethers.Types.t_address()}
  | {:error, :domain_not_found | :record_not_found | term()}
```

Resolves a name on blockchain.

## Parameters
- name: Domain name to resolve. (Example: `foo.eth`)
- opts: Resolve options.
  - resolve_call: TxData for resolution (Defaults to
  `Ethers.Contracts.ENS.Resolver.addr(Ethers.NameService.name_hash(name))`)
  - to: Resolver contract address. Defaults to ENS
  - Accepts all other Execution options from `Ethers.call/2`.

## Examples

```elixir
Ethers.NameService.resolve("vitalik.eth")
{:ok, "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"}
```

# `resolve!`

```elixir
@spec resolve!(String.t(), Keyword.t()) :: Ethers.Types.t_address() | no_return()
```

Same as `resolve/2` but raises on errors.

## Examples

```elixir
Ethers.NameService.resolve!("vitalik.eth")
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
```

# `reverse_resolve`

```elixir
@spec reverse_resolve(Ethers.Types.t_address(), Keyword.t()) ::
  {:ok, String.t()}
  | {:error,
     :domain_not_found | :invalid_name | :forward_resolution_mismatch | term()}
```

Resolves an address to a name on blockchain.

## Parameters
- address: Address to resolve.
- opts: Resolve options.
  - to: Resolver contract address. Defaults to ENS.
  - chain_id: Chain ID of the target chain Defaults to `1`.
  - Accepts all other Execution options from `Ethers.call/2`.

## Examples

```elixir
Ethers.NameService.reverse_resolve("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")
{:ok, "vitalik.eth"}
```

# `reverse_resolve!`

```elixir
@spec reverse_resolve!(Ethers.Types.t_address(), Keyword.t()) ::
  String.t() | no_return()
```

Same as `reverse_resolve/2` but raises on errors.

## Examples

```elixir
Ethers.NameService.reverse_resolve!("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")
"vitalik.eth"
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
