sidebar_position: 2
Introduction
This guide will walk you through retrieving data from providers such as ENS, LENS, and UD using the Domains API.
Prerequisites
- Node.js and npm installed on your machine
- Basic knowledge of JavaScript, React, and Express.js
Step-by-step guide
Step 1: Initialization
- Create a new directory for your project:Bash1
mkdir domains && cd domains - Initialize a new Node.js project:Bash1
npm init -y - Install Express, CORS, and Axios:Bash1
npm install express cors axios - Install dotenv for securely storing environment variables:Then create a new file calledBash1
npm install dotenv.envand add your DevPortal API key to it:Bash1API_KEY=YOUR_1INCH_API_KEY
Step 2: Import required libraries
Create a new file named
api.jsin your project directory.Add the following code to import necessary packages and initialize your Express application:
JavaScript123456789101112const 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());
Step 3: Define API endpoints
Add the following code to define your API endpoints:
Retrieve domain information
JavaScript1234567891011121314151617const 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:
JavaScript123456789101112131415app.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:
JavaScript123456789101112131415app.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' }); } });
Step 4: Start the server
- Add the following code to start your Express server and save the file:JavaScript12345
const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); - Run the server by using in your Terminal:Bash1
node api.js
Response models
The API returns structured JSON responses, which you can use to integrate with your application.
- Response model: Provider data with avatarJSON123456789
{ "result": { "protocol": "string", "domain": "string", "address": "string", "avatar": {} } } - Response model: Domain or address informationJSON12345678
{ "result": { "protocol": "string", "address": "string", "checkUrl": "string" } }