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

@edgeandnode/ens

v2.0.1

Published

Resolver for ENS names and avatars using the Graph Network Subgraph and ensdomains resolution

Downloads

839

Readme

ENS

Resolver for ENS names and avatars using the Graph Network Subgraph and ensdomains resolution.

This lets us resolve the ENS name for a given address/addresses in a consistent way across all apps, following this business logic:

  1. Check if the wallet has set a default ENS name in the L1 GNS contract. Query the L1 Network Subgraph for the GraphAccount.defaultDisplayName to resolve.
  2. Do a lookup with the EnsPublicClient exposed by the @ensdomains/ensjs library to resolve the primary ENS for the given address. Also exposes batch functionality to resolve multiple ENS names if given multiple addresses.

The issue with the ENS subgraph is it does not have a way to determine which domain is the primary domain for a user, resulting in it resolving to any domain the user owns, causing issues (primarily in explorer).

API

  • buildEnsResolver(): EnsResolverConfig -> has two methods:
    • args: BuildEnsResolverArgs
      • infuraKey: [REQUIRED] infura key used to lookup the ENS from the EnsPublicClient
      • gatewayApiKey: [OPTIONAL] used to lookup the set default name from the L1 Network Subgraph
    • resolveEnsName -> resolves the ENS name (using the logic above) for a single address
      • args: ResolveEnsNameArgs
        • address: [REQUIRED] 0x EVM wallet address to lookup the ENS name for
        • gatewayApiKey: [OPTIONAL] used to lookup the set default name from the L1 Network Subgraph
        • testnet: [OPTIONAL, default = false] if true, look up is performed on the L1 testnet
        • timeout: [OPTIONAL, default = 5000] time, in milliseconds, before the client lookup fails
    • resolveEnsNamesBatch -> resolves the ENS names (using the logic above) for an array of addresses
      • args: ResolveEnsNamesBulkArgs
        • addresses: [REQUIRED] array of 0x EVM wallet addresses to lookup the ENS names for
        • gatewayApiKey: [OPTIONAL] used to lookup the set default name from the L1 network Subgraph
        • testnet: [OPTIONAL, default = false] if true, look up is performed on the L1 testnet
    • resolveAvatar -> resolves the Avatar for a single address from the network subgraph and then ENS
      • args: ResolveAvatarArgs
        • address: [REQUIRED] 0x EVM wallet address to lookup the avatar for
        • ens: [OPTIONAL] an already resolved ENS name. Finding the avatar from ENS is found through the ENS name, so passing this removes needing to resolve the ENS name using the user address
        • chain: [OPTIONAL, default = 42161 (arbitrum-one)] the chain to lookup the GraphAccount.metadata.image from the Network Subgraph on
        • gatewayApiKey: [OPTIONAL] used to lookup the GraphAccount.metadata.image from the Network Subgraph
        • timeout: [OPTIONAL, default = 5000] time, in milliseconds, before the client lookup fails
    • resolveAvatarsBatch -> resolves the avatars for an array of addresses
      • args: ResolveAvatarsBatchArgs
        • addresses: [REQUIRED] array of 0x EVM wallet addresses to lookup the avatar for
        • chain: [OPTIONAL, default = 42161 (arbitrum-one)] the chain to lookup the GraphAccount.metadata.image from the Network Subgraph on
        • gatewayApiKey: [OPTIONAL] used to lookup the GraphAccount.metadata.image from the Network Subgraph

Examples

  • EnsResolverConfig.resolveEnsName
import { type Address } from 'viem'
import { buildEnsResolver } from '@edgeandnode/graph-auth-kit/ens'

const resolver = buildEnsResolver({
  infuraKey: 'key',
  gatewayApiKey: 'some32digitapikey',
})

async function lookupEnsName(address: Address) {
  return await resolver.resolveEnsName({ address })
}
lookupEnsName('0x123').then((ens) => {
  // testuser.eth
})
  • EnsResolverConfig.resolveEnsNamesBatch
import { type Address } from 'viem'
import { buildEnsResolver } from '@edgeandnode/graph-auth-kit/ens'

const resolver = buildEnsResolver({
  infuraKey: 'key',
  gatewayApiKey: 'some32digitapikey',
})

async function lookupEnsNames(addresses: Address[]) {
  return await resolver.resolveEnsNamesBatch({ addresses })
}
lookupEnsNames(['0x123', '0x456']).then((ensMap) => {
  // { '0x123': 'testuser.eth', '0x456': null }
})
  • EnsResolverConfig.resolveAvatar
import { type Address } from 'viem'
import { buildEnsResolver } from '@edgeandnode/graph-auth-kit/ens'

const resolver = buildEnsResolver({
  infuraKey: 'key',
  gatewayApiKey: 'some32digitapikey',
})

async function lookupAvatar(address: Address) {
  return await resolver.resolveAvatar({
    address,
    timeout: 2500, // only wait 2.5sec before timing out
  })
}
lookupAvatar('0x123').then((avatar) => {
  // https://api.thegraph.com/ipfs/api/v0/cat?arg=QmdFKawEFPYzDVwZrXyJcyaYyCZd6PP9N5NCuTi2XmLJMD
})

async function lookupAvatarFromENS(address: Address, ens: string) {
  return await resolver.resolveAvatar({
    address,
    ens,
    timeout: 2500, // only wait 2.5sec before timing out
  })
}
lookupAvatarFromENS('0x123').then((avatar) => {
  // https://ipfs.io/ipfs/QmP9ayW28pbW2V9nYAjEbxv45MTezQpz8S913VbV56nkCg/1398.png
})
  • EnsResolverConfig.resolveAvatarsBatch
import { type Address } from 'viem'
import { buildEnsResolver } from '@edgeandnode/graph-auth-kit/ens'

const resolver = buildEnsResolver({
  infuraKey: 'key',
  gatewayApiKey: 'some32digitapikey',
})

async function lookupAvatars(addresses: Address[]) {
  return await resolver.resolveAvatarsBatch({
    addresses,
  })
}
lookupAvatars(['0x123', '0x456']).then((avatar) => {
  // { '0x123': 'https://api.thegraph.com/ipfs/api/v0/cat?arg=QmdFKawEFPYzDVwZrXyJcyaYyCZd6PP9N5NCuTi2XmLJMD', '0x456': null }
})