For the complete documentation index, see llms.txt. This page is also available as Markdown.

NameService contract guide

We can use the Relation NameService contract deployed by Relation Protocol to store and query a user's identity data. The Relation NameService contract is an implementation of the Name Service defined by the Contract Standard.

Construct a Contract object

Via Relation Protocol's resources, you can acquire the contract address and the abi file of the NameService contract. Then you can construct a Contract object with "ethers".

import { ethers, providers } from 'ethers'

const getContractInstance = () => {
  // Contract address
  const contractAddress = '0x0D195ab46a9C9C4f97666A76AADb35d93965Cac8'
  const provider = new providers.Web3Provider(window.ethereum)
  const signer = provider.getSigner()
  const contract = new ethers.Contract(contractAddress, abi, signer)
  return contract
}

How to call the contract

  1. Register a name

A user can call the "register" to register a name. Or, a minter specified by an administrator can also register names for other users. On registration, you can select whether to set a resolve record. Once a name is linked to an address, you can query the mapping with methods like "addr" and "nameOf".

Below are two examples:

  • Register a name for yourself, and set a resolve record.

  • A minter register a name for a specified address without setting a resolve record.

  1. Query the names held by a user

You can query the list of names held by a user through the tokens in said user's possession.

  1. Set a resolve record for a name

A user can set a resolve record for a name (without a resolve record) in his possession. After this setting, the token cannot be transferred.

  1. Query the address mapped to a name

After a resolve record is set, you can query a name's mapped address via "addr".

  1. Query the name mapped to am address

After a resolve record is set, you can query an address mapped to a name via "nameOf".

  1. Configure the profileURI

Users can upload their avatar information to Arweave with the following json format:

The subsequent transaction hash will be stored to a contract as the profileURI.

  1. Query a user's profileURI

Last updated