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 , you can acquire the contract address and the abi file of the NameService contract. Then you can construct a Contract object with "ethers".
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.
// The name to be registered
const registerName = 'name-one';
const contract = getContractInstance()
const accounts = await ethereum.request({ method: 'eth_requestAccounts' })
await (
await contract.register(accounts[0], registerName, true)
).wait()
A minter register a name for a specified address without setting a resolve record.
// The name to be registered
const registerName = 'name-two';
const contract = getContractInstance()
const addr = '0x00000...';
await (
await contract.register(addr, registerName, false)
).wait()
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.
const contract = getContractInstance()
const addr = '0x00000...';
const balance = await contract.balanceOf(addr);
var nameList = [];
for(var i = 0; i < balance; i++){
const tokenId = await contract.tokenOfOwnerByIndex(addr,i);
const name = await contract.nameOfToken(tokenId);
nameList.push(name);
}
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.