Skip to main content

Resolving ENS or Returning Ethereum Address with EdexaClient

The EdexaClient library includes a function resolveENSOrReturnAddress that either resolves an Ethereum Name Service (ENS) domain to its corresponding Ethereum address or verifies and returns a valid Ethereum address. This function is particularly useful for applications that need to handle both raw Ethereum addresses and ENS domains.

Function Signature

async resolveENSOrReturnAddress(input: string): Promise<string>

Parameters

  • input (string): The Ethereum address or ENS domain to be resolved or verified.

Description

The resolveENSOrReturnAddress function performs two main tasks:

  1. Address Verification: If the input is a valid Ethereum address, it returns the address as is.
  2. ENS Resolution: If the input is not a valid Ethereum address, it attempts to resolve it through the Ethereum Name Service (ENS).

Usage Example

The resolveENSOrReturnAddress function can be utilized in various scenarios where handling both ENS domains and Ethereum addresses is required. Below is a practical example demonstrating its use:

Example

// Assuming edexaClient is an instance of EdexaClient
let addressOrEns = "example.eth";
edexaClient
.resolveENSOrReturnAddress(addressOrEns)
.then((address) =>
//Add your logic here
)
.catch((error) =>
// Handle the error here
);

In this example, the function takes a string input, which could be either an ENS domain or an Ethereum address, and attempts to resolve it. The resolved address is then logged to the console, or an error is caught and logged if the resolution fails.

Error Handling

The function throws an error in the following scenarios:

  • The input is neither a valid Ethereum address nor a resolvable ENS domain.
  • The ENS domain does not have a registered resolver.
  • Any other unexpected issues occur during the process.