CORE ID Docs
  • Introduction
  • Connect to CORE ID using ethers.js
  • CID SDK
  • HTTP API
  • Published Contracts
  • Core rpc
  • CORE ID enabling your dapp
  • CORE ID Registry
  • Name processing
  • Public Resolver
  • Resolving Names On Chain
  • Reverse Registrar
  • Decentralized Website
    • Core.Limo Decentralized Gateway
    • Create a decentralized website
    • Quickly create decentralized website
    • Create decentralized blog
  • User Tutorials for .core Domain
    • Set Up a Wallet
    • Register for a .core Domain
    • Set your domain name
    • Set primary name
    • Set Subdomains
    • CID Token
  • App
  • Twitter
  • Telegram
Powered by GitBook
On this page

Resolving Names On Chain

CORE ID resolution is straightforward enough it can be done trivially without a library. First, we define some pared-down interfaces containing only the methods we need:

abstract contract COREID {
    function resolver(bytes32 node) public virtual view returns (Resolver);
}

abstract contract Resolver {
    function addr(bytes32 node) public virtual view returns (address);
}

For resolution, only the resolver function in the CORE ID contract is required; other methods permit looking up owners and updating CORE ID from within a contract that owns a name.

With these definitions, looking up a name given its node hash is straightforward:

contract MyContract {
    // Same address for Mainet, Ropsten, Rinkerby, Gorli and other networks;
    COREID coreid = COREID(0x00000000003dB7663112d1e121c6D2bb8220F671);

    function resolve(bytes32 node) public view returns(address) {
        Resolver resolver = coreid.resolver(node);
        return resolver.addr(node);
    }
}

While it is possible for a contract to process a human-readable name into a node hash, we highly recommend working with node hashes instead, as they are easier and more efficient to work with, and allow contracts to leave the complex work of normalizing the name to their callers outside the blockchain. Where a contract always resolves the same names, those names may be converted to a node hash and stored in the contract as a constant.

PreviousPublic ResolverNextReverse Registrar

Last updated 2 years ago