@monadns/sdk 1.0.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Monad Name Service
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,112 @@
1
+ # @monadns/sdk
2
+
3
+ Resolve **.mon** names on the Monad network. The official SDK for the Monad Name Service.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @monadns/sdk viem
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { resolveName, lookupAddress } from '@monadns/sdk';
15
+
16
+ // Forward: name → address
17
+ const address = await resolveName('alice.mon');
18
+ // '0xa0123BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'
19
+
20
+ // Reverse: address → name
21
+ const name = await lookupAddress('0xa0123BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47');
22
+ // 'alice.mon'
23
+ ```
24
+
25
+ ## React Hooks
26
+
27
+ ```bash
28
+ npm install @monadns/sdk viem react
29
+ ```
30
+
31
+ ```tsx
32
+ import { useMNSDisplay, useMNSResolve } from '@monadns/sdk/react';
33
+
34
+ // Display .mon name instead of address
35
+ function UserBadge({ address }: { address: string }) {
36
+ const { displayName, monName } = useMNSDisplay(address);
37
+ return <span className={monName ? 'font-bold' : ''}>{displayName}</span>;
38
+ }
39
+
40
+ // Input field that accepts names or addresses
41
+ function RecipientInput() {
42
+ const { resolve, address, loading, error } = useMNSResolve();
43
+ return (
44
+ <div>
45
+ <input
46
+ placeholder="Address or .mon name"
47
+ onChange={(e) => resolve(e.target.value)}
48
+ />
49
+ {loading && <span>Resolving...</span>}
50
+ {address && <span>→ {address}</span>}
51
+ {error && <span>{error}</span>}
52
+ </div>
53
+ );
54
+ }
55
+ ```
56
+
57
+ ## API Reference
58
+
59
+ ### Core Functions
60
+
61
+ | Function | Description |
62
+ | -------------------------- | ---------------------------------------- |
63
+ | `resolveName(name)` | Forward resolve: `alice.mon` → `0x...` |
64
+ | `lookupAddress(address)` | Reverse resolve: `0x...` → `alice.mon` |
65
+ | `getDisplayName(address)` | Returns `.mon` name or truncated address |
66
+ | `resolveInput(input)` | Accepts name or address, returns address |
67
+ | `getTextRecord(name, key)` | Get text record (avatar, url, etc.) |
68
+ | `isRegistered(name)` | Check if a name is taken |
69
+ | `clearCache()` | Clear the resolution cache |
70
+
71
+ ### React Hooks
72
+
73
+ | Hook | Description |
74
+ | ------------------------ | -------------------------------------------- |
75
+ | `useMNSName(address)` | `{ name, loading, error }` |
76
+ | `useMNSAddress(name)` | `{ address, loading, error }` |
77
+ | `useMNSDisplay(address)` | `{ displayName, monName, loading }` |
78
+ | `useMNSResolve()` | `{ resolve, address, name, loading, error }` |
79
+ | `useMNSText(name, key)` | `{ value, loading, error }` |
80
+
81
+ ### Custom RPC
82
+
83
+ All functions accept an optional config object:
84
+
85
+ ```typescript
86
+ const name = await lookupAddress('0x...', {
87
+ rpcUrl: 'https://your-custom-rpc.com',
88
+ });
89
+ ```
90
+
91
+ Or pass an existing viem client:
92
+
93
+ ```typescript
94
+ import { createPublicClient, http } from 'viem';
95
+ import { monad } from 'viem/chains';
96
+
97
+ const client = createPublicClient({ chain: monad, transport: http() });
98
+ const name = await lookupAddress('0x...', { client });
99
+ ```
100
+
101
+ ## Contracts
102
+
103
+ | Contract | Address |
104
+ | --------------- | -------------------------------------------- |
105
+ | Registry | `0x13f963486e741c8d3fcdc0a34a910920339a19ce` |
106
+ | Public Resolver | `0xa2eb94c88e55d944aced2066c5cec9b759801f97` |
107
+
108
+ Chain: Monad Mainnet (Chain ID 143)
109
+
110
+ ## License
111
+
112
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ MNS_PUBLIC_RESOLVER: () => MNS_PUBLIC_RESOLVER,
24
+ MNS_REGISTRY: () => MNS_REGISTRY,
25
+ clearCache: () => clearCache,
26
+ getDisplayName: () => getDisplayName,
27
+ getMNSClient: () => getMNSClient,
28
+ getTextRecord: () => getTextRecord,
29
+ isRegistered: () => isRegistered,
30
+ lookupAddress: () => lookupAddress,
31
+ resolveInput: () => resolveInput,
32
+ resolveName: () => resolveName
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+
36
+ // src/resolve.ts
37
+ var import_viem2 = require("viem");
38
+
39
+ // src/client.ts
40
+ var import_viem = require("viem");
41
+ var import_chains = require("viem/chains");
42
+ var defaultClient = null;
43
+ function getMNSClient(config) {
44
+ if (config?.client) return config.client;
45
+ if (config?.rpcUrl) {
46
+ return (0, import_viem.createPublicClient)({
47
+ chain: import_chains.monad,
48
+ transport: (0, import_viem.http)(config.rpcUrl)
49
+ });
50
+ }
51
+ if (!defaultClient) {
52
+ defaultClient = (0, import_viem.createPublicClient)({
53
+ chain: import_chains.monad,
54
+ transport: (0, import_viem.http)()
55
+ });
56
+ }
57
+ return defaultClient;
58
+ }
59
+
60
+ // src/constants.ts
61
+ var MNS_REGISTRY = "0x13f963486e741c8d3fcdc0a34a910920339a19ce";
62
+ var MNS_PUBLIC_RESOLVER = "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
63
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
64
+ var registryAbi = [
65
+ {
66
+ name: "resolver",
67
+ type: "function",
68
+ inputs: [{ name: "node", type: "bytes32" }],
69
+ outputs: [{ name: "", type: "address" }],
70
+ stateMutability: "view"
71
+ }
72
+ ];
73
+ var resolverAbi = [
74
+ {
75
+ name: "addr",
76
+ type: "function",
77
+ inputs: [{ name: "node", type: "bytes32" }],
78
+ outputs: [{ name: "", type: "address" }],
79
+ stateMutability: "view"
80
+ },
81
+ {
82
+ name: "name",
83
+ type: "function",
84
+ inputs: [{ name: "node", type: "bytes32" }],
85
+ outputs: [{ name: "", type: "string" }],
86
+ stateMutability: "view"
87
+ },
88
+ {
89
+ name: "text",
90
+ type: "function",
91
+ inputs: [
92
+ { name: "node", type: "bytes32" },
93
+ { name: "key", type: "string" }
94
+ ],
95
+ outputs: [{ name: "", type: "string" }],
96
+ stateMutability: "view"
97
+ }
98
+ ];
99
+
100
+ // src/resolve.ts
101
+ var nameCache = /* @__PURE__ */ new Map();
102
+ var addrCache = /* @__PURE__ */ new Map();
103
+ var CACHE_TTL = 6e4;
104
+ function getCached(cache, key) {
105
+ const entry = cache.get(key);
106
+ if (entry && Date.now() - entry.ts < CACHE_TTL) return entry.value;
107
+ return void 0;
108
+ }
109
+ async function resolveName(name, config) {
110
+ const key = name.toLowerCase();
111
+ const cached = getCached(addrCache, key);
112
+ if (cached !== void 0) return cached;
113
+ try {
114
+ const client = getMNSClient(config);
115
+ const node = (0, import_viem2.namehash)(key);
116
+ const resolver = await client.readContract({
117
+ address: MNS_REGISTRY,
118
+ abi: registryAbi,
119
+ functionName: "resolver",
120
+ args: [node]
121
+ });
122
+ if (resolver === ZERO_ADDRESS) {
123
+ addrCache.set(key, { value: null, ts: Date.now() });
124
+ return null;
125
+ }
126
+ const addr = await client.readContract({
127
+ address: resolver,
128
+ abi: resolverAbi,
129
+ functionName: "addr",
130
+ args: [node]
131
+ });
132
+ const result = addr === ZERO_ADDRESS ? null : addr;
133
+ addrCache.set(key, { value: result, ts: Date.now() });
134
+ return result;
135
+ } catch {
136
+ addrCache.set(key, { value: null, ts: Date.now() });
137
+ return null;
138
+ }
139
+ }
140
+ async function lookupAddress(address, config) {
141
+ const key = address.toLowerCase();
142
+ const cached = getCached(nameCache, key);
143
+ if (cached !== void 0) return cached;
144
+ try {
145
+ const client = getMNSClient(config);
146
+ const reverseNode = (0, import_viem2.namehash)(
147
+ `${key.slice(2)}.addr.reverse`
148
+ );
149
+ const resolver = await client.readContract({
150
+ address: MNS_REGISTRY,
151
+ abi: registryAbi,
152
+ functionName: "resolver",
153
+ args: [reverseNode]
154
+ });
155
+ if (resolver === ZERO_ADDRESS) {
156
+ nameCache.set(key, { value: null, ts: Date.now() });
157
+ return null;
158
+ }
159
+ const name = await client.readContract({
160
+ address: resolver,
161
+ abi: resolverAbi,
162
+ functionName: "name",
163
+ args: [reverseNode]
164
+ });
165
+ const result = name || null;
166
+ nameCache.set(key, { value: result, ts: Date.now() });
167
+ return result;
168
+ } catch {
169
+ nameCache.set(key, { value: null, ts: Date.now() });
170
+ return null;
171
+ }
172
+ }
173
+ async function getTextRecord(name, key, config) {
174
+ try {
175
+ const client = getMNSClient(config);
176
+ const node = (0, import_viem2.namehash)(name.toLowerCase());
177
+ const resolver = await client.readContract({
178
+ address: MNS_REGISTRY,
179
+ abi: registryAbi,
180
+ functionName: "resolver",
181
+ args: [node]
182
+ });
183
+ if (resolver === ZERO_ADDRESS) return null;
184
+ const value = await client.readContract({
185
+ address: resolver,
186
+ abi: resolverAbi,
187
+ functionName: "text",
188
+ args: [node, key]
189
+ });
190
+ return value || null;
191
+ } catch {
192
+ return null;
193
+ }
194
+ }
195
+ async function getDisplayName(address, config) {
196
+ const name = await lookupAddress(address, config);
197
+ if (name) return name;
198
+ return `${address.slice(0, 6)}...${address.slice(-4)}`;
199
+ }
200
+ async function resolveInput(input, config) {
201
+ const trimmed = input.trim();
202
+ if (!trimmed) return null;
203
+ if (trimmed.startsWith("0x") && trimmed.length === 42) return trimmed;
204
+ if (trimmed.endsWith(".mon")) return resolveName(trimmed, config);
205
+ return resolveName(`${trimmed}.mon`, config);
206
+ }
207
+ async function isRegistered(name, config) {
208
+ const addr = await resolveName(name, config);
209
+ return addr !== null;
210
+ }
211
+ function clearCache() {
212
+ nameCache.clear();
213
+ addrCache.clear();
214
+ }
215
+ // Annotate the CommonJS export names for ESM import in node:
216
+ 0 && (module.exports = {
217
+ MNS_PUBLIC_RESOLVER,
218
+ MNS_REGISTRY,
219
+ clearCache,
220
+ getDisplayName,
221
+ getMNSClient,
222
+ getTextRecord,
223
+ isRegistered,
224
+ lookupAddress,
225
+ resolveInput,
226
+ resolveName
227
+ });
228
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/resolve.ts","../src/client.ts","../src/constants.ts"],"sourcesContent":["// Core resolution\nexport {\n resolveName,\n lookupAddress,\n getTextRecord,\n getDisplayName,\n resolveInput,\n isRegistered,\n clearCache,\n} from './resolve';\n\n// Client config\nexport { getMNSClient } from './client';\nexport type { MNSClientConfig } from './client';\n\n// Constants\nexport { MNS_REGISTRY, MNS_PUBLIC_RESOLVER } from './constants';\n","import { namehash } from 'viem';\nimport { getMNSClient, type MNSClientConfig } from './client';\nimport {\n MNS_REGISTRY,\n ZERO_ADDRESS,\n registryAbi,\n resolverAbi,\n} from './constants';\n\n// ─── Cache ─────────────────────────────────────────────────────\n\nconst nameCache = new Map<string, { value: string | null; ts: number }>();\nconst addrCache = new Map<string, { value: string | null; ts: number }>();\n\nconst CACHE_TTL = 60_000; // 1 minute\n\nfunction getCached(\n cache: Map<string, { value: string | null; ts: number }>,\n key: string,\n) {\n const entry = cache.get(key);\n if (entry && Date.now() - entry.ts < CACHE_TTL) return entry.value;\n return undefined;\n}\n\n// ─── Forward Resolution ────────────────────────────────────────\n\n/**\n * Resolve a .mon name to an address.\n *\n * @param name - Full name including .mon (e.g. \"alice.mon\")\n * @param config - Optional client configuration\n * @returns The resolved address, or null if not found\n *\n * @example\n * ```ts\n * import { resolveName } from '@monadns/sdk'\n *\n * const address = await resolveName('alice.mon')\n * // '0xa05a8BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'\n * ```\n */\nexport async function resolveName(\n name: string,\n config?: MNSClientConfig,\n): Promise<string | null> {\n const key = name.toLowerCase();\n const cached = getCached(addrCache, key);\n if (cached !== undefined) return cached;\n\n try {\n const client = getMNSClient(config);\n const node = namehash(key) as `0x${string}`;\n\n const resolver = await client.readContract({\n address: MNS_REGISTRY,\n abi: registryAbi,\n functionName: 'resolver',\n args: [node],\n });\n\n if (resolver === ZERO_ADDRESS) {\n addrCache.set(key, { value: null, ts: Date.now() });\n return null;\n }\n\n const addr = await client.readContract({\n address: resolver,\n abi: resolverAbi,\n functionName: 'addr',\n args: [node],\n });\n\n const result = addr === ZERO_ADDRESS ? null : addr;\n addrCache.set(key, { value: result, ts: Date.now() });\n return result;\n } catch {\n addrCache.set(key, { value: null, ts: Date.now() });\n return null;\n }\n}\n\n// ─── Reverse Resolution ────────────────────────────────────────\n\n/**\n * Look up the primary .mon name for an address.\n *\n * @param address - A 0x-prefixed Monad address\n * @param config - Optional client configuration\n * @returns The primary name (e.g. \"alice.mon\"), or null\n *\n * @example\n * ```ts\n * import { lookupAddress } from '@monadns/sdk'\n *\n * const name = await lookupAddress('0xa05a8BF1...')\n * // 'alice.mon'\n * ```\n */\nexport async function lookupAddress(\n address: string,\n config?: MNSClientConfig,\n): Promise<string | null> {\n const key = address.toLowerCase();\n const cached = getCached(nameCache, key);\n if (cached !== undefined) return cached;\n\n try {\n const client = getMNSClient(config);\n const reverseNode = namehash(\n `${key.slice(2)}.addr.reverse`,\n ) as `0x${string}`;\n\n const resolver = await client.readContract({\n address: MNS_REGISTRY,\n abi: registryAbi,\n functionName: 'resolver',\n args: [reverseNode],\n });\n\n if (resolver === ZERO_ADDRESS) {\n nameCache.set(key, { value: null, ts: Date.now() });\n return null;\n }\n\n const name = await client.readContract({\n address: resolver,\n abi: resolverAbi,\n functionName: 'name',\n args: [reverseNode],\n });\n\n const result = name || null;\n nameCache.set(key, { value: result, ts: Date.now() });\n return result;\n } catch {\n nameCache.set(key, { value: null, ts: Date.now() });\n return null;\n }\n}\n\n// ─── Text Records ──────────────────────────────────────────────\n\n/**\n * Get a text record for a .mon name.\n *\n * @param name - Full name including .mon\n * @param key - The text record key (e.g. \"avatar\", \"url\", \"com.twitter\")\n * @param config - Optional client configuration\n *\n * @example\n * ```ts\n * const avatar = await getTextRecord('alice.mon', 'avatar')\n * const twitter = await getTextRecord('alice.mon', 'com.twitter')\n * ```\n */\nexport async function getTextRecord(\n name: string,\n key: string,\n config?: MNSClientConfig,\n): Promise<string | null> {\n try {\n const client = getMNSClient(config);\n const node = namehash(name.toLowerCase()) as `0x${string}`;\n\n const resolver = await client.readContract({\n address: MNS_REGISTRY,\n abi: registryAbi,\n functionName: 'resolver',\n args: [node],\n });\n\n if (resolver === ZERO_ADDRESS) return null;\n\n const value = await client.readContract({\n address: resolver,\n abi: resolverAbi,\n functionName: 'text',\n args: [node, key],\n });\n\n return value || null;\n } catch {\n return null;\n }\n}\n\n// ─── Helpers ───────────────────────────────────────────────────\n\n/**\n * Get a display-friendly name for an address.\n * Returns the .mon name if set, otherwise a truncated address.\n *\n * @example\n * ```ts\n * const display = await getDisplayName('0xa05a8BF1...')\n * // 'alice.mon' or '0xa05a...Cc47'\n * ```\n */\nexport async function getDisplayName(\n address: string,\n config?: MNSClientConfig,\n): Promise<string> {\n const name = await lookupAddress(address, config);\n if (name) return name;\n return `${address.slice(0, 6)}...${address.slice(-4)}`;\n}\n\n/**\n * Smart resolver — accepts either a .mon name or a raw address.\n * Useful for input fields where users can type either.\n *\n * @returns The resolved address, or null if invalid/not found\n *\n * @example\n * ```ts\n * const addr = await resolveInput('alice.mon') // resolves name\n * const addr = await resolveInput('alice') // tries alice.mon\n * const addr = await resolveInput('0xa05a...') // passes through\n * ```\n */\nexport async function resolveInput(\n input: string,\n config?: MNSClientConfig,\n): Promise<string | null> {\n const trimmed = input.trim();\n if (!trimmed) return null;\n\n if (trimmed.startsWith('0x') && trimmed.length === 42) return trimmed;\n if (trimmed.endsWith('.mon')) return resolveName(trimmed, config);\n\n // Try appending .mon\n return resolveName(`${trimmed}.mon`, config);\n}\n\n/**\n * Check if a .mon name is registered.\n *\n * @example\n * ```ts\n * const taken = await isRegistered('alice.mon')\n * ```\n */\nexport async function isRegistered(\n name: string,\n config?: MNSClientConfig,\n): Promise<boolean> {\n const addr = await resolveName(name, config);\n return addr !== null;\n}\n\n/**\n * Clear the internal resolution cache.\n * Useful after a new registration.\n */\nexport function clearCache() {\n nameCache.clear();\n addrCache.clear();\n}\n","import {\n createPublicClient,\n http,\n type PublicClient,\n type Chain,\n type Transport,\n} from 'viem';\nimport { monad } from 'viem/chains';\n\nexport type MNSClientConfig = {\n /** Custom RPC URL. Defaults to the public Monad RPC. */\n rpcUrl?: string;\n /** Existing viem PublicClient to reuse instead of creating a new one. */\n client?: PublicClient<Transport, Chain>;\n};\n\nlet defaultClient: PublicClient<Transport, Chain> | null = null;\n\n/**\n * Get or create the MNS public client.\n * Reuses a singleton by default; pass config to override.\n */\nexport function getMNSClient(\n config?: MNSClientConfig,\n): PublicClient<Transport, Chain> {\n if (config?.client) return config.client;\n\n if (config?.rpcUrl) {\n return createPublicClient({\n chain: monad,\n transport: http(config.rpcUrl),\n });\n }\n\n if (!defaultClient) {\n defaultClient = createPublicClient({\n chain: monad,\n transport: http(),\n });\n }\n\n return defaultClient;\n}\n","export const MNS_REGISTRY =\n '0x13f963486e741c8d3fcdc0a34a910920339a19ce' as const;\nexport const MNS_PUBLIC_RESOLVER =\n '0xa2eb94c88e55d944aced2066c5cec9b759801f97' as const;\n\nexport const ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as const;\n\nexport const registryAbi = [\n {\n name: 'resolver',\n type: 'function',\n inputs: [{ name: 'node', type: 'bytes32' }],\n outputs: [{ name: '', type: 'address' }],\n stateMutability: 'view',\n },\n] as const;\n\nexport const resolverAbi = [\n {\n name: 'addr',\n type: 'function',\n inputs: [{ name: 'node', type: 'bytes32' }],\n outputs: [{ name: '', type: 'address' }],\n stateMutability: 'view',\n },\n {\n name: 'name',\n type: 'function',\n inputs: [{ name: 'node', type: 'bytes32' }],\n outputs: [{ name: '', type: 'string' }],\n stateMutability: 'view',\n },\n {\n name: 'text',\n type: 'function',\n inputs: [\n { name: 'node', type: 'bytes32' },\n { name: 'key', type: 'string' },\n ],\n outputs: [{ name: '', type: 'string' }],\n stateMutability: 'view',\n },\n] as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAAyB;;;ACAzB,kB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,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAcA,eAAsB,eACpB,SACA,QACiB;AACjB,QAAM,OAAO,MAAM,cAAc,SAAS,MAAM;AAChD,MAAI,KAAM,QAAO;AACjB,SAAO,GAAG,QAAQ,MAAM,GAAG,CAAC,CAAC,MAAM,QAAQ,MAAM,EAAE,CAAC;AACtD;AAeA,eAAsB,aACpB,OACA,QACwB;AACxB,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,QAAS,QAAO;AAErB,MAAI,QAAQ,WAAW,IAAI,KAAK,QAAQ,WAAW,GAAI,QAAO;AAC9D,MAAI,QAAQ,SAAS,MAAM,EAAG,QAAO,YAAY,SAAS,MAAM;AAGhE,SAAO,YAAY,GAAG,OAAO,QAAQ,MAAM;AAC7C;AAUA,eAAsB,aACpB,MACA,QACkB;AAClB,QAAM,OAAO,MAAM,YAAY,MAAM,MAAM;AAC3C,SAAO,SAAS;AAClB;AAMO,SAAS,aAAa;AAC3B,YAAU,MAAM;AAChB,YAAU,MAAM;AAClB;","names":["import_viem"]}
@@ -0,0 +1,104 @@
1
+ import { PublicClient, Transport, Chain } from 'viem';
2
+
3
+ type MNSClientConfig = {
4
+ /** Custom RPC URL. Defaults to the public Monad RPC. */
5
+ rpcUrl?: string;
6
+ /** Existing viem PublicClient to reuse instead of creating a new one. */
7
+ client?: PublicClient<Transport, Chain>;
8
+ };
9
+ /**
10
+ * Get or create the MNS public client.
11
+ * Reuses a singleton by default; pass config to override.
12
+ */
13
+ declare function getMNSClient(config?: MNSClientConfig): PublicClient<Transport, Chain>;
14
+
15
+ /**
16
+ * Resolve a .mon name to an address.
17
+ *
18
+ * @param name - Full name including .mon (e.g. "alice.mon")
19
+ * @param config - Optional client configuration
20
+ * @returns The resolved address, or null if not found
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { resolveName } from '@monadns/sdk'
25
+ *
26
+ * const address = await resolveName('alice.mon')
27
+ * // '0xa05a8BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'
28
+ * ```
29
+ */
30
+ declare function resolveName(name: string, config?: MNSClientConfig): Promise<string | null>;
31
+ /**
32
+ * Look up the primary .mon name for an address.
33
+ *
34
+ * @param address - A 0x-prefixed Monad address
35
+ * @param config - Optional client configuration
36
+ * @returns The primary name (e.g. "alice.mon"), or null
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { lookupAddress } from '@monadns/sdk'
41
+ *
42
+ * const name = await lookupAddress('0xa05a8BF1...')
43
+ * // 'alice.mon'
44
+ * ```
45
+ */
46
+ declare function lookupAddress(address: string, config?: MNSClientConfig): Promise<string | null>;
47
+ /**
48
+ * Get a text record for a .mon name.
49
+ *
50
+ * @param name - Full name including .mon
51
+ * @param key - The text record key (e.g. "avatar", "url", "com.twitter")
52
+ * @param config - Optional client configuration
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const avatar = await getTextRecord('alice.mon', 'avatar')
57
+ * const twitter = await getTextRecord('alice.mon', 'com.twitter')
58
+ * ```
59
+ */
60
+ declare function getTextRecord(name: string, key: string, config?: MNSClientConfig): Promise<string | null>;
61
+ /**
62
+ * Get a display-friendly name for an address.
63
+ * Returns the .mon name if set, otherwise a truncated address.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const display = await getDisplayName('0xa05a8BF1...')
68
+ * // 'alice.mon' or '0xa05a...Cc47'
69
+ * ```
70
+ */
71
+ declare function getDisplayName(address: string, config?: MNSClientConfig): Promise<string>;
72
+ /**
73
+ * Smart resolver — accepts either a .mon name or a raw address.
74
+ * Useful for input fields where users can type either.
75
+ *
76
+ * @returns The resolved address, or null if invalid/not found
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const addr = await resolveInput('alice.mon') // resolves name
81
+ * const addr = await resolveInput('alice') // tries alice.mon
82
+ * const addr = await resolveInput('0xa05a...') // passes through
83
+ * ```
84
+ */
85
+ declare function resolveInput(input: string, config?: MNSClientConfig): Promise<string | null>;
86
+ /**
87
+ * Check if a .mon name is registered.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const taken = await isRegistered('alice.mon')
92
+ * ```
93
+ */
94
+ declare function isRegistered(name: string, config?: MNSClientConfig): Promise<boolean>;
95
+ /**
96
+ * Clear the internal resolution cache.
97
+ * Useful after a new registration.
98
+ */
99
+ declare function clearCache(): void;
100
+
101
+ declare const MNS_REGISTRY: "0x13f963486e741c8d3fcdc0a34a910920339a19ce";
102
+ declare const MNS_PUBLIC_RESOLVER: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
103
+
104
+ export { type MNSClientConfig, MNS_PUBLIC_RESOLVER, MNS_REGISTRY, clearCache, getDisplayName, getMNSClient, getTextRecord, isRegistered, lookupAddress, resolveInput, resolveName };
@@ -0,0 +1,104 @@
1
+ import { PublicClient, Transport, Chain } from 'viem';
2
+
3
+ type MNSClientConfig = {
4
+ /** Custom RPC URL. Defaults to the public Monad RPC. */
5
+ rpcUrl?: string;
6
+ /** Existing viem PublicClient to reuse instead of creating a new one. */
7
+ client?: PublicClient<Transport, Chain>;
8
+ };
9
+ /**
10
+ * Get or create the MNS public client.
11
+ * Reuses a singleton by default; pass config to override.
12
+ */
13
+ declare function getMNSClient(config?: MNSClientConfig): PublicClient<Transport, Chain>;
14
+
15
+ /**
16
+ * Resolve a .mon name to an address.
17
+ *
18
+ * @param name - Full name including .mon (e.g. "alice.mon")
19
+ * @param config - Optional client configuration
20
+ * @returns The resolved address, or null if not found
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { resolveName } from '@monadns/sdk'
25
+ *
26
+ * const address = await resolveName('alice.mon')
27
+ * // '0xa05a8BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'
28
+ * ```
29
+ */
30
+ declare function resolveName(name: string, config?: MNSClientConfig): Promise<string | null>;
31
+ /**
32
+ * Look up the primary .mon name for an address.
33
+ *
34
+ * @param address - A 0x-prefixed Monad address
35
+ * @param config - Optional client configuration
36
+ * @returns The primary name (e.g. "alice.mon"), or null
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { lookupAddress } from '@monadns/sdk'
41
+ *
42
+ * const name = await lookupAddress('0xa05a8BF1...')
43
+ * // 'alice.mon'
44
+ * ```
45
+ */
46
+ declare function lookupAddress(address: string, config?: MNSClientConfig): Promise<string | null>;
47
+ /**
48
+ * Get a text record for a .mon name.
49
+ *
50
+ * @param name - Full name including .mon
51
+ * @param key - The text record key (e.g. "avatar", "url", "com.twitter")
52
+ * @param config - Optional client configuration
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const avatar = await getTextRecord('alice.mon', 'avatar')
57
+ * const twitter = await getTextRecord('alice.mon', 'com.twitter')
58
+ * ```
59
+ */
60
+ declare function getTextRecord(name: string, key: string, config?: MNSClientConfig): Promise<string | null>;
61
+ /**
62
+ * Get a display-friendly name for an address.
63
+ * Returns the .mon name if set, otherwise a truncated address.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const display = await getDisplayName('0xa05a8BF1...')
68
+ * // 'alice.mon' or '0xa05a...Cc47'
69
+ * ```
70
+ */
71
+ declare function getDisplayName(address: string, config?: MNSClientConfig): Promise<string>;
72
+ /**
73
+ * Smart resolver — accepts either a .mon name or a raw address.
74
+ * Useful for input fields where users can type either.
75
+ *
76
+ * @returns The resolved address, or null if invalid/not found
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const addr = await resolveInput('alice.mon') // resolves name
81
+ * const addr = await resolveInput('alice') // tries alice.mon
82
+ * const addr = await resolveInput('0xa05a...') // passes through
83
+ * ```
84
+ */
85
+ declare function resolveInput(input: string, config?: MNSClientConfig): Promise<string | null>;
86
+ /**
87
+ * Check if a .mon name is registered.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const taken = await isRegistered('alice.mon')
92
+ * ```
93
+ */
94
+ declare function isRegistered(name: string, config?: MNSClientConfig): Promise<boolean>;
95
+ /**
96
+ * Clear the internal resolution cache.
97
+ * Useful after a new registration.
98
+ */
99
+ declare function clearCache(): void;
100
+
101
+ declare const MNS_REGISTRY: "0x13f963486e741c8d3fcdc0a34a910920339a19ce";
102
+ declare const MNS_PUBLIC_RESOLVER: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
103
+
104
+ export { type MNSClientConfig, MNS_PUBLIC_RESOLVER, MNS_REGISTRY, clearCache, getDisplayName, getMNSClient, getTextRecord, isRegistered, lookupAddress, resolveInput, resolveName };