@gitmyabi/zxc 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.
@@ -0,0 +1,750 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Zxc_json = exports.Zxc_jsonAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * Zxc_json ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.Zxc_jsonAbi = [
11
+ {
12
+ "constant": true,
13
+ "inputs": [],
14
+ "name": "name",
15
+ "outputs": [
16
+ {
17
+ "name": "_name",
18
+ "type": "string"
19
+ }
20
+ ],
21
+ "payable": false,
22
+ "stateMutability": "view",
23
+ "type": "function"
24
+ },
25
+ {
26
+ "constant": false,
27
+ "inputs": [
28
+ {
29
+ "name": "_spender",
30
+ "type": "address"
31
+ },
32
+ {
33
+ "name": "_value",
34
+ "type": "uint256"
35
+ }
36
+ ],
37
+ "name": "approve",
38
+ "outputs": [
39
+ {
40
+ "name": "_success",
41
+ "type": "bool"
42
+ }
43
+ ],
44
+ "payable": false,
45
+ "stateMutability": "nonpayable",
46
+ "type": "function"
47
+ },
48
+ {
49
+ "constant": true,
50
+ "inputs": [],
51
+ "name": "totalSupply",
52
+ "outputs": [
53
+ {
54
+ "name": "_totalSupply",
55
+ "type": "uint256"
56
+ }
57
+ ],
58
+ "payable": false,
59
+ "stateMutability": "view",
60
+ "type": "function"
61
+ },
62
+ {
63
+ "constant": false,
64
+ "inputs": [
65
+ {
66
+ "name": "crowdsaleAddr",
67
+ "type": "address"
68
+ }
69
+ ],
70
+ "name": "setCrowdsaleAddress",
71
+ "outputs": [],
72
+ "payable": false,
73
+ "stateMutability": "nonpayable",
74
+ "type": "function"
75
+ },
76
+ {
77
+ "constant": false,
78
+ "inputs": [
79
+ {
80
+ "name": "_from",
81
+ "type": "address"
82
+ },
83
+ {
84
+ "name": "_to",
85
+ "type": "address"
86
+ },
87
+ {
88
+ "name": "_value",
89
+ "type": "uint256"
90
+ }
91
+ ],
92
+ "name": "transferFrom",
93
+ "outputs": [
94
+ {
95
+ "name": "_success",
96
+ "type": "bool"
97
+ }
98
+ ],
99
+ "payable": false,
100
+ "stateMutability": "nonpayable",
101
+ "type": "function"
102
+ },
103
+ {
104
+ "constant": true,
105
+ "inputs": [],
106
+ "name": "decimals",
107
+ "outputs": [
108
+ {
109
+ "name": "_decimals",
110
+ "type": "uint8"
111
+ }
112
+ ],
113
+ "payable": false,
114
+ "stateMutability": "view",
115
+ "type": "function"
116
+ },
117
+ {
118
+ "constant": true,
119
+ "inputs": [],
120
+ "name": "crowdsaleAddress",
121
+ "outputs": [
122
+ {
123
+ "name": "",
124
+ "type": "address"
125
+ }
126
+ ],
127
+ "payable": false,
128
+ "stateMutability": "view",
129
+ "type": "function"
130
+ },
131
+ {
132
+ "constant": false,
133
+ "inputs": [
134
+ {
135
+ "name": "_value",
136
+ "type": "uint256"
137
+ }
138
+ ],
139
+ "name": "burn",
140
+ "outputs": [],
141
+ "payable": false,
142
+ "stateMutability": "nonpayable",
143
+ "type": "function"
144
+ },
145
+ {
146
+ "constant": false,
147
+ "inputs": [],
148
+ "name": "claimOwnership",
149
+ "outputs": [],
150
+ "payable": false,
151
+ "stateMutability": "nonpayable",
152
+ "type": "function"
153
+ },
154
+ {
155
+ "constant": true,
156
+ "inputs": [
157
+ {
158
+ "name": "_owner",
159
+ "type": "address"
160
+ }
161
+ ],
162
+ "name": "balanceOf",
163
+ "outputs": [
164
+ {
165
+ "name": "_balance",
166
+ "type": "uint256"
167
+ }
168
+ ],
169
+ "payable": false,
170
+ "stateMutability": "view",
171
+ "type": "function"
172
+ },
173
+ {
174
+ "constant": true,
175
+ "inputs": [],
176
+ "name": "owner",
177
+ "outputs": [
178
+ {
179
+ "name": "",
180
+ "type": "address"
181
+ }
182
+ ],
183
+ "payable": false,
184
+ "stateMutability": "view",
185
+ "type": "function"
186
+ },
187
+ {
188
+ "constant": true,
189
+ "inputs": [],
190
+ "name": "symbol",
191
+ "outputs": [
192
+ {
193
+ "name": "_symbol",
194
+ "type": "string"
195
+ }
196
+ ],
197
+ "payable": false,
198
+ "stateMutability": "view",
199
+ "type": "function"
200
+ },
201
+ {
202
+ "constant": false,
203
+ "inputs": [
204
+ {
205
+ "name": "_to",
206
+ "type": "address"
207
+ },
208
+ {
209
+ "name": "_value",
210
+ "type": "uint256"
211
+ }
212
+ ],
213
+ "name": "transfer",
214
+ "outputs": [
215
+ {
216
+ "name": "_success",
217
+ "type": "bool"
218
+ }
219
+ ],
220
+ "payable": false,
221
+ "stateMutability": "nonpayable",
222
+ "type": "function"
223
+ },
224
+ {
225
+ "constant": true,
226
+ "inputs": [
227
+ {
228
+ "name": "_owner",
229
+ "type": "address"
230
+ },
231
+ {
232
+ "name": "_spender",
233
+ "type": "address"
234
+ }
235
+ ],
236
+ "name": "allowance",
237
+ "outputs": [
238
+ {
239
+ "name": "_remaining",
240
+ "type": "uint256"
241
+ }
242
+ ],
243
+ "payable": false,
244
+ "stateMutability": "view",
245
+ "type": "function"
246
+ },
247
+ {
248
+ "constant": true,
249
+ "inputs": [],
250
+ "name": "pendingOwner",
251
+ "outputs": [
252
+ {
253
+ "name": "",
254
+ "type": "address"
255
+ }
256
+ ],
257
+ "payable": false,
258
+ "stateMutability": "view",
259
+ "type": "function"
260
+ },
261
+ {
262
+ "constant": false,
263
+ "inputs": [],
264
+ "name": "enableTransfer",
265
+ "outputs": [],
266
+ "payable": false,
267
+ "stateMutability": "nonpayable",
268
+ "type": "function"
269
+ },
270
+ {
271
+ "constant": false,
272
+ "inputs": [
273
+ {
274
+ "name": "_newOwner",
275
+ "type": "address"
276
+ }
277
+ ],
278
+ "name": "transferOwnership",
279
+ "outputs": [],
280
+ "payable": false,
281
+ "stateMutability": "nonpayable",
282
+ "type": "function"
283
+ },
284
+ {
285
+ "inputs": [],
286
+ "payable": false,
287
+ "stateMutability": "nonpayable",
288
+ "type": "constructor"
289
+ },
290
+ {
291
+ "anonymous": false,
292
+ "inputs": [
293
+ {
294
+ "indexed": true,
295
+ "name": "_burner",
296
+ "type": "address"
297
+ },
298
+ {
299
+ "indexed": false,
300
+ "name": "_value",
301
+ "type": "uint256"
302
+ }
303
+ ],
304
+ "name": "Burn",
305
+ "type": "event"
306
+ },
307
+ {
308
+ "anonymous": false,
309
+ "inputs": [
310
+ {
311
+ "indexed": true,
312
+ "name": "previousOwner",
313
+ "type": "address"
314
+ },
315
+ {
316
+ "indexed": true,
317
+ "name": "newOwner",
318
+ "type": "address"
319
+ }
320
+ ],
321
+ "name": "OwnershipTransferred",
322
+ "type": "event"
323
+ },
324
+ {
325
+ "anonymous": false,
326
+ "inputs": [
327
+ {
328
+ "indexed": true,
329
+ "name": "_from",
330
+ "type": "address"
331
+ },
332
+ {
333
+ "indexed": true,
334
+ "name": "_to",
335
+ "type": "address"
336
+ },
337
+ {
338
+ "indexed": false,
339
+ "name": "_value",
340
+ "type": "uint256"
341
+ }
342
+ ],
343
+ "name": "Transfer",
344
+ "type": "event"
345
+ },
346
+ {
347
+ "anonymous": false,
348
+ "inputs": [
349
+ {
350
+ "indexed": true,
351
+ "name": "_owner",
352
+ "type": "address"
353
+ },
354
+ {
355
+ "indexed": true,
356
+ "name": "_spender",
357
+ "type": "address"
358
+ },
359
+ {
360
+ "indexed": false,
361
+ "name": "_value",
362
+ "type": "uint256"
363
+ }
364
+ ],
365
+ "name": "Approval",
366
+ "type": "event"
367
+ }
368
+ ];
369
+ /**
370
+ * Zxc_json Contract Class
371
+ *
372
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * import { createPublicClient, createWalletClient, http } from 'viem';
377
+ * import { mainnet } from 'viem/chains';
378
+ * import { Zxc_json } from 'Zxc_json';
379
+ *
380
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
381
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
382
+ *
383
+ * const contract = new Zxc_json('0x...', { publicClient, walletClient });
384
+ *
385
+ * // Read functions
386
+ * const result = await contract.balanceOf('0x...');
387
+ *
388
+ * // Write functions
389
+ * const hash = await contract.transfer('0x...', 1000n);
390
+ *
391
+ * // Simulate transactions (dry-run)
392
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
393
+ * console.log('Gas estimate:', simulation.request.gas);
394
+ *
395
+ * // Watch events
396
+ * const unwatch = contract.watch.Transfer((event) => {
397
+ * console.log('Transfer event:', event);
398
+ * });
399
+ * ```
400
+ */
401
+ class Zxc_json {
402
+ constructor(address, clients) {
403
+ this.contractAddress = address;
404
+ this.publicClient = clients.publicClient;
405
+ this.contract = (0, viem_1.getContract)({
406
+ address,
407
+ abi: exports.Zxc_jsonAbi,
408
+ client: {
409
+ public: clients.publicClient,
410
+ wallet: clients.walletClient,
411
+ },
412
+ });
413
+ }
414
+ /**
415
+ * Get the contract address
416
+ */
417
+ get address() {
418
+ return this.contractAddress;
419
+ }
420
+ /**
421
+ * Get the underlying viem contract instance
422
+ */
423
+ getContract() {
424
+ return this.contract;
425
+ }
426
+ /**
427
+ * name
428
+ * view
429
+ */
430
+ async name() {
431
+ return this.contract.read.name();
432
+ }
433
+ /**
434
+ * totalSupply
435
+ * view
436
+ */
437
+ async totalSupply() {
438
+ return this.contract.read.totalSupply();
439
+ }
440
+ /**
441
+ * decimals
442
+ * view
443
+ */
444
+ async decimals() {
445
+ return this.contract.read.decimals();
446
+ }
447
+ /**
448
+ * crowdsaleAddress
449
+ * view
450
+ */
451
+ async crowdsaleAddress() {
452
+ return this.contract.read.crowdsaleAddress();
453
+ }
454
+ /**
455
+ * balanceOf
456
+ * view
457
+ */
458
+ async balanceOf(_owner) {
459
+ return this.contract.read.balanceOf([_owner]);
460
+ }
461
+ /**
462
+ * owner
463
+ * view
464
+ */
465
+ async owner() {
466
+ return this.contract.read.owner();
467
+ }
468
+ /**
469
+ * symbol
470
+ * view
471
+ */
472
+ async symbol() {
473
+ return this.contract.read.symbol();
474
+ }
475
+ /**
476
+ * allowance
477
+ * view
478
+ */
479
+ async allowance(_owner, _spender) {
480
+ return this.contract.read.allowance([_owner, _spender]);
481
+ }
482
+ /**
483
+ * pendingOwner
484
+ * view
485
+ */
486
+ async pendingOwner() {
487
+ return this.contract.read.pendingOwner();
488
+ }
489
+ /**
490
+ * approve
491
+ * nonpayable
492
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
493
+ */
494
+ async approve(_spender, _value, options) {
495
+ if (!this.contract.write) {
496
+ throw new Error('Wallet client is required for write operations');
497
+ }
498
+ return this.contract.write.approve([_spender, _value], options);
499
+ }
500
+ /**
501
+ * setCrowdsaleAddress
502
+ * nonpayable
503
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
504
+ */
505
+ async setCrowdsaleAddress(crowdsaleAddr, options) {
506
+ if (!this.contract.write) {
507
+ throw new Error('Wallet client is required for write operations');
508
+ }
509
+ return this.contract.write.setCrowdsaleAddress([crowdsaleAddr], options);
510
+ }
511
+ /**
512
+ * transferFrom
513
+ * nonpayable
514
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
515
+ */
516
+ async transferFrom(_from, _to, _value, options) {
517
+ if (!this.contract.write) {
518
+ throw new Error('Wallet client is required for write operations');
519
+ }
520
+ return this.contract.write.transferFrom([_from, _to, _value], options);
521
+ }
522
+ /**
523
+ * burn
524
+ * nonpayable
525
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
526
+ */
527
+ async burn(_value, options) {
528
+ if (!this.contract.write) {
529
+ throw new Error('Wallet client is required for write operations');
530
+ }
531
+ return this.contract.write.burn([_value], options);
532
+ }
533
+ /**
534
+ * claimOwnership
535
+ * nonpayable
536
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
537
+ */
538
+ async claimOwnership(options) {
539
+ if (!this.contract.write) {
540
+ throw new Error('Wallet client is required for write operations');
541
+ }
542
+ return this.contract.write.claimOwnership(options);
543
+ }
544
+ /**
545
+ * transfer
546
+ * nonpayable
547
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
548
+ */
549
+ async transfer(_to, _value, options) {
550
+ if (!this.contract.write) {
551
+ throw new Error('Wallet client is required for write operations');
552
+ }
553
+ return this.contract.write.transfer([_to, _value], options);
554
+ }
555
+ /**
556
+ * enableTransfer
557
+ * nonpayable
558
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
559
+ */
560
+ async enableTransfer(options) {
561
+ if (!this.contract.write) {
562
+ throw new Error('Wallet client is required for write operations');
563
+ }
564
+ return this.contract.write.enableTransfer(options);
565
+ }
566
+ /**
567
+ * transferOwnership
568
+ * nonpayable
569
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
570
+ */
571
+ async transferOwnership(_newOwner, options) {
572
+ if (!this.contract.write) {
573
+ throw new Error('Wallet client is required for write operations');
574
+ }
575
+ return this.contract.write.transferOwnership([_newOwner], options);
576
+ }
577
+ /**
578
+ * Simulate contract write operations (dry-run without sending transaction)
579
+ *
580
+ * @example
581
+ * const result = await contract.simulate.transfer('0x...', 1000n);
582
+ * console.log('Gas estimate:', result.request.gas);
583
+ * console.log('Would succeed:', result.result);
584
+ */
585
+ get simulate() {
586
+ const contract = this.contract;
587
+ if (!contract.simulate) {
588
+ throw new Error('Public client is required for simulation');
589
+ }
590
+ return {
591
+ /**
592
+ * Simulate approve
593
+ * Returns gas estimate and result without sending transaction
594
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
595
+ */
596
+ async approve(_spender, _value, options) {
597
+ return contract.simulate.approve([_spender, _value], options);
598
+ },
599
+ /**
600
+ * Simulate setCrowdsaleAddress
601
+ * Returns gas estimate and result without sending transaction
602
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
603
+ */
604
+ async setCrowdsaleAddress(crowdsaleAddr, options) {
605
+ return contract.simulate.setCrowdsaleAddress([crowdsaleAddr], options);
606
+ },
607
+ /**
608
+ * Simulate transferFrom
609
+ * Returns gas estimate and result without sending transaction
610
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
611
+ */
612
+ async transferFrom(_from, _to, _value, options) {
613
+ return contract.simulate.transferFrom([_from, _to, _value], options);
614
+ },
615
+ /**
616
+ * Simulate burn
617
+ * Returns gas estimate and result without sending transaction
618
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
619
+ */
620
+ async burn(_value, options) {
621
+ return contract.simulate.burn([_value], options);
622
+ },
623
+ /**
624
+ * Simulate claimOwnership
625
+ * Returns gas estimate and result without sending transaction
626
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
627
+ */
628
+ async claimOwnership(options) {
629
+ return contract.simulate.claimOwnership(options);
630
+ },
631
+ /**
632
+ * Simulate transfer
633
+ * Returns gas estimate and result without sending transaction
634
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
635
+ */
636
+ async transfer(_to, _value, options) {
637
+ return contract.simulate.transfer([_to, _value], options);
638
+ },
639
+ /**
640
+ * Simulate enableTransfer
641
+ * Returns gas estimate and result without sending transaction
642
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
643
+ */
644
+ async enableTransfer(options) {
645
+ return contract.simulate.enableTransfer(options);
646
+ },
647
+ /**
648
+ * Simulate transferOwnership
649
+ * Returns gas estimate and result without sending transaction
650
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
651
+ */
652
+ async transferOwnership(_newOwner, options) {
653
+ return contract.simulate.transferOwnership([_newOwner], options);
654
+ }
655
+ };
656
+ }
657
+ /**
658
+ * Watch contract events
659
+ *
660
+ * @example
661
+ * // Watch all Transfer events
662
+ * const unwatch = contract.watch.Transfer((event) => {
663
+ * console.log('Transfer:', event);
664
+ * });
665
+ *
666
+ * // Stop watching
667
+ * unwatch();
668
+ */
669
+ get watch() {
670
+ return {
671
+ /**
672
+ * Watch Burn events
673
+ * @param callback Function to call when event is emitted
674
+ * @param filter Optional filter for indexed parameters
675
+ * @returns Unwatch function to stop listening
676
+ */
677
+ Burn: (callback, filter) => {
678
+ return this.publicClient.watchContractEvent({
679
+ address: this.contractAddress,
680
+ abi: exports.Zxc_jsonAbi,
681
+ eventName: 'Burn',
682
+ args: filter,
683
+ onLogs: (logs) => {
684
+ logs.forEach((log) => {
685
+ callback(log.args);
686
+ });
687
+ },
688
+ });
689
+ },
690
+ /**
691
+ * Watch OwnershipTransferred events
692
+ * @param callback Function to call when event is emitted
693
+ * @param filter Optional filter for indexed parameters
694
+ * @returns Unwatch function to stop listening
695
+ */
696
+ OwnershipTransferred: (callback, filter) => {
697
+ return this.publicClient.watchContractEvent({
698
+ address: this.contractAddress,
699
+ abi: exports.Zxc_jsonAbi,
700
+ eventName: 'OwnershipTransferred',
701
+ args: filter,
702
+ onLogs: (logs) => {
703
+ logs.forEach((log) => {
704
+ callback(log.args);
705
+ });
706
+ },
707
+ });
708
+ },
709
+ /**
710
+ * Watch Transfer events
711
+ * @param callback Function to call when event is emitted
712
+ * @param filter Optional filter for indexed parameters
713
+ * @returns Unwatch function to stop listening
714
+ */
715
+ Transfer: (callback, filter) => {
716
+ return this.publicClient.watchContractEvent({
717
+ address: this.contractAddress,
718
+ abi: exports.Zxc_jsonAbi,
719
+ eventName: 'Transfer',
720
+ args: filter,
721
+ onLogs: (logs) => {
722
+ logs.forEach((log) => {
723
+ callback(log.args);
724
+ });
725
+ },
726
+ });
727
+ },
728
+ /**
729
+ * Watch Approval events
730
+ * @param callback Function to call when event is emitted
731
+ * @param filter Optional filter for indexed parameters
732
+ * @returns Unwatch function to stop listening
733
+ */
734
+ Approval: (callback, filter) => {
735
+ return this.publicClient.watchContractEvent({
736
+ address: this.contractAddress,
737
+ abi: exports.Zxc_jsonAbi,
738
+ eventName: 'Approval',
739
+ args: filter,
740
+ onLogs: (logs) => {
741
+ logs.forEach((log) => {
742
+ callback(log.args);
743
+ });
744
+ },
745
+ });
746
+ }
747
+ };
748
+ }
749
+ }
750
+ exports.Zxc_json = Zxc_json;