View Source Ethers.NameService (Ethers v0.5.5)

Name Service resolution implementation

Summary

Functions

Implementation of namehash function in Elixir.

Resolves a name on blockchain.

Same as resolve/2 but raises on errors.

Resolves an address to a name on blockchain.

Functions

name_hash(name)

@spec name_hash(String.t()) :: <<_::256>>

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(name, opts \\ [])

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

Resolves a name on blockchain.

Parameters

  • name: Domain name to resolve. (Example: foo.eth)
  • opts: Resolve options.
    • to: Resolver contract address. Defaults to ENS
    • Accepts all other Execution options from Ethers.call/2.

Examples

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

resolve!(name, opts \\ [])

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

Same as resolve/2 but raises on errors.

Examples

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

reverse_resolve(address, opts \\ [])

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

Resolves an address to a name on blockchain.

Parameters

  • address: Address to resolve.
  • opts: Resolve options.
    • to: Resolver contract address. Defaults to ENS
    • Accepts all other Execution options from Ethers.call/2.

Examples

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

reverse_resolve!(address, opts \\ [])

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

Same as reverse_resolve/2 but raises on errors.

Examples

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