# Reverse Resolution Sample Code

## Constants

```javascript
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

```javascript
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

```javascript
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

```javascript
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`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.klaytn.domains/english/dev/reverse-resolution.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
