This guide will walk you through retrieving data from providers such as ENS, LENS, and UD using the Domains API.
Bash
1
mkdir domains && cd domains
Bash
1
npm init -y
Bash
1
npm install express cors axios
Bash
1
npm install dotenv
Then create a new file called .env and add your DevPortal API key to it:
Bash
1
API_KEY=YOUR_1INCH_API_KEY
Create a new file named api.js in your project directory.
Add the following code to import necessary packages and initialize your Express application:
JavaScript
1234567891011
const express = require("express");
const axios = require("axios");
const dotenv = require("dotenv");
const cors = require("cors");
const path = require("path");
// Load environment variables
dotenv.config({ path: path.resolve(__dirname, ".env") });
const app = express();
app.use(cors());
Add the following code to define your API endpoints:
Retrieve domain information
JavaScript
12345678910111213141516
const BASE_URL = "https://api.1inch.com/domains/v2.0";
app.get("/api/:domain/info", async (req, res) => {
const domain = req.params.domain;
try {
const constructedUrl = `${BASE_URL}/${domain}/lookup`;
const response = await axios.get(constructedUrl, {
headers: {
Authorization: `Bearer ${process.env.API_KEY}`
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: "API error" });
}
});
Reverse lookup for a domain:
JavaScript
1234567891011121314
app.get("/api/:domain/reverseinfo", async (req, res) => {
const domain = req.params.domain;
try {
const constructedUrl = `${BASE_URL}/${domain}/reverse-lookup`;
const response = await axios.get(constructedUrl, {
headers: {
Authorization: `Bearer ${process.env.API_KEY}`
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: "API error" });
}
});
Retrieve provider data with avatars:
JavaScript
1234567891011121314
app.get("/api/:domain/get-providers-data-with-avatar", async (req, res) => {
const domain = req.params.domain;
try {
const constructedUrl = `${BASE_URL}/get-providers-data-with-avatar`;
const response = await axios.get(constructedUrl, {
headers: {
Authorization: `Bearer ${process.env.API_KEY}`
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: "API error" });
}
});
JavaScript
1234
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Bash
1
node api.js
The API returns structured JSON responses, which you can use to integrate with your application.
JSON
12345678
{
"result": {
"protocol": "string",
"domain": "string",
"address": "string",
"avatar": {}
}
}
JSON
1234567
{
"result": {
"protocol": "string",
"address": "string",
"checkUrl": "string"
}
}