@ensnode/ensnode-sdk 0.0.0-next-20260102143513
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +192 -0
- package/dist/index.cjs +4396 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4592 -0
- package/dist/index.d.ts +4592 -0
- package/dist/index.js +4378 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NameHash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# ENSNode SDK
|
|
2
|
+
|
|
3
|
+
This package is a set of libraries enabling smooth interaction with ENSNode services and data, including shared types, data processing (such as validating data and enforcing invariants), and ENS-oriented helper functions.
|
|
4
|
+
|
|
5
|
+
Learn more about [ENSNode](https://ensnode.io/) from [the ENSNode docs](https://ensnode.io/docs/).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ensnode/ensnode-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## ENSNode Client
|
|
14
|
+
|
|
15
|
+
The `ENSNodeClient` provides a unified interface for the supported ENSNode APIs:
|
|
16
|
+
- Resolution API (Protocol Accelerated Forward/Reverse Resolution)
|
|
17
|
+
- Indexing Status API
|
|
18
|
+
- Configuration API
|
|
19
|
+
|
|
20
|
+
### Basic Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { ENSNodeClient, evmChainIdToCoinType } from "@ensnode/ensnode-sdk";
|
|
24
|
+
import { mainnet } from 'viem/chains';
|
|
25
|
+
|
|
26
|
+
const client = new ENSNodeClient();
|
|
27
|
+
|
|
28
|
+
// Resolution API: Records Resolution
|
|
29
|
+
const { records } = await client.resolveRecords("jesse.base.eth", {
|
|
30
|
+
addresses: [evmChainIdToCoinType(mainnet.id)],
|
|
31
|
+
texts: ["avatar", "com.twitter"],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Resolution API: Primary Name Resolution
|
|
35
|
+
const { name } = await client.resolvePrimaryName("0x179A862703a4adfb29896552DF9e307980D19285", mainnet.id);
|
|
36
|
+
// name === 'gregskril.eth'
|
|
37
|
+
|
|
38
|
+
// Resolution API: Primary Names Resolution
|
|
39
|
+
const { names } = await client.resolvePrimaryNames("0x179A862703a4adfb29896552DF9e307980D19285");
|
|
40
|
+
// names === { '1': 'gregskril.eth', "8453": "greg.base.eth", ... }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### API Methods
|
|
44
|
+
|
|
45
|
+
#### Resolution API
|
|
46
|
+
|
|
47
|
+
##### `resolveRecords(name, selection, options)`
|
|
48
|
+
|
|
49
|
+
Resolves records for an ENS name (Forward Resolution), via ENSNode, which implements Protocol Acceleration for indexed names.
|
|
50
|
+
|
|
51
|
+
The returned `name` field, if set, is guaranteed to be a [Normalized Name](https://ensnode.io/docs/reference/terminology#normalized-name). If the name record returned by the resolver is not normalized, `null` is returned as if no name record was set.
|
|
52
|
+
|
|
53
|
+
- `name`: The ENS Name whose records to resolve
|
|
54
|
+
- `selection`: Optional selection of Resolver records:
|
|
55
|
+
- `addresses`: Array of coin types to resolve addresses for
|
|
56
|
+
- `texts`: Array of text record keys to resolve
|
|
57
|
+
- `options`: (optional) additional options
|
|
58
|
+
- `trace`: (optional) Whether to include a trace in the response (default: false)
|
|
59
|
+
- `accelerate`: (optional) Whether to attempt Protocol Acceleration (default: false)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { mainnet, base } from 'viem/chains';
|
|
64
|
+
|
|
65
|
+
const { records } = await client.resolveRecords("greg.base.eth", {
|
|
66
|
+
// Resolve ETH Mainnet Address (if set) and Base Address (if set)
|
|
67
|
+
addresses: [evmChainIdToCoinType(mainnet.id), evmChainIdToCoinType(base.id)],
|
|
68
|
+
// or pass the CoinTypes directly if you know them
|
|
69
|
+
// addresses: [60, 2147492101],
|
|
70
|
+
texts: ["avatar", "com.twitter"],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
console.log(records);
|
|
74
|
+
// {
|
|
75
|
+
// "addresses": {
|
|
76
|
+
// "60": "0x179A862703a4adfb29896552DF9e307980D19285",
|
|
77
|
+
// "2147492101": "0x179A862703a4adfb29896552DF9e307980D19285"
|
|
78
|
+
// },
|
|
79
|
+
// "texts": {
|
|
80
|
+
// "avatar": "https://...",
|
|
81
|
+
// "com.twitter": "gregskril"
|
|
82
|
+
// }
|
|
83
|
+
// }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
##### `resolvePrimaryName(address, chainId, options)`
|
|
87
|
+
|
|
88
|
+
Resolves the primary name of the provided `address` on the specified `chainId`, via ENSNode, which implements Protocol Acceleration for indexed names. If the chainId-specific Primary Name is not defined, but the `address` specifies a valid [ENSIP-19 Default Name](https://docs.ens.domains/ensip/19/#default-primary-name), the Default Name will be returned. You _may_ query the Default EVM Chain Id (`0`) in order to determine the `address`'s Default Name directly.
|
|
89
|
+
|
|
90
|
+
The returned Primary Name, if set, is guaranteed to be a [Normalized Name](https://ensnode.io/docs/reference/terminology#normalized-name). If the primary name set for the address is not normalized, `null` is returned as if no primary name was set.
|
|
91
|
+
|
|
92
|
+
- `address`: The Address whose Primary Name to resolve
|
|
93
|
+
- `chainId`: The chain id within which to query the address' ENSIP-19 Multichain Primary Name
|
|
94
|
+
- `options`: (optional) additional options
|
|
95
|
+
- `trace`: (optional) Whether to include a trace in the response (default: false)
|
|
96
|
+
- `accelerate`: (optional) Whether to attempt Protocol Acceleration (default: false)
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { mainnet, base } from 'viem/chains';
|
|
100
|
+
import { DEFAULT_EVM_CHAIN_ID } from '@ensnode/ensnode-sdk';
|
|
101
|
+
|
|
102
|
+
// Resolve the address' Primary Name on Ethereum Mainnet
|
|
103
|
+
const { name } = await client.resolvePrimaryName("0x179A862703a4adfb29896552DF9e307980D19285", mainnet.id);
|
|
104
|
+
// name === 'gregskril.eth'
|
|
105
|
+
|
|
106
|
+
// Resolve the address' Primary Name on Base
|
|
107
|
+
const { name } = await client.resolvePrimaryName("0x179A862703a4adfb29896552DF9e307980D19285", base.id);
|
|
108
|
+
// name === 'greg.base.eth'
|
|
109
|
+
|
|
110
|
+
// Resolve the address' Default Primary Name
|
|
111
|
+
const { name } = await client.resolvePrimaryName("0x179A862703a4adfb29896552DF9e307980D19285", DEFAULT_EVM_CHAIN_ID);
|
|
112
|
+
// name === 'gregskril.eth'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
##### `resolvePrimaryNames(address, options)`
|
|
116
|
+
|
|
117
|
+
Resolves the primary names of the provided `address` on the specified chainIds, via ENSNode, which implements Protocol Acceleration for indexed names. For each Primary Name, if the chainId-specific Primary Name is not defined, but the `address` specifies a valid [ENSIP-19 Default Name](https://docs.ens.domains/ensip/19/#default-primary-name), the Default Name will be returned. You _may not_ query the Default EVM Chain Id (`0`) directly, and should rely on the aforementioned per-chain defaulting behavior.
|
|
118
|
+
|
|
119
|
+
Each returned Primary Name, if set, is guaranteed to be a [Normalized Name](https://ensnode.io/docs/reference/terminology#normalized-name). If the primary name set for the address on any chain is not normalized, `null` is returned for that chain as if no primary name was set.
|
|
120
|
+
|
|
121
|
+
- `address`: The Address whose Primary Names to resolve
|
|
122
|
+
- `options`: (optional) additional options
|
|
123
|
+
- `chainIds`: The chain ids within which to query the address' ENSIP-19 Multichain Primary Name (default: all ENSIP-19 supported chains)
|
|
124
|
+
- `trace`: (optional) Whether to include a trace in the response (default: false)
|
|
125
|
+
- `accelerate`: (optional) Whether to attempt Protocol Acceleration (default: false)
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { mainnet, base } from 'viem/chains';
|
|
129
|
+
|
|
130
|
+
// Resolve an address' Primary Names on all ENSIP-19 supported chain ids
|
|
131
|
+
const { names } = await client.resolvePrimaryNames("0x179A862703a4adfb29896552DF9e307980D19285");
|
|
132
|
+
|
|
133
|
+
console.log(names);
|
|
134
|
+
// {
|
|
135
|
+
// "1": "gregskril.eth", // Default Primary Name
|
|
136
|
+
// "10": "gregskril.eth", // Default Primary Name
|
|
137
|
+
// "8453": "greg.base.eth", // Base-specific Primary Name!
|
|
138
|
+
// "42161": "gregskril.eth", // Default Primary Name
|
|
139
|
+
// "59144": "gregskril.eth", // Default Primary Name
|
|
140
|
+
// "534352": "gregskril.eth" // Default Primary Name
|
|
141
|
+
// }
|
|
142
|
+
|
|
143
|
+
// Resolve an address' Primary Names on specific chain Ids
|
|
144
|
+
const { names } = await client.resolvePrimaryNames("0x179A862703a4adfb29896552DF9e307980D19285", {
|
|
145
|
+
chainIds: [mainnet.id, base.id],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(names);
|
|
149
|
+
// {
|
|
150
|
+
// "1": "gregskril.eth",
|
|
151
|
+
// "8453": "greg.base.eth", // base-specific Primary Name!
|
|
152
|
+
// }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Configuration API
|
|
156
|
+
|
|
157
|
+
##### `config()`
|
|
158
|
+
|
|
159
|
+
Fetches the ENSNode's configuration.
|
|
160
|
+
|
|
161
|
+
- Returns: `ConfigResponse` - The ENSNode configuration data
|
|
162
|
+
- Throws: Error if the request fails or the ENSNode API returns an error response
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const config = await client.config();
|
|
166
|
+
console.log(config);
|
|
167
|
+
// Returns the ENSNode configuration including indexed chains, etc.
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Indexing Status API
|
|
171
|
+
|
|
172
|
+
##### `indexingStatus()`
|
|
173
|
+
|
|
174
|
+
Fetches the ENSNode's multichain indexing status.
|
|
175
|
+
|
|
176
|
+
- Returns: `IndexingStatusResponse` - The indexing status data for all indexed chains
|
|
177
|
+
- Throws: Error if the request fails or the ENSNode API returns an error response
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// Get current indexing status
|
|
181
|
+
const status = await client.indexingStatus();
|
|
182
|
+
console.log(status);
|
|
183
|
+
// Returns indexing status for all indexed chains
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Configuration
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
const client = new ENSNodeClient({
|
|
190
|
+
url: new URL("https://my-ensnode-instance.com"),
|
|
191
|
+
});
|
|
192
|
+
```
|