Documentation
Usage

Imports

registry

The library exports a registry object with the required methods. You can import it like this:

import { registry } from '@leapwallet/name-matcha'

services

The library exports a services object with the available services:

import { services as nameMatcha } from '@leapwallet/name-matcha'

It looks like this:

const services = {
  icns: 'icns',
  ibcDomains: 'ibcDomains',
  stargazeNames: 'stargazeNames',
  archIds: 'archIds',
  spaceIds: 'spaceIds',
  sns: 'sns',
  nibId: 'nibId',
  degeNS: 'degeNS',
  celestialsId: 'celestialsId'
}

Name Resolution

resolve

For resolving a name to address, you can use the resolve method. It takes two arguments:

  1. The name to query
  2. The service to query against

The response can be either:

  • A string containing the resolved address for single-chain services
  • An array of chain_id and address pairs for multichain services like celestialsId
// Single chain example
const address = await nameMatcha.resolve('leap_cosmos.osmo', services.icns)
console.log(address); // osmo19vf5mfr40awvkefw69nl6p3mmlsnacmmzu45k9
 
// Multichain example
const multiChainAddress = await nameMatcha.resolve('celestiaa.id', services.celestialsId)
console.log(multiChainAddress);
/* Output:
[
  {
    "chain_id": "984122",
    "address": "0x90cc5514f5eef8b8a683224a54991d90fb3f8c16"
  },
  {
    "chain_id": "8453",
    "address": "0xdf3b77dde35eb980a03915f2a36032dcb89f924c"
  },
  {
    "chain_id": "celestia",
    "address": "celestia1u0cltepg9wjkj0u49enu0fswgygze9va74lkwy"
  }
]
*/

resolveAll

To resolve a name to an address, for all the available services, you can use the resolveAll method. It takes one argument:

  1. The name to query
const address = await nameMatcha.resolveAll('leap_cosmos.osmo')
console.log(address);

The output will be an object with the service as key and the value can be:

  • null if no resolution found for that service
  • A string containing the resolved address for single-chain services
  • An array of chain_id and address pairs for multichain services like celestialsId
// Example output for single chain name
{
  icns: 'osmo19vf5mfr40awvkefw69nl6p3mmlsnacmmzu45k9',
  ibcDomains: null,
  stargazeNames: null,
  archIds: null,
  spaceIds: null,
  sns: null,
  nibId: null,
  degeNS: null,
  bidds: null,
  celestialsId: null
}
 
// Example output for multichain name (celestiaa.id)
{
  spaceIds: null,
  archIds: null,
  nibId: null,
  degeNS: null,
  bdd: null,
  sns: null,
  ibcDomains: null,
  icns: null,
  stargazeNames: null,
  celestialsId: [
    {
      chain_id: "984122",
      address: "0x90cc5514f5eef8b8a683224a54991d90fb3f8c16"
    },
    {
      chain_id: "8453",
      address: "0xdf3b77dde35eb980a03915f2a36032dcb89f924c"
    },
    {
      chain_id: "celestia",
      address: "celestia1u0cltepg9wjkj0u49enu0fswgygze9va74lkwy"
    }
  ]
}

Name Lookup

lookup

For getting the name associated to an address, you can use the lookup method. It takes two arguments:

  1. The address to query
  2. The service to query against
const name = await nameMatcha.lookup('osmo19vf5mfr40awvkefw69nl6p3mmlsnacmmzu45k9', services.icns)
console.log(name); // leap_cosmos.osmo

lookupAll

To get the name associated to an address, for all the available services, you can use the lookupAll method. It takes one argument:

  1. The address to query
const names = await nameMatcha.lookupAll('osmo19vf5mfr40awvkefw69nl6p3mmlsnacmmzu45k9')

The output will be an object with the service as key and the name as value:

{
  icns: 'leap_cosmos.osmo',
  ibcDomains: 'leapwallet.osmo',
  stargazeNames: 'messi.osmo',
  archIds: null,
  spaceIds: null,
  sns: null,
  nibId: null,
  degeNS: 'ligma.pp',
  bidds: null
}

Switch Network

By default, the library uses the mainnet network. To switch network, you can use the setNetwork method. It takes one argument:

  1. The network to use

Here's an example:

nameMatcha.setNetwork('testnet')

Custom RPC Endpoints

Name Matcha comes with default RPC endpoints for each service.

Error Handling

The library throws errors when something goes wrong. The library throws errors of type MatchaError. It is built on top of the Error class, and has an additional property type of type MatchaErrorType.

import nameMatcha, { MatchaError, MatchaErrorType } from '@leapwallet/name-matcha'
 
try {
  const name = await nameMatcha.lookup('osmo19vf5mfr40awvkefw69nl6p3mmlsnacmmzu45k9', services.icns)
} catch (error: MatchaError) {
  if (error.type === MatchaErrorType.NOT_FOUND) {
    alert('Name not found')
  }
}

Supported Chains