@gitmyabi/erc20 1.0.1 → 1.0.2

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.
@@ -1,589 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenERC20 = exports.TokenERC20Abi = void 0;
4
- const viem_1 = require("viem");
5
- /**
6
- * TokenERC20 ABI
7
- *
8
- * This ABI is typed using viem's type system for full type safety.
9
- */
10
- exports.TokenERC20Abi = [
11
- {
12
- "constant": true,
13
- "inputs": [],
14
- "name": "name",
15
- "outputs": [
16
- {
17
- "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": "",
55
- "type": "uint256"
56
- }
57
- ],
58
- "payable": false,
59
- "stateMutability": "view",
60
- "type": "function"
61
- },
62
- {
63
- "constant": false,
64
- "inputs": [
65
- {
66
- "name": "_from",
67
- "type": "address"
68
- },
69
- {
70
- "name": "_to",
71
- "type": "address"
72
- },
73
- {
74
- "name": "_value",
75
- "type": "uint256"
76
- }
77
- ],
78
- "name": "transferFrom",
79
- "outputs": [
80
- {
81
- "name": "success",
82
- "type": "bool"
83
- }
84
- ],
85
- "payable": false,
86
- "stateMutability": "nonpayable",
87
- "type": "function"
88
- },
89
- {
90
- "constant": true,
91
- "inputs": [],
92
- "name": "decimals",
93
- "outputs": [
94
- {
95
- "name": "",
96
- "type": "uint8"
97
- }
98
- ],
99
- "payable": false,
100
- "stateMutability": "view",
101
- "type": "function"
102
- },
103
- {
104
- "constant": false,
105
- "inputs": [
106
- {
107
- "name": "_value",
108
- "type": "uint256"
109
- }
110
- ],
111
- "name": "burn",
112
- "outputs": [
113
- {
114
- "name": "success",
115
- "type": "bool"
116
- }
117
- ],
118
- "payable": false,
119
- "stateMutability": "nonpayable",
120
- "type": "function"
121
- },
122
- {
123
- "constant": true,
124
- "inputs": [
125
- {
126
- "name": "",
127
- "type": "address"
128
- }
129
- ],
130
- "name": "balanceOf",
131
- "outputs": [
132
- {
133
- "name": "",
134
- "type": "uint256"
135
- }
136
- ],
137
- "payable": false,
138
- "stateMutability": "view",
139
- "type": "function"
140
- },
141
- {
142
- "constant": false,
143
- "inputs": [
144
- {
145
- "name": "_from",
146
- "type": "address"
147
- },
148
- {
149
- "name": "_value",
150
- "type": "uint256"
151
- }
152
- ],
153
- "name": "burnFrom",
154
- "outputs": [
155
- {
156
- "name": "success",
157
- "type": "bool"
158
- }
159
- ],
160
- "payable": false,
161
- "stateMutability": "nonpayable",
162
- "type": "function"
163
- },
164
- {
165
- "constant": true,
166
- "inputs": [],
167
- "name": "symbol",
168
- "outputs": [
169
- {
170
- "name": "",
171
- "type": "string"
172
- }
173
- ],
174
- "payable": false,
175
- "stateMutability": "view",
176
- "type": "function"
177
- },
178
- {
179
- "constant": false,
180
- "inputs": [
181
- {
182
- "name": "_to",
183
- "type": "address"
184
- },
185
- {
186
- "name": "_value",
187
- "type": "uint256"
188
- }
189
- ],
190
- "name": "transfer",
191
- "outputs": [],
192
- "payable": false,
193
- "stateMutability": "nonpayable",
194
- "type": "function"
195
- },
196
- {
197
- "constant": false,
198
- "inputs": [
199
- {
200
- "name": "_spender",
201
- "type": "address"
202
- },
203
- {
204
- "name": "_value",
205
- "type": "uint256"
206
- },
207
- {
208
- "name": "_extraData",
209
- "type": "bytes"
210
- }
211
- ],
212
- "name": "approveAndCall",
213
- "outputs": [
214
- {
215
- "name": "success",
216
- "type": "bool"
217
- }
218
- ],
219
- "payable": false,
220
- "stateMutability": "nonpayable",
221
- "type": "function"
222
- },
223
- {
224
- "constant": true,
225
- "inputs": [
226
- {
227
- "name": "",
228
- "type": "address"
229
- },
230
- {
231
- "name": "",
232
- "type": "address"
233
- }
234
- ],
235
- "name": "allowance",
236
- "outputs": [
237
- {
238
- "name": "",
239
- "type": "uint256"
240
- }
241
- ],
242
- "payable": false,
243
- "stateMutability": "view",
244
- "type": "function"
245
- },
246
- {
247
- "inputs": [
248
- {
249
- "name": "initialSupply",
250
- "type": "uint256"
251
- },
252
- {
253
- "name": "tokenName",
254
- "type": "string"
255
- },
256
- {
257
- "name": "tokenSymbol",
258
- "type": "string"
259
- }
260
- ],
261
- "payable": false,
262
- "stateMutability": "nonpayable",
263
- "type": "constructor"
264
- },
265
- {
266
- "anonymous": false,
267
- "inputs": [
268
- {
269
- "indexed": true,
270
- "name": "from",
271
- "type": "address"
272
- },
273
- {
274
- "indexed": true,
275
- "name": "to",
276
- "type": "address"
277
- },
278
- {
279
- "indexed": false,
280
- "name": "value",
281
- "type": "uint256"
282
- }
283
- ],
284
- "name": "Transfer",
285
- "type": "event"
286
- },
287
- {
288
- "anonymous": false,
289
- "inputs": [
290
- {
291
- "indexed": true,
292
- "name": "from",
293
- "type": "address"
294
- },
295
- {
296
- "indexed": false,
297
- "name": "value",
298
- "type": "uint256"
299
- }
300
- ],
301
- "name": "Burn",
302
- "type": "event"
303
- }
304
- ];
305
- /**
306
- * TokenERC20 Contract Class
307
- *
308
- * Provides a class-based API similar to TypeChain for interacting with the contract.
309
- *
310
- * @example
311
- * ```typescript
312
- * import { createPublicClient, createWalletClient, http } from 'viem';
313
- * import { mainnet } from 'viem/chains';
314
- * import { TokenERC20 } from 'TokenERC20';
315
- *
316
- * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
317
- * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
318
- *
319
- * const contract = new TokenERC20('0x...', { publicClient, walletClient });
320
- *
321
- * // Read functions
322
- * const result = await contract.balanceOf('0x...');
323
- *
324
- * // Write functions
325
- * const hash = await contract.transfer('0x...', 1000n);
326
- *
327
- * // Simulate transactions (dry-run)
328
- * const simulation = await contract.simulate.transfer('0x...', 1000n);
329
- * console.log('Gas estimate:', simulation.request.gas);
330
- *
331
- * // Watch events
332
- * const unwatch = contract.watch.Transfer((event) => {
333
- * console.log('Transfer event:', event);
334
- * });
335
- * ```
336
- */
337
- class TokenERC20 {
338
- constructor(address, clients) {
339
- this.contractAddress = address;
340
- this.publicClient = clients.publicClient;
341
- this.contract = (0, viem_1.getContract)({
342
- address,
343
- abi: exports.TokenERC20Abi,
344
- client: {
345
- public: clients.publicClient,
346
- wallet: clients.walletClient,
347
- },
348
- });
349
- }
350
- /**
351
- * Get the contract address
352
- */
353
- get address() {
354
- return this.contractAddress;
355
- }
356
- /**
357
- * Get the underlying viem contract instance.
358
- */
359
- getContract() {
360
- return this.contract;
361
- }
362
- /**
363
- * name
364
- * view
365
- */
366
- async name() {
367
- return this.contract.read.name();
368
- }
369
- /**
370
- * totalSupply
371
- * view
372
- */
373
- async totalSupply() {
374
- return this.contract.read.totalSupply();
375
- }
376
- /**
377
- * decimals
378
- * view
379
- */
380
- async decimals() {
381
- return this.contract.read.decimals();
382
- }
383
- /**
384
- * balanceOf
385
- * view
386
- */
387
- async balanceOf(arg0) {
388
- return this.contract.read.balanceOf([arg0]);
389
- }
390
- /**
391
- * symbol
392
- * view
393
- */
394
- async symbol() {
395
- return this.contract.read.symbol();
396
- }
397
- /**
398
- * allowance
399
- * view
400
- */
401
- async allowance(arg0, arg1) {
402
- return this.contract.read.allowance([arg0, arg1]);
403
- }
404
- /**
405
- * approve
406
- * nonpayable
407
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
408
- */
409
- async approve(_spender, _value, options) {
410
- if (!this.contract.write) {
411
- throw new Error('Wallet client is required for write operations');
412
- }
413
- return this.contract.write.approve([_spender, _value], options);
414
- }
415
- /**
416
- * transferFrom
417
- * nonpayable
418
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
419
- */
420
- async transferFrom(_from, _to, _value, options) {
421
- if (!this.contract.write) {
422
- throw new Error('Wallet client is required for write operations');
423
- }
424
- return this.contract.write.transferFrom([_from, _to, _value], options);
425
- }
426
- /**
427
- * burn
428
- * nonpayable
429
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
430
- */
431
- async burn(_value, options) {
432
- if (!this.contract.write) {
433
- throw new Error('Wallet client is required for write operations');
434
- }
435
- return this.contract.write.burn([_value], options);
436
- }
437
- /**
438
- * burnFrom
439
- * nonpayable
440
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
441
- */
442
- async burnFrom(_from, _value, options) {
443
- if (!this.contract.write) {
444
- throw new Error('Wallet client is required for write operations');
445
- }
446
- return this.contract.write.burnFrom([_from, _value], options);
447
- }
448
- /**
449
- * transfer
450
- * nonpayable
451
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
452
- */
453
- async transfer(_to, _value, options) {
454
- if (!this.contract.write) {
455
- throw new Error('Wallet client is required for write operations');
456
- }
457
- return this.contract.write.transfer([_to, _value], options);
458
- }
459
- /**
460
- * approveAndCall
461
- * nonpayable
462
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
463
- */
464
- async approveAndCall(_spender, _value, _extraData, options) {
465
- if (!this.contract.write) {
466
- throw new Error('Wallet client is required for write operations');
467
- }
468
- return this.contract.write.approveAndCall([_spender, _value, _extraData], options);
469
- }
470
- /**
471
- * Simulate contract write operations (dry-run without sending transaction)
472
- *
473
- * @example
474
- * const result = await contract.simulate.transfer('0x...', 1000n);
475
- * console.log('Gas estimate:', result.request.gas);
476
- * console.log('Would succeed:', result.result);
477
- */
478
- get simulate() {
479
- const contract = this.contract;
480
- if (!contract.simulate) {
481
- throw new Error('Public client is required for simulation');
482
- }
483
- return {
484
- /**
485
- * Simulate approve
486
- * Returns gas estimate and result without sending transaction
487
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
488
- */
489
- async approve(_spender, _value, options) {
490
- return contract.simulate.approve([_spender, _value], options);
491
- },
492
- /**
493
- * Simulate transferFrom
494
- * Returns gas estimate and result without sending transaction
495
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
496
- */
497
- async transferFrom(_from, _to, _value, options) {
498
- return contract.simulate.transferFrom([_from, _to, _value], options);
499
- },
500
- /**
501
- * Simulate burn
502
- * Returns gas estimate and result without sending transaction
503
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
504
- */
505
- async burn(_value, options) {
506
- return contract.simulate.burn([_value], options);
507
- },
508
- /**
509
- * Simulate burnFrom
510
- * Returns gas estimate and result without sending transaction
511
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
512
- */
513
- async burnFrom(_from, _value, options) {
514
- return contract.simulate.burnFrom([_from, _value], options);
515
- },
516
- /**
517
- * Simulate transfer
518
- * Returns gas estimate and result without sending transaction
519
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
520
- */
521
- async transfer(_to, _value, options) {
522
- return contract.simulate.transfer([_to, _value], options);
523
- },
524
- /**
525
- * Simulate approveAndCall
526
- * Returns gas estimate and result without sending transaction
527
- * @param options Optional transaction parameters (value, gas, nonce, etc.)
528
- */
529
- async approveAndCall(_spender, _value, _extraData, options) {
530
- return contract.simulate.approveAndCall([_spender, _value, _extraData], options);
531
- }
532
- };
533
- }
534
- /**
535
- * Watch contract events
536
- *
537
- * @example
538
- * // Watch all Transfer events
539
- * const unwatch = contract.watch.Transfer((event) => {
540
- * console.log('Transfer:', event);
541
- * });
542
- *
543
- * // Stop watching
544
- * unwatch();
545
- */
546
- get watch() {
547
- return {
548
- /**
549
- * Watch Transfer events
550
- * @param callback Function to call when event is emitted
551
- * @param filter Optional filter for indexed parameters
552
- * @returns Unwatch function to stop listening
553
- */
554
- Transfer: (callback, filter) => {
555
- return this.publicClient.watchContractEvent({
556
- address: this.contractAddress,
557
- abi: exports.TokenERC20Abi,
558
- eventName: 'Transfer',
559
- args: filter,
560
- onLogs: (logs) => {
561
- logs.forEach((log) => {
562
- callback(log.args);
563
- });
564
- },
565
- });
566
- },
567
- /**
568
- * Watch Burn events
569
- * @param callback Function to call when event is emitted
570
- * @param filter Optional filter for indexed parameters
571
- * @returns Unwatch function to stop listening
572
- */
573
- Burn: (callback, filter) => {
574
- return this.publicClient.watchContractEvent({
575
- address: this.contractAddress,
576
- abi: exports.TokenERC20Abi,
577
- eventName: 'Burn',
578
- args: filter,
579
- onLogs: (logs) => {
580
- logs.forEach((log) => {
581
- callback(log.args);
582
- });
583
- },
584
- });
585
- }
586
- };
587
- }
588
- }
589
- exports.TokenERC20 = TokenERC20;