Skip to main content

Method Signature

align.blockchain.utils.resolveName(
  name: string,
  provider: JsonRpcProvider
): Promise<string | null>

Parameters

name
string
required
ENS name (e.g., vitalik.eth)
provider
JsonRpcProvider
required
Ethereum mainnet provider (ENS only works on mainnet)

Returns

Returns the address as a string, or null if not found.

Examples

import Align from "@tolbel/align";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

const provider = align.blockchain.providers.getProvider("ethereum");

const address = await align.blockchain.utils.resolveName(
  "vitalik.eth",
  provider
);

if (address) {
  console.log(`vitalik.eth → ${address}`);
  // vitalik.eth → 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
} else {
  console.log("ENS name not found");
}

Accept ENS or Address

async function resolveRecipient(input: string): Promise<string> {
  // If it's already a valid address, return it
  if (align.blockchain.utils.isValidAddress(input)) {
    return input;
  }

  // Try to resolve as ENS
  if (input.endsWith(".eth")) {
    const provider = align.blockchain.providers.getProvider("ethereum");
    const resolved = await align.blockchain.utils.resolveName(input, provider);

    if (resolved) {
      return resolved;
    }

    throw new Error(`Could not resolve ENS: ${input}`);
  }

  throw new Error("Invalid address or ENS name");
}
ENS resolution only works on Ethereum mainnet. The SDK uses the mainnet provider regardless of which network you’re transacting on.