npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nadnameservice/nns-ethers-sdk

v1.0.3

Published

Nad Name Service SDK using Ethers

Downloads

8

Readme

@nadnameservice/nns-ethers-sdk

A TypeScript library for interacting with Nad Name Service (NNS) protocol using ethers v5. This library provides a convenient wrapper around the NNS smart contract, enabling seamless operations related to name resolution, address mapping, and managing name attributes.

About Nad Name Service

Nad Name Service (NNS) is a web3 name service built natively on Monad. NNS maps human-readable names like 'salmo.nad' to machine-readable identifiers such as cryptocurrency addresses, metadata, and more.

More information:

Website
Documents
Monad

Table of Contents

Features

  • Name Resolution: Resolve .nad domain names to Ethereum addresses.
  • Address Mapping: Retrieve primary names associated with wallet addresses.
  • Attribute Management: Get and set custom attributes for names.
  • Avatar Integration: Fetch avatar URLs associated with names.
  • And many more...

Prerequisites

  • Node.js: Ensure you have Node.js installed (v12 or higher recommended).
  • TypeScript
  • Ethers.js: This library depends on Ethers.js for blockchain interactions.

Installation

Install the library via npm:

npm install @nadnameservice/nns-ethers-sdk

Or using yarn:

yarn add @nadnameservice/nns-ethers-sdk

Usage

Initialization

To initialize the NNS library:

Create an instance of the NNS class by providing a provider if you only want to read infos:

import { NNS } from '@nadnameservice/nns-ethers-sdk'
import { ethers } from 'ethers'

const provider = new providers.JsonRpcProvider(
  'YOUR_RPC_URL'
)

const nns = new NNS(provider)

Or if you want to modify name attributes, provide a signer to the NNS class:

import { NNS } from '@nadnameservice/nns-ethers-sdk'
import { ethers } from 'ethers'

const provider = new providers.JsonRpcProvider(
  'YOUR_RPC_URL'
)

const wallet = new Wallet('...')

const signer = wallet.connect(provider)

const nns = new NNS(signer)

Examples

Get resolved address of a .nad name

const resolveAddress = await nns.getResolvedAddress(
  'test.nad'
)
// 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Get the primary .nad name of an address

const primaryName = await nns.getPrimaryNameForAddress(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
)
// test.nad

Get the avatar associated with a name

const avatar = await nns.getAvatarUrl('test.nad')
// https://www.example.com/image.png

Get name attributes

// Get an attribute
const avatarStr = await nns.getNameAttribute(
  'test.nad',
  'avatar'
)

// Get a list of attribute of a name
const customAttrs = await nns.getNameAttributes(
  'test.nad',
  ['key1', 'key2', 'key3']
)

Set name attributes

// Set value for an attribute
const tx = await nns.setNameAttribute(
  'test.nad',
  'key1',
  'value1'
)

await provider.waitForTransaction(tx.hash!)

// Set value for a list of attributes
const tx2 = await nns.setNameAttributes('test.nad', [
  {
    key: 'key2',
    value: 'value2',
  },
  {
    key: 'key3',
    value: 'value3',
  },
])

await provider.waitForTransaction(tx2.hash!)

API Reference

NNS Class

getResolvedAddress(name: string)

Resolves a given name to an address.

  • Parameters:
    • name: The name to resolve, with the .nad domain.
  • Returns: Resolved address or zero address if unregistered.

getPrimaryNameForAddress(address: string)

Retrieves the primary name associated with an address.

  • Parameters:
    • address: The wallet address.
  • Returns: Primary name or empty string if not set.

getNameAttribute(name: string, key: string)

Retrieves the value of a specific attribute for a given name.

  • Parameters:
    • name: The name to retrieve the attribute from, with the .nad domain.
    • key: The key of the attribute.
  • Returns: Value of the attribute.

getNameAttributes(name: string, keys: string[])

Retrieves a list of name attributes.

  • Parameters:
    • name: The name to retrieve attributes from, with the .nad domain.
    • keys: The keys of the attributes to retrieve.
  • Returns: List of name attributes.

getNamesOfAddress(address: string)

Retrieves the names associated with a given address.

  • Parameters:
    • address: The wallet address.
  • Returns: An array of names associated with the address.

getAvatarUrl(name: string)

Retrieves the avatar URL associated with a given name.

  • Parameters:
    • name: The name to retrieve the avatar URL from, with the .nad domain.
  • Returns: Avatar URL.

setNameAttribute(name: string, key: string, value: string)

Sets a value for a specific attribute for a given name.

  • Parameters:
    • name: The name to set the attribute for, with the .nad domain.
    • key: The key of the attribute to set.
    • value: The value of the attribute to set.
  • Returns: Transaction object for the contract call.

setNameAttributes(name: string, attributes: NNSNameAttribute[])

Sets multiple attributes for a given name.

  • Parameters:
    • name: The name to set the attributes for, with the .nad domain.
    • attributes: The attributes to set.
  • Returns: Transaction object for the contract call.

Contributing

Contributions are welcome! If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive messages.
  4. Push your changes to your forked repository.
  5. Open a pull request detailing your changes and why they should be merged.

License

This project is licensed under the MIT License. See the LICENSE file for details.