0.4.0 • Published 3 months ago

lnsjs v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

The LNS Javascript Library is the ultimate solution for working with the LNS on the Lightlink ecosystem, with ethers.js at its core and inspired by and modelled on the ENS Package

NOTE!!!

lnsjs is currently in the early development stage, meaning that the projects are subject to change.

Given the current development status, we're actively seeking feedback so feel free to create an issue or PR if you notice something!

Installation

npm i lnsjs ethers

Getting Started

All that's needed to get started is an ethers provider instance(https://replicator.pegasus.lightlink.io/rpc/v1). Once you create a new LNS instance, you can pass it in using setProvider.

import { LNS } from 'lnsjs'
import { ethers } from 'ethers'

const provider = new ethers.providers.JsonRpcProvider(providerUrl)

const LNSInstance = new LNS()
await LNSInstance.setProvider(provider)

NOTE: If using lnsjs with Node, you may need to pass the --experimental-specifier-resolution=node flag.

node --experimental-specifier-resolution=node ./index.js

Single-use Providers

If you want to use a specific provider to make a single call occasionally, you can easily do so.

import { LNS } from 'lnsja'

const LNSInstance = new LNS()

const callWithProvider = await LNSInstance.withProvider(otherProvider).getText(
  'arome.link',
  'foo',
)

Name Availability

Check if a name is available to be registered on the FEVM Naming Service.

const name = "arome.link"
const isAvailable = await LNSInstance.getAvailable(name);

Price

View the current price of registering or updating a name on the FEVM Naming Service. The price is determined by market demand and is subject to change.

const name = "arome.link"
const price = await LNSInstance.getPrice(name, duration);

Profiles

You can fetch almost all information about an LNS name (or address) using getProfile. If an address is used as the first argument, it will fetch the primary name and give the same response as a name would. It will automatically get all the records for a name, as well as get the resolver address for the name. Specific records can also be used as an input, if you only want to get certain ones. If an address is used as an input alongside this, you also save 1 RPC call.

NOTE:
The profile function will always request an ETH addr record. For names, this means the address will always at the top level of the returned object. For addresses, this means the "match" property (a boolean value for matching reverse/forward resolution) will always be at the top level of the returned object.

/* Normal profile fetching */
const profile = await LNSInstance.getProfile('arome.link')

/* Normal address fetching */
const address = await LNSInstance.getAddress('arome.link')

/* Normal content fetching */
const contentHash = await LNSInstance.getContent('arome.link')

/* Get Name from Address */
const node = await LNSInstance.getNameNode(address);
const name = await LNSInstance.getAddrName(node);

/* Profile fetching from an address */
const profile = await LNSInstance.getProfile(
  '0x562937835cdD5C92F54B94Df658Fd3b50A68ecD5',
)

/* Get all records of a specific type (or multiple) */
const profile = await LNSInstance.getProfile('arome.link', {
  texts: true,
  coinTypes: true,
  contentHash: true,
})

/* Get specific records */
const profile = await LNSInstance.getProfile('arome.link', {
  texts: ['foo'],
  coinTypes: ['FIL'],
})

Returns:

type RecordItem = {
  key: string | number
  type: 'addr' | 'text' | 'contentHash'
  coin?: string
  addr?: string
  value?: string
}

type ProfileReturn = {
  address?: string // ONLY RETURNED AT TOP-LEVEL FOR NAME QUERIES
  name?: string // ONLY RETURNED AT TOP-LEVEL FOR ADDRESS QUERIES
  records: {
    contentHash?: ContentHashObject | null
    texts?: RecordItem[]
    coinTypes?: RecordItem[]
  }
  resolverAddress: string
}

Contribution

Feel free to create an issue or raise a PR

0.3.0

3 months ago

0.4.0

3 months ago

0.1.0

3 months ago

0.2.0

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.5

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago