Managing names

Querying and updating records

Querying records

Here's some examples on how to query records for a domain:

import { Id } from '@imperviousinc/id';
import { BrowserProvider, Contract, parseEther } from 'ethers';

const provider = new BrowserProvider(...); // get a provider
const network = await provider.getNetwork() ;

const id = new Id({network, provider});

const results = await Promise.all([
  id.getDns('impervious.forever', [
    {name:'_443._tcp.impervious.forever', type: 'TLSA'},
    {name:'impervious.forever', type: 'A'}
  ]),
  id.getText('live.forever', 'email'),
  id.getOwner('bob.forever'),
  id.getRegistration('bob.forever'),
  id.getAddress('vitalik.eth')
])

Updating records

You can efficiently update multiple records at once with a single transaction using the setRecords method:


const tx = await id.setRecords('impervious.forever', {
    dns: [ 
        {'name':'impervious.forever', type: 'TXT', data: 'hello world'}, 
        {'name':'_443._tcp.impervious.forever', type: 'TLSA', data: ...},
        ...
    ],
    text: {
        'email': 'example@impervoius.forever',
        'url': 'https://impervious.com',
        'github': 'https://github.com/imperviousinc',
        'twitter': 'https://twitter.com/impervious',
    },
    contentHash: new RawContentHash('0x1234.....'),
    address: {
      'ETH': '0x1234.....',
      // Unsupported coin types must use RawAddress
      // to be stored on chain as-is (so you should encode them yourself)
      1919191: new RawAddress('0x1234.....'),
    }
})

await tx.wait()
Previous
Quick start