🤖
LNS Documentation
  • Introduction
  • Terminology
  • Frequently Asked Questions
  • Tokenomics
  • LNS Deployments
  • Registrar Frequently Asked Questions
  • Deploying LNS on a Private Chain
  • DNS Registrar guide
  • Bug Bounty Program
  • ENS Improvement Proposals
    • ENSIP-1: ENS
    • ENSIP-2: Initial Hash Registrar
    • ENSIP-3: Reverse Resolution
    • ENSIP-4: Support for contract ABIs
    • ENSIP-5: Text Records
    • ENSIP-6: DNS-in-ENS
    • ENSIP-7: Contenthash field
    • ENSIP-8: Interface Discovery
    • ENSIP-9: Multichain Address Resolution
    • ENSIP-10: Wildcard Resolution
    • ENSIP-11: EVM compatible Chain Address Resolution
    • ENSIP-12: Avatar Text Records
  • Dapp Developer Guide
    • LNS Enabling your DApp
    • LNS Libraries
    • Working with LNS
    • Resolving Names
    • Managing Names
    • Registering & Renewing Names
    • LNS Front-End Design Guidelines
    • LNS as NFT
  • Contract API Reference
    • Name Processing
    • Registry
    • ReverseRegistrar
    • PublicResolver
    • .bch Permanent Registrar
      • Registrar
      • Controller
    • DNS Registrar
  • Contract Developer Guide
    • Resolving Names On-chain
    • Writing a Resolver
    • Writing a Registrar
    • LNS Support Chat
Powered by GitBook
On this page
Edit on GitHub
  1. Dapp Developer Guide

Working with LNS

PreviousLNS LibrariesNextResolving Names

Last updated 3 years ago

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

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

In all cases when using a library designed for ENS, you will have to provide the LNS registrar contract address to the library.

import ENS from '@ensdomains/ensjs'
import ENS_REGISTRAR_ADDRESS from '@mistswapdex/sdk'

const ens = new ENS({ provider, ensAddress: ENS_REGISTRAR_ADDRESS[10000] })
var Web3 = require("web3")
var { ENS_REGISTRAR_ADDRESS } = require('@mistswapdex/sdk');

var accounts = ethereum.enable();
var web3 = new Web3(ethereum);
web3.eth.ens.registryAddress = ENS_REGISTRAR_ADDRESS[10000];
var ens = web3.eth.ens;
const ENS = require('ethjs-ens');
const { ENS_REGISTRAR_ADDRESS } = require('@mistswapdex/sdk');
// Currently requires both provider and
// either a network or registryAddress param
var accounts = ethereum.enable();
const ens = new ENS({ ethereum, network: '1', registryAddress: ENS_REGISTRAR_ADDRESS[10000] });
const { ethers } = require('ethers');
const { ENS_REGISTRAR_ADDRESS } = require('@mistswapdex/sdk');

const provider = new ethers.providers.JsonRpcProvider('https://smartbch.fountainhead.cash/mainnet', {
    name: 'smartbch',
    chainId: 10000,
    ensAddress: ENS_REGISTRAR_ADDRESS[10000],
});

(async () => {
    const resolver = await provider.getResolver('kasumi.bch');
    console.log(resolver.address);
    console.log(await provider.lookupAddress('0x8370DAE31693A8BbB9630b7052de52aCBcEC7525'));
})()
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 LNS name anywhere you can supply an address, meaning you do not need to interact directly with their LNS APIs unless you want to manually resolve names or do other LNS operations.

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

metamask installed
here
LNS Deployments