This is a sample app showcasing ensjs
library to interact with ENS.
This project was bootstrapped with Create Eth App.
git clone https://github.com/ensdomains/my-ens-app.git
cd my-ens-app
yarn
cd packages/react-app
yarn start
This demo app shows three basic ways to integrate ENS into your dapp.
- Resolve ENS name
- Support reverse resolution
- Let users name things
All the logic is in App.js
import ENS, { getEnsAddress } from '@ensdomains/ensjs'
const ensAddress = getEnsAddress('1') // Pass chainId
const ens = new ENS({ provider, ensAddress })
await ens.name(name).getAddress()
Getting reverse name
ens.getName(address)
Setting reverser name
let tx = await ens.setReverseRecord(address)
tx.wait()
let tx = await ens.name(myName).createSubdomain(subdomain)
tx.wait()
As an extra bonus, it shows how to query ENS subgraph to retrieve events such as list of subdomains
query getSubdomains($id: ID!) {
domain(id: $id) {
id
labelName
subdomains {
id
labelName
labelhash
name
}
}
}
For more detail, please look into our guide