Reverse Resolution Sample Code

Constants

const JSON_RPC_PROVIDER = "" // JSON-RPC provider url
const REVERSE_RECORDS_ADDRESS = "0x87f4483E4157a6592dd1d1546f145B5EE22c790a";
const REVERSE_RECORDS_ABI = [
  {
    type: "function",
    name: "getName",
    stateMutability: "view",
    inputs: [
      {
        internalType: "address",
        name: "addr",
        type: "address",
      },
    ],
    outputs: [
      {
        internalType: "string",
        name: "",
        type: "string",
      },
    ],
  },
];

ethers.js

import ethers from "ethers";

async function domainOrAddressEthers(address) {
  const provider = new ethers.providers.JsonRpcProvider(JSON_RPC_PROVIDER);
  const reverseRecords = new ethers.Contract(REVERSE_RECORDS_ADDRESS, REVERSE_RECORDS_ABI, provider);
  const domain = await reverseRecords.getName(address);
  if (domain === "") {
    return address;
  } else {
    return domain;
  }
}

web3.js

import Web3 from "web3";

async function domainOrAddressWeb3(address) {
  const web3 = new Web3(JSON_RPC_PROVIDER);
  const reverseRecords = new web3.eth.Contract(REVERSE_RECORDS_ABI, REVERSE_RECORDS_ADDRESS);
  const domain = await reverseRecords.methods.getName(address).call();
  if (domain === "") {
    return address;
  } else {
    return domain;
  }
}

caver-js

import Caver from "caver-js";

async function domainOrAddressCaver(address) {
  const caver = new Caver(JSON_RPC_PROVIDER);
  const reverseRecords = new caver.klay.Contract(REVERSE_RECORDS_ABI, REVERSE_RECORDS_ADDRESS);
  const domain = await reverseRecords.methods.getName(address).call();
  if (domain === "") {
    return address;
  } else {
    return domain;
  }
}

Sample Wallet Address and Domain

If the implementation of reverse resolution is successful, it should return the following domain when the following wallet address is fetched.

  • Wallet Address: 0x0000ac03932ff48ee30209774e3f10fb0ac522e9

  • Domain: kns.klay

Last updated