@monadns/sdk 1.0.0 → 2.1.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 CHANGED
@@ -1,21 +1,24 @@
1
- MIT License
1
+ This is free and unencumbered software released into the public domain.
2
2
 
3
- Copyright (c) 2026 Monad Name Service
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
4
7
 
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:
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
11
15
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
14
23
 
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.
24
+ For more information, please refer to <https://unlicense.org>
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @monadns/sdk
2
2
 
3
- Resolve **.mon** names on the Monad network. The official SDK for the Monad Name Service.
3
+ Resolve and register **.mon** names on the Monad network. The official SDK for the [Monad Name Service](https://monadscan.com).
4
4
 
5
5
  ## Install
6
6
 
@@ -15,31 +15,45 @@ import { resolveName, lookupAddress } from '@monadns/sdk';
15
15
 
16
16
  // Forward: name → address
17
17
  const address = await resolveName('alice.mon');
18
- // '0xa0123BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'
18
+ // '0xa05a8BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47'
19
19
 
20
20
  // Reverse: address → name
21
- const name = await lookupAddress('0xa0123BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47');
21
+ const name = await lookupAddress('0xa05a8BF1eda5bbC2b3aCAF03D04f77bD7d66Cc47');
22
22
  // 'alice.mon'
23
23
  ```
24
24
 
25
25
  ## React Hooks
26
26
 
27
+ All hooks are compatible with Next.js App Router, Remix, and any React 17+ framework. The `'use client'` directive is included in the build.
28
+
27
29
  ```bash
28
30
  npm install @monadns/sdk viem react
29
31
  ```
30
32
 
33
+ ### Display .mon names
34
+
31
35
  ```tsx
32
- import { useMNSDisplay, useMNSResolve } from '@monadns/sdk/react';
36
+ import { useMNSDisplay } from '@monadns/sdk/react';
33
37
 
34
- // Display .mon name instead of address
35
38
  function UserBadge({ address }: { address: string }) {
36
- const { displayName, monName } = useMNSDisplay(address);
37
- return <span className={monName ? 'font-bold' : ''}>{displayName}</span>;
39
+ const { displayName, monName, loading } = useMNSDisplay(address);
40
+
41
+ return (
42
+ <span className={monName ? 'text-purple-400 font-bold' : 'text-gray-400'}>
43
+ {loading ? '...' : displayName}
44
+ </span>
45
+ );
38
46
  }
47
+ ```
48
+
49
+ ### Resolve input (name or address)
50
+
51
+ ```tsx
52
+ import { useMNSResolve } from '@monadns/sdk/react';
39
53
 
40
- // Input field that accepts names or addresses
41
54
  function RecipientInput() {
42
- const { resolve, address, loading, error } = useMNSResolve();
55
+ const { resolve, address, name, loading, error } = useMNSResolve();
56
+
43
57
  return (
44
58
  <div>
45
59
  <input
@@ -47,36 +61,324 @@ function RecipientInput() {
47
61
  onChange={(e) => resolve(e.target.value)}
48
62
  />
49
63
  {loading && <span>Resolving...</span>}
50
- {address && <span>→ {address}</span>}
51
- {error && <span>{error}</span>}
64
+ {error && <span className="text-red-500">{error}</span>}
65
+ {address && <span className="text-green-500">→ {address}</span>}
66
+ </div>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### Get avatar
72
+
73
+ ```tsx
74
+ import { useMNSAvatar } from '@monadns/sdk/react';
75
+
76
+ function Avatar({ name }: { name: string }) {
77
+ const { url, loading } = useMNSAvatar(name);
78
+ if (loading)
79
+ return <div className="animate-pulse w-10 h-10 rounded-full bg-gray-700" />;
80
+ return url ? <img src={url} className="w-10 h-10 rounded-full" /> : null;
81
+ }
82
+ ```
83
+
84
+ ### Get text records
85
+
86
+ ```tsx
87
+ import { useMNSText } from '@monadns/sdk/react';
88
+
89
+ function Twitter({ name }: { name: string }) {
90
+ const { value: handle } = useMNSText(name, 'com.twitter');
91
+ return handle ? <a href={`https://x.com/${handle}`}>@{handle}</a> : null;
92
+ }
93
+ ```
94
+
95
+ ### Check ownership and expiry
96
+
97
+ ```tsx
98
+ import { useMNSOwner, useMNSExpiry } from '@monadns/sdk/react';
99
+
100
+ function NameInfo({ name }: { name: string }) {
101
+ const { owner, loading: ownerLoading } = useMNSOwner(name);
102
+ const {
103
+ daysUntilExpiry,
104
+ isExpired,
105
+ loading: expiryLoading,
106
+ } = useMNSExpiry(name);
107
+
108
+ if (ownerLoading || expiryLoading) return <div>Loading...</div>;
109
+
110
+ return (
111
+ <div>
112
+ <p>Owner: {owner}</p>
113
+ {isExpired ? (
114
+ <p className="text-red-500">This name has expired!</p>
115
+ ) : (
116
+ <p>Expires in {daysUntilExpiry} days</p>
117
+ )}
52
118
  </div>
53
119
  );
54
120
  }
55
121
  ```
56
122
 
123
+ ## Registration (with wagmi)
124
+
125
+ The SDK returns transaction parameters that work directly with wagmi's `useWriteContract`:
126
+
127
+ ```bash
128
+ npm install @monadns/sdk viem wagmi @tanstack/react-query
129
+ ```
130
+
131
+ ### Full Registration Page
132
+
133
+ ```tsx
134
+ import { useState } from 'react';
135
+ import {
136
+ useAccount,
137
+ useWriteContract,
138
+ useWaitForTransactionReceipt,
139
+ } from 'wagmi';
140
+ import { formatEther } from 'viem';
141
+ import { useRegistrationInfo, useMNSRegister } from '@monadns/sdk/react';
142
+ import { clearCache } from '@monadns/sdk';
143
+
144
+ function RegisterPage() {
145
+ const [label, setLabel] = useState('');
146
+ const { address } = useAccount();
147
+ const { info, loading: checking } = useRegistrationInfo(label, address);
148
+ const { prepare, loading: preparing, error } = useMNSRegister();
149
+ const { writeContract, data: hash } = useWriteContract();
150
+ const { isLoading: confirming, isSuccess } = useWaitForTransactionReceipt({
151
+ hash,
152
+ });
153
+
154
+ const handleRegister = async () => {
155
+ const tx = await prepare(label, address!);
156
+ if (tx) writeContract(tx);
157
+ };
158
+
159
+ // Clear cache after successful registration so lookups reflect new state
160
+ if (isSuccess) clearCache();
161
+
162
+ return (
163
+ <div className="max-w-md mx-auto p-6">
164
+ <h1 className="text-2xl font-bold mb-4">Register a .mon name</h1>
165
+
166
+ <input
167
+ className="w-full p-3 border rounded-lg mb-4"
168
+ placeholder="Search for a name..."
169
+ value={label}
170
+ onChange={(e) => setLabel(e.target.value)}
171
+ />
172
+
173
+ {checking && <p className="text-gray-400">Checking availability...</p>}
174
+
175
+ {info && !checking && (
176
+ <div className="space-y-2">
177
+ <p>{info.available ? '✅ Available!' : '❌ Already taken'}</p>
178
+
179
+ {info.available && (
180
+ <>
181
+ <p className="text-lg">
182
+ {info.isFreebie
183
+ ? '🎉 FREE for 100 years!'
184
+ : `${formatEther(info.price)} MON / year`}
185
+ </p>
186
+
187
+ <button
188
+ className="w-full bg-purple-600 text-white p-3 rounded-lg disabled:opacity-50"
189
+ onClick={handleRegister}
190
+ disabled={preparing || confirming}
191
+ >
192
+ {confirming
193
+ ? 'Confirming...'
194
+ : preparing
195
+ ? 'Preparing...'
196
+ : `Register ${label}.mon`}
197
+ </button>
198
+ </>
199
+ )}
200
+ </div>
201
+ )}
202
+
203
+ {error && <p className="text-red-500 mt-2">❌ {error}</p>}
204
+ {isSuccess && (
205
+ <p className="text-green-500 mt-4">🎉 {label}.mon is yours!</p>
206
+ )}
207
+ </div>
208
+ );
209
+ }
210
+ ```
211
+
212
+ ### Profile Editor (Avatar, Twitter, Bio)
213
+
214
+ ```tsx
215
+ import { useState } from 'react';
216
+ import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
217
+ import { useMNSText, useMNSTextRecords } from '@monadns/sdk/react';
218
+
219
+ function ProfileEditor({ name }: { name: string }) {
220
+ const { value: currentAvatar } = useMNSText(name, 'avatar');
221
+ const { value: currentTwitter } = useMNSText(name, 'com.twitter');
222
+ const { value: currentBio } = useMNSText(name, 'description');
223
+
224
+ const { setAvatar, setTwitter, setDescription } = useMNSTextRecords();
225
+ const { writeContract, data: hash } = useWriteContract();
226
+ const { isLoading: saving, isSuccess } = useWaitForTransactionReceipt({
227
+ hash,
228
+ });
229
+
230
+ const [avatar, setAvatarUrl] = useState('');
231
+ const [twitter, setTwitterHandle] = useState('');
232
+ const [bio, setBio] = useState('');
233
+
234
+ return (
235
+ <div className="max-w-md mx-auto p-6 space-y-4">
236
+ <h2 className="text-xl font-bold">Edit {name} Profile</h2>
237
+
238
+ {currentAvatar && (
239
+ <img src={currentAvatar} className="w-20 h-20 rounded-full" />
240
+ )}
241
+
242
+ <div>
243
+ <label className="block text-sm font-medium mb-1">Avatar URL</label>
244
+ <div className="flex gap-2">
245
+ <input
246
+ className="flex-1 p-2 border rounded"
247
+ placeholder={currentAvatar || 'https://example.com/avatar.png'}
248
+ value={avatar}
249
+ onChange={(e) => setAvatarUrl(e.target.value)}
250
+ />
251
+ <button
252
+ className="px-4 py-2 bg-purple-600 text-white rounded disabled:opacity-50"
253
+ onClick={() => writeContract(setAvatar(name, avatar))}
254
+ disabled={saving || !avatar}
255
+ >
256
+ Save
257
+ </button>
258
+ </div>
259
+ </div>
260
+
261
+ <div>
262
+ <label className="block text-sm font-medium mb-1">Twitter</label>
263
+ <div className="flex gap-2">
264
+ <input
265
+ className="flex-1 p-2 border rounded"
266
+ placeholder={currentTwitter || '@handle'}
267
+ value={twitter}
268
+ onChange={(e) => setTwitterHandle(e.target.value)}
269
+ />
270
+ <button
271
+ className="px-4 py-2 bg-purple-600 text-white rounded disabled:opacity-50"
272
+ onClick={() => writeContract(setTwitter(name, twitter))}
273
+ disabled={saving || !twitter}
274
+ >
275
+ Save
276
+ </button>
277
+ </div>
278
+ </div>
279
+
280
+ <div>
281
+ <label className="block text-sm font-medium mb-1">Bio</label>
282
+ <div className="flex gap-2">
283
+ <input
284
+ className="flex-1 p-2 border rounded"
285
+ placeholder={currentBio || 'Tell the world about yourself'}
286
+ value={bio}
287
+ onChange={(e) => setBio(e.target.value)}
288
+ />
289
+ <button
290
+ className="px-4 py-2 bg-purple-600 text-white rounded disabled:opacity-50"
291
+ onClick={() => writeContract(setDescription(name, bio))}
292
+ disabled={saving || !bio}
293
+ >
294
+ Save
295
+ </button>
296
+ </div>
297
+ </div>
298
+
299
+ {saving && <p className="text-gray-400">⏳ Saving to blockchain...</p>}
300
+ {isSuccess && <p className="text-green-500">✅ Profile updated!</p>}
301
+ </div>
302
+ );
303
+ }
304
+ ```
305
+
306
+ ## Advanced Usage
307
+
308
+ ### Check Name Ownership & Expiry
309
+
310
+ ```typescript
311
+ import { getOwner, getExpiry, getResolver } from '@monadns/sdk';
312
+
313
+ // Check who owns a name
314
+ const owner = await getOwner('alice.mon');
315
+ console.log('Owner:', owner);
316
+
317
+ // Check when it expires
318
+ const expiry = await getExpiry('alice.mon');
319
+ const expiryDate = new Date(expiry * 1000);
320
+ const daysLeft = Math.floor(
321
+ (expiry * 1000 - Date.now()) / (1000 * 60 * 60 * 24),
322
+ );
323
+ console.log(`Expires: ${expiryDate.toLocaleDateString()} (${daysLeft} days)`);
324
+
325
+ // Get resolver contract
326
+ const resolver = await getResolver('alice.mon');
327
+ console.log('Resolver:', resolver);
328
+ ```
329
+
330
+ ### Check Availability Before Registration
331
+
332
+ ```typescript
333
+ import { getAvailable } from '@monadns/sdk';
334
+
335
+ const available = await getAvailable('alice.mon');
336
+ if (available) {
337
+ console.log('alice.mon is available for registration!');
338
+ } else {
339
+ console.log('alice.mon is already taken');
340
+ }
341
+ ```
342
+
57
343
  ## API Reference
58
344
 
59
- ### Core Functions
345
+ ### Core Functions (`@monadns/sdk`)
60
346
 
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 |
347
+ | Function | Description |
348
+ | ------------------------------------- | --------------------------------------------- |
349
+ | `resolveName(name)` | Forward resolve: `alice.mon` → `0x...` |
350
+ | `lookupAddress(address)` | Reverse resolve: `0x...` → `alice.mon` |
351
+ | `getDisplayName(address)` | Returns `.mon` name or truncated address |
352
+ | `resolveInput(input)` | Accepts name or address, returns address |
353
+ | `getTextRecord(name, key)` | Get text record (avatar, url, etc.) |
354
+ | `getAvatarUrl(name)` | Get resolved avatar URL (handles IPFS, NFTs) |
355
+ | `getAvailable(name)` | Check if a name is available for registration |
356
+ | `getOwner(name)` | Get the owner address of a name |
357
+ | `getResolver(name)` | Get the resolver contract address |
358
+ | `getExpiry(name)` | Get expiry timestamp (Unix seconds) |
359
+ | `clearCache()` | Clear the resolution cache |
360
+ | `getRegistrationInfo(label, address)` | Get price, availability, freebie status |
361
+ | `getRegisterTx(label, address)` | Get tx params for registration |
362
+ | `getSetTextTx(name, key, value)` | Get tx params for setting a text record |
363
+ | `getSetAddrTx(name, address)` | Get tx params for updating the address record |
70
364
 
71
- ### React Hooks
365
+ ### React Hooks (`@monadns/sdk/react`)
72
366
 
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 }` |
367
+ | Hook | Returns | Description |
368
+ | ------------------------------------- | -------------------------------------------------------------------- | ----------------------------- |
369
+ | `useMNSName(address)` | `{ name, loading, error }` | Reverse resolution |
370
+ | `useMNSAddress(name)` | `{ address, loading, error }` | Forward resolution |
371
+ | `useMNSDisplay(address)` | `{ displayName, monName, loading }` | Display-ready name |
372
+ | `useMNSResolve()` | `{ resolve, address, name, loading, error }` | On-demand resolver for inputs |
373
+ | `useMNSText(name, key)` | `{ value, loading, error }` | Read text records |
374
+ | `useMNSAvatar(name)` | `{ url, loading, error }` | Resolved avatar URL |
375
+ | `useMNSOwner(name)` | `{ owner, loading, error }` | Get name owner |
376
+ | `useMNSResolver(name)` | `{ resolver, loading, error }` | Get resolver address |
377
+ | `useMNSExpiry(name)` | `{ expiry, expiryDate, daysUntilExpiry, isExpired, loading, error }` | Get expiration info |
378
+ | `useRegistrationInfo(label, address)` | `{ info, loading, error }` | Pre-registration data |
379
+ | `useMNSRegister()` | `{ prepare, tx, loading, error }` | Prepare registration tx |
380
+ | `useMNSTextRecords()` | `{ setAvatar, setTwitter, ... }` | Prepare text record txs |
381
+ | `useMNSAddr()` | `{ setAddr }` | Prepare address update tx |
80
382
 
81
383
  ### Custom RPC
82
384
 
@@ -100,13 +402,59 @@ const name = await lookupAddress('0x...', { client });
100
402
 
101
403
  ## Contracts
102
404
 
103
- | Contract | Address |
104
- | --------------- | -------------------------------------------- |
105
- | Registry | `0x13f963486e741c8d3fcdc0a34a910920339a19ce` |
106
- | Public Resolver | `0xa2eb94c88e55d944aced2066c5cec9b759801f97` |
405
+ | Contract | Address |
406
+ | ----------------- | -------------------------------------------- |
407
+ | Registry | `0x13f963486e741c8d3fcdc0a34a910920339a19ce` |
408
+ | Public Resolver | `0xa2eb94c88e55d944aced2066c5cec9b759801f97` |
409
+ | Controller | `0x98866c55adbc73ec6c272bb3604ddbdee3f282a8` |
410
+ | Base Registrar | `0x104a49db9318c284d462841b6940bdb46624ca55` |
411
+ | Reverse Registrar | `0x6fff58419ad964f2357590c3f1bae576ebe45f52` |
412
+
413
+ **Chain:** Monad Mainnet (Chain ID 143)
414
+
415
+ ## Migrating from v2.0 to v2.1
416
+
417
+ ### Breaking Changes
418
+
419
+ **`isRegistered()` has been renamed to `getAvailable()` with inverted logic**
420
+
421
+ **Before (v2.0):**
422
+
423
+ ```typescript
424
+ const registered = await isRegistered('alice.mon');
425
+ if (registered) {
426
+ console.log('Name is taken');
427
+ }
428
+ ```
429
+
430
+ **After (v2.1):**
431
+
432
+ ```typescript
433
+ const available = await getAvailable('alice.mon');
434
+ if (available) {
435
+ console.log('Name is available for registration');
436
+ } else {
437
+ console.log('Name is taken');
438
+ }
439
+ ```
440
+
441
+ ### New Features
442
+
443
+ - `getOwner(name)` - Get the owner of a name
444
+ - `getResolver(name)` - Get the resolver contract
445
+ - `getExpiry(name)` - Get expiration timestamp
446
+ - `useMNSOwner(name)` - React hook for ownership info
447
+ - `useMNSResolver(name)` - React hook for resolver info
448
+ - `useMNSExpiry(name)` - React hook for expiry info with computed fields
449
+ - `MNS_BASE_REGISTRAR` constant now exported
450
+
451
+ ## Compatibility
107
452
 
108
- Chain: Monad Mainnet (Chain ID 143)
453
+ - **Frameworks:** React 17+, Next.js (App Router & Pages), Remix, Vite, CRA
454
+ - **Wallet libraries:** wagmi, RainbowKit, ConnectKit, Privy, or any viem-based client
455
+ - **Non-React:** All core functions work without React in any JS/TS environment
456
+ - **Server-side:** Core functions can run in Node.js, edge functions, or API routes
109
457
 
110
458
  ## License
111
459
 
112
- MIT
460
+ [Unlicense](https://unlicense.org) – public domain, no attribution required.