LogoLogo
  • Introduction
    • Terminology
  • Frequently Asked Questions
  • Domains Deployments
  • Registrar Frequently Asked Questions
  • Deploying Domains on a Private Chain
  • DNS Registrar guide
  • Domains Improvement Proposals
    • DomainsIP-1: Domains
    • DomainsIP-2: Initial Hash Registrar
    • DomainsIP-3: Reverse Resolution
    • DomainsIP-4: Support for contract ABIs
    • DomainsIP-5: Text Records
    • DomainsIP-6: DNS-in-Domains
    • DomainsIP-7: Interface Discovery
    • DomainsIP-8: Multichain Address Resolution
    • DomainsIP-9: Wildcard Resolution
    • DomainsIP-10: EVM compatible Chain Address Resolution
    • DomainsIP-11: Avatar Text Records
    • DomainsIP-12: SAFE Authentication for Domains
    • DomainsIP-13: On-chain Source Parameter
  • DAPP DEVELOPER GUIDE
    • Domains Enabling your DApp
    • Domains Libraries
    • Working with Domains
    • Resolving Names
    • Managing Names
    • Registering & Renewing Names
    • Domains Front-End Design Guidelines
    • Domains AS NFT
    • Domains Layer2 and offchain data support
    • Domains Data guide
  • CONTRACT API REFERENCE
    • Name Processing
  • Registry
  • ReverseRegistrar
  • TestRegistrar
  • PublicResolver
  • .tomi Permanent Registrar
    • Registrar
    • Controller
  • DNS Registrar
  • Subgraph
    • Query Examples
  • CONTRACT DEVELOPER GUIDE
    • Resolving Names On-chain
    • Writing a Resolver
    • Writing a Registrar
    • TOMI DISCUSSION FORUM
    • TOMI SUPPORT CHAT
  • TOMI MIGRATION (FEBRUARY 2020)
    • Guide for DApp Developers
    • Technical Description
Powered by GitBook
On this page
  1. DAPP DEVELOPER GUIDE

Working with Domains

PreviousDomains LibrariesNextResolving Names

Last updated 1 year ago

Before you can begin interacting with Domains, you will need to obtain a reference to the Domains registry. How you do this depends on the library you are using.

Example code for the Javascript-based APIs (tdnsjs, web3.js, ethjs-tdns, and ethers.js) here expect that they are being run inside a DApp browser, such as Chrome with , which exposes the polygon object.

import ENS, { getEnsAddress } from '@ensdomains/ensjs'

const ens = new ENS({ provider, ensAddress: "0x78C9E78D00De510e41c4a36a6325f6D3Eb2aE473" })
var Web3 = require("web3")

var accounts = ethereum.enable();
var web3 = new Web3(ethereum);
var ens = web3.eth.ens;
const ENS = require('ethjs-ens');
// Currently requires both provider and
// either a network or registryAddress param
var accounts = ethereum.enable();
const ens = new ENS({ ethereum, network: '1' });
var ethers = require('ethers');
var provider = new ethers.providers.Web3Provider(ethereum);
// ENS functionality is provided directly on the core provider object.
import (
  ens "github.com/wealdtech/go-ens/v2"
  ethereum "github.com/ethereum/go-ethereum"
)

// Can dial up a connection through either IPC or HTTP/HTTPS
client, err := ethereum.Dial("/home/ethereum/.ethereum/geth.ipc")
registry, err := ens.Registry(client)
from ens.auto import ns
EnsResolver ens = new EnsResolver(web3j, 300 /* sync threshold, seconds */);

Some web3 libraries - e.g., ethers.js, web3j, and web3.py - have integrated support for name resolution. In these libraries, you can pass in an Domains name anywhere you can supply an address, meaning you do not need to interact directly with their tDNS APIs unless you want to manually resolve names or do other Domains operations.

If no library is available for your platform, you can instantiate the Domains registry contract directly using the interface definition . Addresses for the Domains registry on each supported network are available in the Domains Deployments page.

metamask installed
here