Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/ensnode-react-example/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 NameHash

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions examples/ensnode-react-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ensnode-react Example

A minimal React app demonstrating how to use `@ensnode/ensnode-react` to resolve
an address' Mainnet Primary Name (via `usePrimaryName`).

By default it connects to the NameHash-hosted alpha ENSNode at
`https://api.alpha.ensnode.io`.

## Usage

```bash
pnpm install
pnpm -F @ensnode/ensnode-react-example dev
```

To point at a different ENSNode, set `VITE_ENSNODE_URL`:

```bash
VITE_ENSNODE_URL=http://localhost:4334 pnpm -F @ensnode/ensnode-react-example dev
```
12 changes: 12 additions & 0 deletions examples/ensnode-react-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ensnode-react Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/ensnode-react-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@ensnode/ensnode-react-example",
"private": true,
"version": "0.0.1",
"license": "MIT",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"typecheck": "tsgo --noEmit"
},
"dependencies": {
"@ensnode/ensnode-react": "workspace:*",
"@ensnode/ensnode-sdk": "workspace:*",
"@tanstack/react-query": "^5.62.14",
"enssdk": "workspace:*",
"react": "catalog:",
"react-dom": "catalog:"
},
"devDependencies": {
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"@vitejs/plugin-react": "^4.5.2",
"typescript": "catalog:",
"vite": "catalog:"
}
}
25 changes: 25 additions & 0 deletions examples/ensnode-react-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StrictMode } from "react";

import { createEnsNodeProviderOptions, EnsNodeProvider } from "@ensnode/ensnode-react";

import { PrimaryNameView } from "./PrimaryNameView";

const ENSNODE_URL = import.meta.env.VITE_ENSNODE_URL ?? "https://api.alpha.ensnode.io";

const options = createEnsNodeProviderOptions({ url: ENSNODE_URL });

export function App() {
return (
<StrictMode>
<EnsNodeProvider options={options}>
<h1>
<code>ensnode-react</code> Example App
</h1>
<p>
Connected to <code>{ENSNODE_URL}</code>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this example app to achieve its goals, we need it to implement more critical ideas:

  1. How is it guaranteeing that it was able to successfully connect to the provided ENSNode?
  2. If for some reason it was unable to connect to the provided ENSNode, how is this case being gracefully handled? All the meaningfully distinct edge cases should have explicit handling. I don't want to see just a single "error connecting". I want more detailed error recognition such that you can disambiguate an error connecting (network-level error) from an unsupported ENSNode error (application-level error) where the config returned by the connected ENSNode is either not fetched or deserialized successfully.
  3. How is this app managing the latest indexing status projection / snapshot asynchronously in the background? I want to see a UI component for this in the example app similar to what's implemented for this inside the ENSAdmin UI (the little info icon).
  4. How is this app navigating the vital question of ENS Namespace? There's 2 options for this:
    1. Option 1: The example app hardcodes its own ENS Namespace configuration (ex: mainnet) and then upon connecting to an ENSNode instance, verifies that its config matches the expected namespace. If it doesn't, the example app should refuse the connection.
    2. Option 2: The example app doesn't hardcode any ENS Namespace configuration. Instead, it waits to connect to an ENSNode instance and then makes use of the whatever namespace that ENSNode instance's config is using.

I believe that Option 1 is the direction that 99% of our customers will want to use as there are benefits to knowing the ENS namespace even before a successful connection to ENSNode is established. Therefore this example app should implement Option 1.

That means this example app should also read an ENS namespace as an environment variable that defaults to mainnet.

</p>
<PrimaryNameView />
</EnsNodeProvider>
</StrictMode>
);
}
51 changes: 51 additions & 0 deletions examples/ensnode-react-example/src/PrimaryNameView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Address, ChainId } from "enssdk";
import { useState } from "react";

import { usePrimaryName } from "@ensnode/ensnode-react";

const DEFAULT_ADDRESS: Address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All address values we use in this app should use NormalizedAddress as imported from enssdk. You also need to call a utility function such as asNormalizedAddress on this hardcoded address string.

const MAINNET: ChainId = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This form shouldn't hardcode the chainId this way and also make reference to ENSIP-19 (which is multichain).

We should reference what we've already built for this idea before in ENSAdmin.

CleanShot 2026-05-04 at 14 20 16


export function PrimaryNameView() {
const [address, setAddress] = useState<Address>(DEFAULT_ADDRESS);
const [input, setInput] = useState<string>(DEFAULT_ADDRESS);

const { data, isLoading, error } = usePrimaryName({
address,
chainId: MAINNET,
accelerate: true,
});

return (
<div>
<h2>Primary Name</h2>
<p>
Resolves the ENSIP-19 Mainnet Primary Name for an address using <code>usePrimaryName</code>.
</p>

<form
onSubmit={(event) => {
event.preventDefault();
setAddress(input as Address);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notrab I need to stop seeing code like this. Ever. It completely goes against our culture as a team and company. I'm going completely crazy at how many times I have to repeat the related ideas. There's so many problems in this 1 line of code I'm not going to spend the time to explain them all over and over again.

}}
>
<input
type="text"
value={input}
onChange={(event) => setInput(event.target.value)}
placeholder="0x..."
style={{ width: "28rem" }}
/>
<button type="submit">Resolve</button>
</form>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

{isLoading && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
{data && (
<p>
Primary Name: <strong>{data.name ?? "(none)"}</strong>
</p>
)}
</div>
);
}
6 changes: 6 additions & 0 deletions examples/ensnode-react-example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createRoot } from "react-dom/client";

import { App } from "./App";

// biome-ignore lint/style/noNonNullAssertion: the #root element definitely exists (see index.html)
createRoot(document.getElementById("root")!).render(<App />);
1 change: 1 addition & 0 deletions examples/ensnode-react-example/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions examples/ensnode-react-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"lib": ["ESNext", "DOM", "DOM.Iterable"]
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions examples/ensnode-react-example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [react()],
});
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading