When integrating the JustaName Widget into your platform, it's important to avoid exposing sensitive information, such as your API key, in the frontend. A best practice approach is to set up a backend service to handle calls to JustaName, ensuring that your API key remains secure. In this guide, we'll walk you through configuring the widget and setting up a backend to manage these requests.
Install JustaName SDK
Install the JustaName SDK in your backend by running the following command:
npminstall@justaname.id/sdk
pnpminstall@justaname.id/sdk
yarnadd@justaname.id/sdk
Set Up Your Backend with JustaName SDK
To securely handle API requests, you need to create a backend service using the JustaName SDK. This backend will manage subname issuance and revocation requests, ensuring your API key is never exposed.
This setup can also be achieved using serverless functions, such as AWS Lambda, Google Cloud Functions, or Vercel Functions. Simply deploy the backend logic to your serverless environment and configure your backendUrl in the Widget to point to the appropriate endpoint.
Create a backend that will handle API requests from the frontend. Below is a simple example of an Express.js server that can handle subname issuance and revocation:
Subname Issuance: The /api/subnames/add endpoint issues new subnames for users. It checks if the address already holds a subname for the given ENS domain before adding the new subname.
Subname Revocation: The /api/subnames/revoke endpoint revokes a subname for a specific address.
Security: The API key is never exposed in the frontend and all sensitive operations are handled by the backend.