Working with LNS

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 metamask installed, 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] })

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 here. Addresses for the LNS registry on each supported network are available in the LNS Deployments page.

Last updated