-
Notifications
You must be signed in to change notification settings - Fork 2
feat(nameguard): Add ENSNode API for primary name resolution #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5550563
127a5f7
5f18320
9795c6d
a502021
49d2610
24275b5
ab08179
9e93704
9413536
675d901
94304ea
d6b2448
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,12 @@ pip install nameguard | |
| <Step title="Configure API keys"> | ||
|
|
||
| ```bash | ||
| export PROVIDER_URI_MAINNET=https://eth-mainnet.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY] | ||
| export PROVIDER_URI_SEPOLIA=https://eth-sepolia.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY] | ||
| export ENSNODE_URL_MAINNET=https://api.alpha.ensnode.io | ||
| export ENSNODE_URL_SEPOLIA=https://api.alpha-sepolia.ensnode.io | ||
| export ALCHEMY_URI_MAINNET=https://eth-mainnet.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY] | ||
| export ALCHEMY_URI_SEPOLIA=https://eth-sepolia.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY] | ||
| export ENS_SUBGRAPH_URL_MAINNET="https://gateway-arbitrum.network.thegraph.com/api/[YOUR_SUBGRAPH_API_KEY]/subgraphs/id/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to completely remove any reference to any ENS Subgraphs that are hosted by The Graph. |
||
| export ENS_SUBGRAPH_URL_SEPOLIA="https://gateway-arbitrum.network.thegraph.com/api/[YOUR_SUBGRAPH_API_KEY]/subgraphs/id/DmMXLtMZnGbQXASJ7p1jfzLUbBYnYUD9zNBTxpkjHYXV" | ||
| export ENS_SUBGRAPH_URL_SEPOLIA="https://gateway-arbitrum.network.thegraph.com/api/[YOUR_SUBGRAPH_API_KEY]/subgraphs/id/G1SxZs317YUb9nQX3CC98hDyvxfMJNZH5pPRGpNrtvwN" | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,35 @@ | ||
| import { PublicClient } from "viem"; | ||
|
|
||
| /** | ||
| * Looks up the primary name associated with the given address. | ||
| * Looks up the primary name associated with the given address using ENS node API. | ||
| * | ||
| * @param address - The address to lookup. | ||
| * @param client - The viem client instance used for the lookup. | ||
| * @param network - The network to query ("mainnet" or "sepolia"). | ||
| * @returns A Promise that resolves to the primary name associated with the address, or null if not found. | ||
| */ | ||
| export function lookupPrimaryName( | ||
| export async function lookupPrimaryName( | ||
| address: string, | ||
| client: PublicClient, | ||
| network: "mainnet" | "sepolia", | ||
| ): Promise<string | null> { | ||
| return client.getEnsName({ address }); | ||
| const baseUrl = network === "mainnet" | ||
| ? process.env.ENSNODE_URL_MAINNET || "https://api.alpha.ensnode.io" | ||
| : process.env.ENSNODE_URL_SEPOLIA || "https://api.alpha-sepolia.ensnode.io"; | ||
|
|
||
| const chainId = network === "mainnet" ? 1 : 11155111; | ||
| const url = `${baseUrl}/api/resolve/primary-name/${address}/${chainId}`; | ||
vercel[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're supposed to use |
||
|
|
||
| try { | ||
| const response = await fetch(`${url}?accelerate=true`); | ||
|
|
||
| if (response.status === 404) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`ENS node API error: ${response.status} ${response.statusText}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data.name || null; | ||
| } catch (error) { | ||
| throw new Error(`Failed to lookup primary name: ${error}`); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djstrong Several lines below I still see the following environment variables:
ENS_SUBGRAPH_URL_MAINNETENS_SUBGRAPH_URL_SEPOLIAThese should be fully removed because we can instead build ENS Subgraph API URLs as a function of ENSNODE_URL_* values by taking any ENSNode URL and just appending
/subgraphto the end.Ex: