@monadns/sdk 1.0.0 → 2.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 +20 -17
- package/README.md +276 -35
- package/dist/index.cjs +225 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +265 -1
- package/dist/index.d.ts +265 -1
- package/dist/index.js +214 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +367 -19
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +440 -8
- package/dist/react.d.ts +440 -8
- package/dist/react.js +362 -18
- package/dist/react.js.map +1 -1
- package/package.json +10 -6
package/dist/react.d.cts
CHANGED
|
@@ -7,6 +7,426 @@ type MNSClientConfig = {
|
|
|
7
7
|
client?: PublicClient<Transport, Chain>;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
type RegistrationInfo = {
|
|
11
|
+
available: boolean;
|
|
12
|
+
price: bigint;
|
|
13
|
+
isFreebie: boolean;
|
|
14
|
+
hasClaimed: boolean;
|
|
15
|
+
duration: bigint;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to get registration info (price, availability, freebie status).
|
|
21
|
+
* Use this to build a registration UI before the user submits.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* function RegisterPage() {
|
|
26
|
+
* const [name, setName] = useState('')
|
|
27
|
+
* const { address } = useAccount()
|
|
28
|
+
* const { info, loading, error } = useRegistrationInfo(name, address)
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <div>
|
|
32
|
+
* <input value={name} onChange={(e) => setName(e.target.value)} />
|
|
33
|
+
* {info?.available && (
|
|
34
|
+
* <p>{info.isFreebie ? 'FREE!' : `${formatEther(info.price)} MON`}</p>
|
|
35
|
+
* )}
|
|
36
|
+
* </div>
|
|
37
|
+
* )
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function useRegistrationInfo(label: string | undefined, userAddress: string | undefined, durationYears?: number, config?: MNSClientConfig): {
|
|
42
|
+
info: RegistrationInfo | null;
|
|
43
|
+
loading: boolean;
|
|
44
|
+
error: string | null;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Hook to register a .mon name.
|
|
48
|
+
* Returns a prepare function that gives you tx params for wagmi's writeContract.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* const { prepare, loading, error } = useMNSRegister()
|
|
53
|
+
* const { writeContract, data: hash } = useWriteContract()
|
|
54
|
+
*
|
|
55
|
+
* const handleRegister = async () => {
|
|
56
|
+
* const tx = await prepare('alice', address)
|
|
57
|
+
* if (tx) writeContract(tx)
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function useMNSRegister(config?: MNSClientConfig): {
|
|
62
|
+
prepare: (label: string, ownerAddress: string, durationYears?: number) => Promise<{
|
|
63
|
+
address: "0x98866c55adbc73ec6c272bb3604ddbdee3f282a8";
|
|
64
|
+
abi: readonly [{
|
|
65
|
+
readonly name: "register";
|
|
66
|
+
readonly type: "function";
|
|
67
|
+
readonly inputs: readonly [{
|
|
68
|
+
readonly name: "label";
|
|
69
|
+
readonly type: "string";
|
|
70
|
+
}, {
|
|
71
|
+
readonly name: "owner";
|
|
72
|
+
readonly type: "address";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "duration";
|
|
75
|
+
readonly type: "uint256";
|
|
76
|
+
}];
|
|
77
|
+
readonly outputs: readonly [{
|
|
78
|
+
readonly name: "";
|
|
79
|
+
readonly type: "uint256";
|
|
80
|
+
}];
|
|
81
|
+
readonly stateMutability: "payable";
|
|
82
|
+
}];
|
|
83
|
+
functionName: "register";
|
|
84
|
+
args: readonly [string, `0x${string}`, bigint];
|
|
85
|
+
value: bigint;
|
|
86
|
+
gas: bigint;
|
|
87
|
+
_meta: {
|
|
88
|
+
label: string;
|
|
89
|
+
isFreebie: boolean;
|
|
90
|
+
price: bigint;
|
|
91
|
+
duration: bigint;
|
|
92
|
+
};
|
|
93
|
+
} | null>;
|
|
94
|
+
tx: {
|
|
95
|
+
address: "0x98866c55adbc73ec6c272bb3604ddbdee3f282a8";
|
|
96
|
+
abi: readonly [{
|
|
97
|
+
readonly name: "register";
|
|
98
|
+
readonly type: "function";
|
|
99
|
+
readonly inputs: readonly [{
|
|
100
|
+
readonly name: "label";
|
|
101
|
+
readonly type: "string";
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "owner";
|
|
104
|
+
readonly type: "address";
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "duration";
|
|
107
|
+
readonly type: "uint256";
|
|
108
|
+
}];
|
|
109
|
+
readonly outputs: readonly [{
|
|
110
|
+
readonly name: "";
|
|
111
|
+
readonly type: "uint256";
|
|
112
|
+
}];
|
|
113
|
+
readonly stateMutability: "payable";
|
|
114
|
+
}];
|
|
115
|
+
functionName: "register";
|
|
116
|
+
args: readonly [string, `0x${string}`, bigint];
|
|
117
|
+
value: bigint;
|
|
118
|
+
gas: bigint;
|
|
119
|
+
_meta: {
|
|
120
|
+
label: string;
|
|
121
|
+
isFreebie: boolean;
|
|
122
|
+
price: bigint;
|
|
123
|
+
duration: bigint;
|
|
124
|
+
};
|
|
125
|
+
} | null;
|
|
126
|
+
loading: boolean;
|
|
127
|
+
error: string | null;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Hook to set text records (avatar, url, twitter, etc.)
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* const { setAvatar, setTwitter } = useMNSTextRecords()
|
|
135
|
+
* const { writeContract } = useWriteContract()
|
|
136
|
+
*
|
|
137
|
+
* writeContract(setAvatar('alice.mon', 'https://example.com/pic.png'))
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare function useMNSTextRecords(): {
|
|
141
|
+
setTextRecord: (name: string, key: string, value: string) => {
|
|
142
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
143
|
+
abi: readonly [{
|
|
144
|
+
readonly name: "setText";
|
|
145
|
+
readonly type: "function";
|
|
146
|
+
readonly inputs: readonly [{
|
|
147
|
+
readonly name: "node";
|
|
148
|
+
readonly type: "bytes32";
|
|
149
|
+
}, {
|
|
150
|
+
readonly name: "key";
|
|
151
|
+
readonly type: "string";
|
|
152
|
+
}, {
|
|
153
|
+
readonly name: "value";
|
|
154
|
+
readonly type: "string";
|
|
155
|
+
}];
|
|
156
|
+
readonly outputs: readonly [];
|
|
157
|
+
readonly stateMutability: "nonpayable";
|
|
158
|
+
}, {
|
|
159
|
+
readonly name: "setAddr";
|
|
160
|
+
readonly type: "function";
|
|
161
|
+
readonly inputs: readonly [{
|
|
162
|
+
readonly name: "node";
|
|
163
|
+
readonly type: "bytes32";
|
|
164
|
+
}, {
|
|
165
|
+
readonly name: "a";
|
|
166
|
+
readonly type: "address";
|
|
167
|
+
}];
|
|
168
|
+
readonly outputs: readonly [];
|
|
169
|
+
readonly stateMutability: "nonpayable";
|
|
170
|
+
}];
|
|
171
|
+
functionName: "setText";
|
|
172
|
+
args: readonly [`0x${string}`, string, string];
|
|
173
|
+
};
|
|
174
|
+
setAvatar: (name: string, url: string) => {
|
|
175
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
176
|
+
abi: readonly [{
|
|
177
|
+
readonly name: "setText";
|
|
178
|
+
readonly type: "function";
|
|
179
|
+
readonly inputs: readonly [{
|
|
180
|
+
readonly name: "node";
|
|
181
|
+
readonly type: "bytes32";
|
|
182
|
+
}, {
|
|
183
|
+
readonly name: "key";
|
|
184
|
+
readonly type: "string";
|
|
185
|
+
}, {
|
|
186
|
+
readonly name: "value";
|
|
187
|
+
readonly type: "string";
|
|
188
|
+
}];
|
|
189
|
+
readonly outputs: readonly [];
|
|
190
|
+
readonly stateMutability: "nonpayable";
|
|
191
|
+
}, {
|
|
192
|
+
readonly name: "setAddr";
|
|
193
|
+
readonly type: "function";
|
|
194
|
+
readonly inputs: readonly [{
|
|
195
|
+
readonly name: "node";
|
|
196
|
+
readonly type: "bytes32";
|
|
197
|
+
}, {
|
|
198
|
+
readonly name: "a";
|
|
199
|
+
readonly type: "address";
|
|
200
|
+
}];
|
|
201
|
+
readonly outputs: readonly [];
|
|
202
|
+
readonly stateMutability: "nonpayable";
|
|
203
|
+
}];
|
|
204
|
+
functionName: "setText";
|
|
205
|
+
args: readonly [`0x${string}`, string, string];
|
|
206
|
+
};
|
|
207
|
+
setUrl: (name: string, url: string) => {
|
|
208
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
209
|
+
abi: readonly [{
|
|
210
|
+
readonly name: "setText";
|
|
211
|
+
readonly type: "function";
|
|
212
|
+
readonly inputs: readonly [{
|
|
213
|
+
readonly name: "node";
|
|
214
|
+
readonly type: "bytes32";
|
|
215
|
+
}, {
|
|
216
|
+
readonly name: "key";
|
|
217
|
+
readonly type: "string";
|
|
218
|
+
}, {
|
|
219
|
+
readonly name: "value";
|
|
220
|
+
readonly type: "string";
|
|
221
|
+
}];
|
|
222
|
+
readonly outputs: readonly [];
|
|
223
|
+
readonly stateMutability: "nonpayable";
|
|
224
|
+
}, {
|
|
225
|
+
readonly name: "setAddr";
|
|
226
|
+
readonly type: "function";
|
|
227
|
+
readonly inputs: readonly [{
|
|
228
|
+
readonly name: "node";
|
|
229
|
+
readonly type: "bytes32";
|
|
230
|
+
}, {
|
|
231
|
+
readonly name: "a";
|
|
232
|
+
readonly type: "address";
|
|
233
|
+
}];
|
|
234
|
+
readonly outputs: readonly [];
|
|
235
|
+
readonly stateMutability: "nonpayable";
|
|
236
|
+
}];
|
|
237
|
+
functionName: "setText";
|
|
238
|
+
args: readonly [`0x${string}`, string, string];
|
|
239
|
+
};
|
|
240
|
+
setTwitter: (name: string, handle: string) => {
|
|
241
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
242
|
+
abi: readonly [{
|
|
243
|
+
readonly name: "setText";
|
|
244
|
+
readonly type: "function";
|
|
245
|
+
readonly inputs: readonly [{
|
|
246
|
+
readonly name: "node";
|
|
247
|
+
readonly type: "bytes32";
|
|
248
|
+
}, {
|
|
249
|
+
readonly name: "key";
|
|
250
|
+
readonly type: "string";
|
|
251
|
+
}, {
|
|
252
|
+
readonly name: "value";
|
|
253
|
+
readonly type: "string";
|
|
254
|
+
}];
|
|
255
|
+
readonly outputs: readonly [];
|
|
256
|
+
readonly stateMutability: "nonpayable";
|
|
257
|
+
}, {
|
|
258
|
+
readonly name: "setAddr";
|
|
259
|
+
readonly type: "function";
|
|
260
|
+
readonly inputs: readonly [{
|
|
261
|
+
readonly name: "node";
|
|
262
|
+
readonly type: "bytes32";
|
|
263
|
+
}, {
|
|
264
|
+
readonly name: "a";
|
|
265
|
+
readonly type: "address";
|
|
266
|
+
}];
|
|
267
|
+
readonly outputs: readonly [];
|
|
268
|
+
readonly stateMutability: "nonpayable";
|
|
269
|
+
}];
|
|
270
|
+
functionName: "setText";
|
|
271
|
+
args: readonly [`0x${string}`, string, string];
|
|
272
|
+
};
|
|
273
|
+
setGithub: (name: string, handle: string) => {
|
|
274
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
275
|
+
abi: readonly [{
|
|
276
|
+
readonly name: "setText";
|
|
277
|
+
readonly type: "function";
|
|
278
|
+
readonly inputs: readonly [{
|
|
279
|
+
readonly name: "node";
|
|
280
|
+
readonly type: "bytes32";
|
|
281
|
+
}, {
|
|
282
|
+
readonly name: "key";
|
|
283
|
+
readonly type: "string";
|
|
284
|
+
}, {
|
|
285
|
+
readonly name: "value";
|
|
286
|
+
readonly type: "string";
|
|
287
|
+
}];
|
|
288
|
+
readonly outputs: readonly [];
|
|
289
|
+
readonly stateMutability: "nonpayable";
|
|
290
|
+
}, {
|
|
291
|
+
readonly name: "setAddr";
|
|
292
|
+
readonly type: "function";
|
|
293
|
+
readonly inputs: readonly [{
|
|
294
|
+
readonly name: "node";
|
|
295
|
+
readonly type: "bytes32";
|
|
296
|
+
}, {
|
|
297
|
+
readonly name: "a";
|
|
298
|
+
readonly type: "address";
|
|
299
|
+
}];
|
|
300
|
+
readonly outputs: readonly [];
|
|
301
|
+
readonly stateMutability: "nonpayable";
|
|
302
|
+
}];
|
|
303
|
+
functionName: "setText";
|
|
304
|
+
args: readonly [`0x${string}`, string, string];
|
|
305
|
+
};
|
|
306
|
+
setDiscord: (name: string, handle: string) => {
|
|
307
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
308
|
+
abi: readonly [{
|
|
309
|
+
readonly name: "setText";
|
|
310
|
+
readonly type: "function";
|
|
311
|
+
readonly inputs: readonly [{
|
|
312
|
+
readonly name: "node";
|
|
313
|
+
readonly type: "bytes32";
|
|
314
|
+
}, {
|
|
315
|
+
readonly name: "key";
|
|
316
|
+
readonly type: "string";
|
|
317
|
+
}, {
|
|
318
|
+
readonly name: "value";
|
|
319
|
+
readonly type: "string";
|
|
320
|
+
}];
|
|
321
|
+
readonly outputs: readonly [];
|
|
322
|
+
readonly stateMutability: "nonpayable";
|
|
323
|
+
}, {
|
|
324
|
+
readonly name: "setAddr";
|
|
325
|
+
readonly type: "function";
|
|
326
|
+
readonly inputs: readonly [{
|
|
327
|
+
readonly name: "node";
|
|
328
|
+
readonly type: "bytes32";
|
|
329
|
+
}, {
|
|
330
|
+
readonly name: "a";
|
|
331
|
+
readonly type: "address";
|
|
332
|
+
}];
|
|
333
|
+
readonly outputs: readonly [];
|
|
334
|
+
readonly stateMutability: "nonpayable";
|
|
335
|
+
}];
|
|
336
|
+
functionName: "setText";
|
|
337
|
+
args: readonly [`0x${string}`, string, string];
|
|
338
|
+
};
|
|
339
|
+
setDescription: (name: string, desc: string) => {
|
|
340
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
341
|
+
abi: readonly [{
|
|
342
|
+
readonly name: "setText";
|
|
343
|
+
readonly type: "function";
|
|
344
|
+
readonly inputs: readonly [{
|
|
345
|
+
readonly name: "node";
|
|
346
|
+
readonly type: "bytes32";
|
|
347
|
+
}, {
|
|
348
|
+
readonly name: "key";
|
|
349
|
+
readonly type: "string";
|
|
350
|
+
}, {
|
|
351
|
+
readonly name: "value";
|
|
352
|
+
readonly type: "string";
|
|
353
|
+
}];
|
|
354
|
+
readonly outputs: readonly [];
|
|
355
|
+
readonly stateMutability: "nonpayable";
|
|
356
|
+
}, {
|
|
357
|
+
readonly name: "setAddr";
|
|
358
|
+
readonly type: "function";
|
|
359
|
+
readonly inputs: readonly [{
|
|
360
|
+
readonly name: "node";
|
|
361
|
+
readonly type: "bytes32";
|
|
362
|
+
}, {
|
|
363
|
+
readonly name: "a";
|
|
364
|
+
readonly type: "address";
|
|
365
|
+
}];
|
|
366
|
+
readonly outputs: readonly [];
|
|
367
|
+
readonly stateMutability: "nonpayable";
|
|
368
|
+
}];
|
|
369
|
+
functionName: "setText";
|
|
370
|
+
args: readonly [`0x${string}`, string, string];
|
|
371
|
+
};
|
|
372
|
+
textRecordKeys: {
|
|
373
|
+
readonly avatar: "avatar";
|
|
374
|
+
readonly url: "url";
|
|
375
|
+
readonly description: "description";
|
|
376
|
+
readonly email: "email";
|
|
377
|
+
readonly twitter: "com.twitter";
|
|
378
|
+
readonly github: "com.github";
|
|
379
|
+
readonly discord: "com.discord";
|
|
380
|
+
readonly telegram: "org.telegram";
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Hook to update the address a name points to.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```tsx
|
|
388
|
+
* const { setAddr } = useMNSAddr()
|
|
389
|
+
* const { writeContract } = useWriteContract()
|
|
390
|
+
*
|
|
391
|
+
* writeContract(setAddr('alice.mon', '0xnewaddress...'))
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function useMNSAddr(): {
|
|
395
|
+
setAddr: (name: string, addr: string) => {
|
|
396
|
+
address: "0xa2eb94c88e55d944aced2066c5cec9b759801f97";
|
|
397
|
+
abi: readonly [{
|
|
398
|
+
readonly name: "setText";
|
|
399
|
+
readonly type: "function";
|
|
400
|
+
readonly inputs: readonly [{
|
|
401
|
+
readonly name: "node";
|
|
402
|
+
readonly type: "bytes32";
|
|
403
|
+
}, {
|
|
404
|
+
readonly name: "key";
|
|
405
|
+
readonly type: "string";
|
|
406
|
+
}, {
|
|
407
|
+
readonly name: "value";
|
|
408
|
+
readonly type: "string";
|
|
409
|
+
}];
|
|
410
|
+
readonly outputs: readonly [];
|
|
411
|
+
readonly stateMutability: "nonpayable";
|
|
412
|
+
}, {
|
|
413
|
+
readonly name: "setAddr";
|
|
414
|
+
readonly type: "function";
|
|
415
|
+
readonly inputs: readonly [{
|
|
416
|
+
readonly name: "node";
|
|
417
|
+
readonly type: "bytes32";
|
|
418
|
+
}, {
|
|
419
|
+
readonly name: "a";
|
|
420
|
+
readonly type: "address";
|
|
421
|
+
}];
|
|
422
|
+
readonly outputs: readonly [];
|
|
423
|
+
readonly stateMutability: "nonpayable";
|
|
424
|
+
}];
|
|
425
|
+
functionName: "setAddr";
|
|
426
|
+
args: readonly [`0x${string}`, `0x${string}`];
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
|
|
10
430
|
/**
|
|
11
431
|
* Reverse resolution hook: address → .mon name
|
|
12
432
|
*
|
|
@@ -67,16 +487,11 @@ declare function useMNSDisplay(address: string | undefined, config?: MNSClientCo
|
|
|
67
487
|
* ```tsx
|
|
68
488
|
* function SendForm() {
|
|
69
489
|
* const { resolve, address, name, loading, error } = useMNSResolve()
|
|
70
|
-
*
|
|
71
490
|
* return (
|
|
72
491
|
* <div>
|
|
73
|
-
* <input
|
|
74
|
-
* placeholder="Address or .mon name"
|
|
75
|
-
* onChange={(e) => resolve(e.target.value)}
|
|
76
|
-
* />
|
|
492
|
+
* <input placeholder="Address or .mon name" onChange={(e) => resolve(e.target.value)} />
|
|
77
493
|
* {loading && <span>Resolving...</span>}
|
|
78
|
-
* {
|
|
79
|
-
* {address && <span className="text-green-500">→ {address}</span>}
|
|
494
|
+
* {address && <span>→ {address}</span>}
|
|
80
495
|
* </div>
|
|
81
496
|
* )
|
|
82
497
|
* }
|
|
@@ -105,5 +520,22 @@ declare function useMNSText(name: string | undefined, key: string, config?: MNSC
|
|
|
105
520
|
loading: boolean;
|
|
106
521
|
error: string | null;
|
|
107
522
|
};
|
|
523
|
+
/**
|
|
524
|
+
* Avatar URL hook: resolves avatar from text record, handling IPFS and NFT formats
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```tsx
|
|
528
|
+
* function Avatar({ name }: { name: string }) {
|
|
529
|
+
* const { url, loading } = useMNSAvatar(name)
|
|
530
|
+
* if (loading) return <div className="animate-pulse w-10 h-10 rounded-full bg-gray-700" />
|
|
531
|
+
* return url ? <img src={url} className="w-10 h-10 rounded-full" /> : null
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
declare function useMNSAvatar(name: string | undefined, config?: MNSClientConfig): {
|
|
536
|
+
url: string | null;
|
|
537
|
+
loading: boolean;
|
|
538
|
+
error: string | null;
|
|
539
|
+
};
|
|
108
540
|
|
|
109
|
-
export { type MNSClientConfig, useMNSAddress, useMNSDisplay, useMNSName, useMNSResolve, useMNSText };
|
|
541
|
+
export { type MNSClientConfig, useMNSAddr, useMNSAddress, useMNSAvatar, useMNSDisplay, useMNSName, useMNSRegister, useMNSResolve, useMNSText, useMNSTextRecords, useRegistrationInfo };
|