essential-eth 0.13.0 → 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/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
- import { logger, encodeData, decodeRPCResponse, toChecksumAddress, hexlify } from './chunk-C4VOKUKQ.js';
2
- export { arrayify, computeAddress, computePublicKey, concat, hashMessage, hexConcat, hexDataLength, hexDataSlice, hexStripZeros, hexValue, hexZeroPad, hexlify, isAddress, isBytes, isBytesLike, isHexString, keccak256, pack, solidityKeccak256, splitSignature, stripZeros, toChecksumAddress, toUtf8Bytes, zeroPad } from './chunk-C4VOKUKQ.js';
3
- import { hexToDecimal, tinyBig, TinyBig } from './chunk-UXC5R4JE.js';
4
- export { TinyBig, etherToGwei, etherToWei, gweiToEther, tinyBig, weiToEther } from './chunk-UXC5R4JE.js';
1
+ import { keccak256, toUtf8Bytes, logger, encodeData, decodeRPCResponse, arrayify, hexlify, toChecksumAddress, hexToDecimal } from './chunk-CLIQ4S3P.js';
2
+ export { arrayify, computeAddress, computePublicKey, concat, hashMessage, hexConcat, hexDataLength, hexDataSlice, hexStripZeros, hexValue, hexZeroPad, hexlify, isAddress, isBytes, isBytesLike, isHexString, keccak256, pack, solidityKeccak256, splitSignature, stripZeros, toChecksumAddress, toUtf8Bytes, zeroPad } from './chunk-CLIQ4S3P.js';
3
+ import { formatFixed, toBigInt, parseFixed } from './chunk-GFWRB7PT.js';
4
+ export { etherToGwei, etherToWei, gweiToEther, weiToEther } from './chunk-GFWRB7PT.js';
5
5
  import unfetch from 'isomorphic-unfetch';
6
- import Big from 'big.js';
7
6
 
8
7
  // src/classes/Contract.ts
9
8
  function estimateGas(txnData) {
@@ -78,7 +77,8 @@ function cleanTransaction(transaction) {
78
77
  ...transaction
79
78
  };
80
79
  Object.keys(transaction).forEach((key) => {
81
- if (!transaction[key]) return;
80
+ if (!transaction[key])
81
+ return;
82
82
  switch (key) {
83
83
  case "blockNumber":
84
84
  case "chainId":
@@ -99,7 +99,7 @@ function cleanTransaction(transaction) {
99
99
  case "maxFeePerGas":
100
100
  case "maxPriorityFeePerGas":
101
101
  case "nonce":
102
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
102
+ cleanedTransaction[key] = BigInt(hexToDecimal(transaction[key]));
103
103
  break;
104
104
  }
105
105
  });
@@ -110,7 +110,8 @@ function cleanTransaction(transaction) {
110
110
  function cleanBlock(block, returnTransactionObjects) {
111
111
  const cleanedBlock = { ...block };
112
112
  Object.keys(block).forEach((key) => {
113
- if (!block[key]) return;
113
+ if (!block[key])
114
+ return;
114
115
  switch (key) {
115
116
  case "difficulty":
116
117
  case "totalDifficulty":
@@ -119,7 +120,7 @@ function cleanBlock(block, returnTransactionObjects) {
119
120
  case "size":
120
121
  case "timestamp":
121
122
  case "baseFeePerGas":
122
- cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
123
+ cleanedBlock[key] = BigInt(hexToDecimal(block[key]));
123
124
  break;
124
125
  case "number":
125
126
  cleanedBlock[key] = Number(hexToDecimal(block[key]));
@@ -172,7 +173,8 @@ function cleanTransactionReceipt(transactionReceipt) {
172
173
  ...cleanedTransaction
173
174
  };
174
175
  Object.keys(transactionReceipt).forEach((key) => {
175
- if (!transactionReceipt[key]) return;
176
+ if (!transactionReceipt[key])
177
+ return;
176
178
  switch (key) {
177
179
  case "status":
178
180
  cleanedTransactionReceipt[key] = Number(
@@ -189,7 +191,7 @@ function cleanTransactionReceipt(transactionReceipt) {
189
191
  case "cumulativeGasUsed":
190
192
  case "effectiveGasPrice":
191
193
  case "gasUsed":
192
- cleanedTransactionReceipt[key] = tinyBig(
194
+ cleanedTransactionReceipt[key] = BigInt(
193
195
  hexToDecimal(transactionReceipt[key])
194
196
  );
195
197
  break;
@@ -238,6 +240,8 @@ function buildRPCPostBody(method, params) {
238
240
  params
239
241
  };
240
242
  }
243
+
244
+ // src/classes/utils/prepare-transaction.ts
241
245
  function prepareTransaction(transaction) {
242
246
  const preparedTransaction = {
243
247
  ...transaction
@@ -252,15 +256,13 @@ function prepareTransaction(transaction) {
252
256
  case "maxPriorityFeePerGas":
253
257
  case "value": {
254
258
  const value = transaction[key];
255
- if (value instanceof TinyBig) {
256
- preparedTransaction[key] = value.toHexString();
257
- } else if (value instanceof Big) {
258
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(
259
- 16
260
- )}`;
261
- } else if (typeof transaction[key] === "number")
262
- preparedTransaction[key] = "0x" + transaction[key].toString(16);
263
- else preparedTransaction[key] = transaction[key].toString();
259
+ if (typeof value === "bigint") {
260
+ preparedTransaction[key] = "0x" + value.toString(16);
261
+ } else if (typeof value === "number") {
262
+ preparedTransaction[key] = "0x" + value.toString(16);
263
+ } else {
264
+ preparedTransaction[key] = value.toString();
265
+ }
264
266
  break;
265
267
  }
266
268
  case "data":
@@ -272,6 +274,20 @@ function prepareTransaction(transaction) {
272
274
  return preparedTransaction;
273
275
  }
274
276
 
277
+ // src/utils/namehash.ts
278
+ function namehash(name) {
279
+ let node = "0x0000000000000000000000000000000000000000000000000000000000000000";
280
+ if (name === "") {
281
+ return node;
282
+ }
283
+ const labels = name.split(".");
284
+ for (let i = labels.length - 1; i >= 0; i--) {
285
+ const labelHash = keccak256(toUtf8Bytes(labels[i]));
286
+ node = keccak256("0x" + node.slice(2) + labelHash.slice(2));
287
+ }
288
+ return node;
289
+ }
290
+
275
291
  // src/providers/utils/chains-info.ts
276
292
  var chains_info_default = {
277
293
  "1": [
@@ -343,7 +359,7 @@ var chains_info_default = {
343
359
 
344
360
  // src/providers/BaseProvider.ts
345
361
  function prepBlockTag(blockTag) {
346
- return typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag;
362
+ return typeof blockTag === "number" ? "0x" + blockTag.toString(16) : blockTag;
347
363
  }
348
364
  var BaseProvider = class {
349
365
  /**
@@ -369,7 +385,6 @@ var BaseProvider = class {
369
385
  *
370
386
  * * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
371
387
  * * [Similar](/docs/api#isd) to [`web3.eth.getChainId`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getchainid) in web3.js, returns more than just the `chainId`
372
- *
373
388
  * @returns information about the network this provider is currently connected to
374
389
  * @example
375
390
  * ```javascript
@@ -400,7 +415,6 @@ var BaseProvider = class {
400
415
  *
401
416
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
402
417
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
403
- *
404
418
  * @returns the number of the most recently mined block
405
419
  * @example
406
420
  * ```javascript
@@ -419,7 +433,6 @@ var BaseProvider = class {
419
433
  *
420
434
  * * [Similar](/docs/api#isd) to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction) in ethers.js, does not have `wait` method that waits until the transaction has been mined
421
435
  * * [Similar](/docs/api#isd) to [`web3.eth.getTransaction`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransaction) in web3.js, some information returned using different types
422
- *
423
436
  * @param transactionHash the hash of the transaction to get information about
424
437
  * @returns information about the specified transaction
425
438
  * @example
@@ -431,20 +444,20 @@ var BaseProvider = class {
431
444
  * // blockNumber: 14578286,
432
445
  * // chainId: 1,
433
446
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
434
- * // gas: { TinyBig: 112163 },
435
- * // gasPrice: { TinyBig: 48592426858 },
447
+ * // gas: 112163n,
448
+ * // gasPrice: 48592426858n,
436
449
  * // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
437
450
  * // input: "0x83259f17000000000000000000000000000000000000000000...",
438
- * // maxFeePerGas: { TinyBig: 67681261618 },
439
- * // maxPriorityFeePerGas: { TinyBig: 1500000000 },
440
- * // nonce: { TinyBig: 129 },
451
+ * // maxFeePerGas: 67681261618n,
452
+ * // maxPriorityFeePerGas: 1500000000n,
453
+ * // nonce: 129n,
441
454
  * // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
442
455
  * // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
443
456
  * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
444
457
  * // transactionIndex: 29,
445
458
  * // type: 2,
446
459
  * // v: 0,
447
- * // value: { TinyBig: 0 },
460
+ * // value: 0n,
448
461
  * // confirmations: 298140,
449
462
  * // }
450
463
  * ```
@@ -465,7 +478,6 @@ var BaseProvider = class {
465
478
  *
466
479
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
467
480
  * * [Similar](/docs/api#isd) to [`web3.eth.getTransactionReceipt`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactionreceipt) in web3.js, some information returned using different types
468
- *
469
481
  * @param transactionHash the hash of the transaction to get information about
470
482
  * @returns information about the specified transaction that has already been mined
471
483
  * @example
@@ -475,10 +487,10 @@ var BaseProvider = class {
475
487
  * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
476
488
  * // blockNumber: 14578286,
477
489
  * // contractAddress: null,
478
- * // cumulativeGasUsed: { TinyBig: 3067973 },
479
- * // effectiveGasPrice: { TinyBig: 48592426858 },
490
+ * // cumulativeGasUsed: 3067973n,
491
+ * // effectiveGasPrice: 48592426858n,
480
492
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
481
- * // gasUsed: { TinyBig: 112163 },
493
+ * // gasUsed: 112163n,
482
494
  * // logs: [
483
495
  * // {
484
496
  * // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
@@ -536,7 +548,6 @@ var BaseProvider = class {
536
548
  *
537
549
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
538
550
  * * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
539
- *
540
551
  * @param address the address to count number of sent transactions
541
552
  * @param blockTag the block to count transactions up to, inclusive
542
553
  * @returns the number of transactions sent by the specified address
@@ -568,7 +579,6 @@ var BaseProvider = class {
568
579
  *
569
580
  * * [Similar](/docs/api#isd) to [`ethers.provider.getBlock`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js, includes some additional information. Can also return block with full transaction objects, similar to [`ethers.providers.getBlockWithTransactions`]
570
581
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
571
- *
572
582
  * @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
573
583
  * @param returnTransactionObjects Whether to also return data about the transactions on the block.
574
584
  * @returns A BlockResponse object with information about the specified block
@@ -576,11 +586,11 @@ var BaseProvider = class {
576
586
  * ```javascript
577
587
  * await provider.getBlock(14879862);
578
588
  * // {
579
- * // baseFeePerGas: { TinyBig: 39095728776 },
580
- * // difficulty: { TinyBig: 14321294455359973 },
589
+ * // baseFeePerGas: 39095728776n,
590
+ * // difficulty: 14321294455359973n,
581
591
  * // extraData: "0x486976656f6e2073672d6865617679",
582
- * // gasLimit: { TinyBig: 29970620 },
583
- * // gasUsed: { TinyBig: 20951384 },
592
+ * // gasLimit: 29970620n,
593
+ * // gasUsed: 20951384n,
584
594
  * // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
585
595
  * // logsBloom:
586
596
  * // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
@@ -591,10 +601,10 @@ var BaseProvider = class {
591
601
  * // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
592
602
  * // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
593
603
  * // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
594
- * // size: { TinyBig: 134483 },
604
+ * // size: 134483n,
595
605
  * // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
596
- * // timestamp: { TinyBig: 1654016186 },
597
- * // totalDifficulty: { TinyBig: 50478104614257705213748 },
606
+ * // timestamp: 1654016186n,
607
+ * // totalDifficulty: 50478104614257705213748n,
598
608
  * // transactions: [
599
609
  * // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
600
610
  * // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
@@ -625,8 +635,7 @@ var BaseProvider = class {
625
635
  * Gives an estimate of the current gas price in wei.
626
636
  *
627
637
  * * [Similar](/docs/api#isd) to [`ethers.provider.getGasPrice`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getGasPrice) in ethers.js, does not have a parameter specifying what unit you'd like to return. See also [`weiToEther`](/docs/api/modules#weitoether) and [`etherToGwei`](/docs/api/modules#ethertogwei)
628
- * * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (TinyBig) instead of a string
629
- *
638
+ * * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (bigint) instead of a string
630
639
  * @returns an estimate of the current gas price in wei
631
640
  * @example
632
641
  * ```javascript
@@ -638,14 +647,13 @@ var BaseProvider = class {
638
647
  const hexGasPrice = await this.post(
639
648
  buildRPCPostBody("eth_gasPrice", [])
640
649
  );
641
- return tinyBig(hexToDecimal(hexGasPrice));
650
+ return BigInt(hexToDecimal(hexGasPrice));
642
651
  }
643
652
  /**
644
653
  * Returns the balance of the account in wei.
645
654
  *
646
655
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
647
- * * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (TinyBig) instead of a string
648
- *
656
+ * * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (bigint) instead of a string
649
657
  * @param address the address to check the balance of
650
658
  * @param blockTag the block to check the specified address' balance on
651
659
  * @returns the balance of the network's native token for the specified address on the specified block
@@ -660,14 +668,13 @@ var BaseProvider = class {
660
668
  const hexBalance = await this.post(
661
669
  buildRPCPostBody("eth_getBalance", [address, blockTag])
662
670
  );
663
- return tinyBig(hexToDecimal(hexBalance));
671
+ return BigInt(hexToDecimal(hexBalance));
664
672
  }
665
673
  /**
666
674
  * Gets the code of a contract on a specified block.
667
675
  *
668
676
  * * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
669
677
  * * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
670
- *
671
678
  * @param address the contract address to get the contract code from
672
679
  * @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
673
680
  * @returns the contract creation code for the specified address at the specified block height
@@ -690,7 +697,6 @@ var BaseProvider = class {
690
697
  *
691
698
  * * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
692
699
  * * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
693
- *
694
700
  * @param transaction the transaction to check the estimated gas cost for
695
701
  * @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
696
702
  * @example
@@ -701,7 +707,7 @@ var BaseProvider = class {
701
707
  * data: "0xd0e30db0",
702
708
  * value: etherToWei('1.0').toHexString(),
703
709
  * });
704
- * // { TinyBig: "27938" }
710
+ * // 27938n
705
711
  * ```
706
712
  */
707
713
  async estimateGas(transaction) {
@@ -709,7 +715,7 @@ var BaseProvider = class {
709
715
  const gasUsed = await this.post(
710
716
  buildRPCPostBody("eth_estimateGas", [rpcTransaction])
711
717
  );
712
- return tinyBig(hexToDecimal(gasUsed));
718
+ return BigInt(hexToDecimal(gasUsed));
713
719
  }
714
720
  /**
715
721
  * Returns the current recommended FeeData to use in a transaction.
@@ -717,16 +723,15 @@ var BaseProvider = class {
717
723
  * For legacy transactions and networks which do not support EIP-1559, the gasPrice should be used.Returns an estimate of the amount of gas that would be required to submit transaction to the network.
718
724
  *
719
725
  * * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
720
- *
721
726
  * @returns an object with gas estimates for the network currently
722
727
  * @example
723
728
  * ```javascript
724
729
  * await provider.getFeeData();
725
730
  * // {
726
- * // gasPrice: { TinyBig: "14184772639" },
727
- * // lastBaseFeePerGas: { TinyBig: "14038523098" },
728
- * // maxFeePerGas: { TinyBig: "29577046196" },
729
- * // maxPriorityFeePerGas: { TinyBig: "1500000000" }
731
+ * // gasPrice: 14184772639n,
732
+ * // lastBaseFeePerGas: 14038523098n,
733
+ * // maxFeePerGas: 29577046196n,
734
+ * // maxPriorityFeePerGas: 1500000000n
730
735
  * // }
731
736
  * ```
732
737
  */
@@ -738,10 +743,8 @@ var BaseProvider = class {
738
743
  let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
739
744
  if (block && block.baseFeePerGas) {
740
745
  lastBaseFeePerGas = block.baseFeePerGas;
741
- maxPriorityFeePerGas = tinyBig("1500000000");
742
- maxFeePerGas = tinyBig(
743
- block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas)
744
- );
746
+ maxPriorityFeePerGas = BigInt("1500000000");
747
+ maxFeePerGas = block.baseFeePerGas * 2n + maxPriorityFeePerGas;
745
748
  }
746
749
  return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
747
750
  }
@@ -751,7 +754,6 @@ var BaseProvider = class {
751
754
  *
752
755
  * * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
753
756
  * * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
754
- *
755
757
  * @param filter parameters to filter the logs by
756
758
  * @returns an array of logs matching the specified filter
757
759
  * @example
@@ -803,7 +805,6 @@ var BaseProvider = class {
803
805
  *
804
806
  * * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
805
807
  * * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
806
- *
807
808
  * @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
808
809
  * @param blockTag the block to execute this transaction on
809
810
  * @returns the result of executing the transaction on the specified block
@@ -840,6 +841,61 @@ var BaseProvider = class {
840
841
  );
841
842
  return transactionRes;
842
843
  }
844
+ /**
845
+ * Resolves an ENS name to an Ethereum address.
846
+ *
847
+ * Performs the full ENS resolution process:
848
+ * 1. Computes the namehash of the ENS name
849
+ * 2. Queries the ENS Registry for the resolver contract
850
+ * 3. Queries the resolver for the address
851
+ *
852
+ * * [Identical](/docs/api#isd) to [`ethers.provider.resolveName`](https://docs.ethers.io/v5/api/providers/provider/#Provider-resolveName) in ethers.js
853
+ * @param name the ENS name to resolve (e.g. 'vitalik.eth')
854
+ * @returns the Ethereum address the name resolves to, or null if not found
855
+ * @example
856
+ * ```javascript
857
+ * await provider.resolveName('vitalik.eth');
858
+ * // '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
859
+ * ```
860
+ * @example
861
+ * ```javascript
862
+ * await provider.resolveName('thisshouldnotexist12345.eth');
863
+ * // null
864
+ * ```
865
+ */
866
+ async resolveName(name) {
867
+ const ENS_REGISTRY = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
868
+ const RESOLVER_SELECTOR = "0x0178b8bf";
869
+ const ADDR_SELECTOR = "0x3b3b57de";
870
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
871
+ const node = namehash(name);
872
+ const nodeWithoutPrefix = node.slice(2);
873
+ const resolverData = RESOLVER_SELECTOR + nodeWithoutPrefix;
874
+ const resolverResult = await this.call({
875
+ to: ENS_REGISTRY,
876
+ data: resolverData
877
+ });
878
+ if (!resolverResult || resolverResult === ZERO_ADDRESS) {
879
+ return null;
880
+ }
881
+ const resolverAddress = "0x" + resolverResult.slice(26);
882
+ if (resolverAddress === "0x0000000000000000000000000000000000000000" || resolverAddress === "0x" + "0".repeat(resolverResult.length - 2)) {
883
+ return null;
884
+ }
885
+ const addrData = ADDR_SELECTOR + nodeWithoutPrefix;
886
+ const addrResult = await this.call({
887
+ to: resolverAddress,
888
+ data: addrData
889
+ });
890
+ if (!addrResult || addrResult === ZERO_ADDRESS) {
891
+ return null;
892
+ }
893
+ const rawAddress = "0x" + addrResult.slice(26);
894
+ if (rawAddress === "0x0000000000000000000000000000000000000000") {
895
+ return null;
896
+ }
897
+ return toChecksumAddress(rawAddress);
898
+ }
843
899
  };
844
900
 
845
901
  // src/providers/JsonRpcProvider.ts
@@ -941,4 +997,149 @@ var FallthroughProvider = class extends BaseProvider {
941
997
  };
942
998
  };
943
999
 
944
- export { AlchemyProvider, BaseContract, Contract, FallthroughProvider, JsonRpcProvider, jsonRpcProvider };
1000
+ // src/utils/abi-encode-decode.ts
1001
+ function findFunctionABI(abi, functionName) {
1002
+ const entry = abi.find(
1003
+ (item) => item.type === "function" && item.name === functionName
1004
+ );
1005
+ if (!entry) {
1006
+ throw new Error(`Function "${functionName}" not found in ABI`);
1007
+ }
1008
+ return entry;
1009
+ }
1010
+ function encodeFunctionData(abi, functionName, args = []) {
1011
+ const abiEntry = findFunctionABI(abi, functionName);
1012
+ return encodeData(abiEntry, args);
1013
+ }
1014
+ function decodeFunctionResult(abi, functionName, data) {
1015
+ const abiEntry = findFunctionABI(abi, functionName);
1016
+ return decodeRPCResponse(abiEntry, data);
1017
+ }
1018
+
1019
+ // src/utils/to-utf8-string.ts
1020
+ function toUtf8String(bytes) {
1021
+ return new TextDecoder().decode(arrayify(bytes));
1022
+ }
1023
+
1024
+ // src/utils/bytes32-string.ts
1025
+ function encodeBytes32String(text) {
1026
+ const bytes = toUtf8Bytes(text);
1027
+ if (bytes.length > 31) {
1028
+ throw new Error("bytes32 string must be less than 32 bytes");
1029
+ }
1030
+ const padded = new Uint8Array(32);
1031
+ padded.set(bytes);
1032
+ return hexlify(padded);
1033
+ }
1034
+ function decodeBytes32String(bytes32) {
1035
+ let hex = bytes32;
1036
+ if (hex.startsWith("0x") || hex.startsWith("0X")) {
1037
+ hex = hex.slice(2);
1038
+ }
1039
+ hex = hex.replace(/(00)+$/, "");
1040
+ if (hex.length === 0)
1041
+ return "";
1042
+ return toUtf8String("0x" + hex);
1043
+ }
1044
+
1045
+ // src/utils/decode-event-log.ts
1046
+ function computeEventTopic(event) {
1047
+ const types = event.inputs.map((input) => input.type);
1048
+ const signature = `${event.name}(${types.join(",")})`;
1049
+ return keccak256(toUtf8Bytes(signature));
1050
+ }
1051
+ function decodeValue(hexChunk, type) {
1052
+ if (type === "bool") {
1053
+ return hexChunk[hexChunk.length - 1] === "1";
1054
+ }
1055
+ if (type === "address") {
1056
+ return toChecksumAddress(`0x${hexChunk.slice(24)}`);
1057
+ }
1058
+ if (type === "bytes32") {
1059
+ return `0x${hexChunk}`;
1060
+ }
1061
+ if (type === "uint8") {
1062
+ return Number(BigInt(`0x${hexChunk}`));
1063
+ }
1064
+ if (type.startsWith("uint")) {
1065
+ return BigInt(`0x${hexChunk}`);
1066
+ }
1067
+ if (type.startsWith("int")) {
1068
+ return BigInt(`0x${hexChunk}`);
1069
+ }
1070
+ throw new Error(
1071
+ `essential-eth does not yet support decoding "${type}" in event logs. Make a PR today!`
1072
+ );
1073
+ }
1074
+ function decodeEventLog(abi, log) {
1075
+ const topic0 = log.topics[0];
1076
+ const events = abi.filter((entry) => entry.type === "event");
1077
+ let matchedEvent;
1078
+ for (const event of events) {
1079
+ const hash = computeEventTopic(event);
1080
+ if (hash === topic0) {
1081
+ matchedEvent = event;
1082
+ break;
1083
+ }
1084
+ }
1085
+ if (!matchedEvent) {
1086
+ throw new Error(`No matching event found in ABI for topic0: ${topic0}`);
1087
+ }
1088
+ const args = {};
1089
+ let topicIndex = 1;
1090
+ let dataOffset = 0;
1091
+ const rawData = log.data.startsWith("0x") ? log.data.slice(2) : log.data;
1092
+ for (const input of matchedEvent.inputs) {
1093
+ if (input.indexed) {
1094
+ const topicHex = log.topics[topicIndex];
1095
+ const hexChunk = topicHex.startsWith("0x") ? topicHex.slice(2) : topicHex;
1096
+ args[input.name] = decodeValue(hexChunk, input.type);
1097
+ topicIndex++;
1098
+ } else {
1099
+ const hexChunk = rawData.slice(dataOffset, dataOffset + 64);
1100
+ args[input.name] = decodeValue(hexChunk, input.type);
1101
+ dataOffset += 64;
1102
+ }
1103
+ }
1104
+ return {
1105
+ eventName: matchedEvent.name,
1106
+ args
1107
+ };
1108
+ }
1109
+
1110
+ // src/utils/event-topic.ts
1111
+ function getEventTopic(eventSignature) {
1112
+ return keccak256(toUtf8Bytes(eventSignature));
1113
+ }
1114
+ function getEventSignature(abi, eventName) {
1115
+ const event = abi.find(
1116
+ (entry) => entry.type === "event" && entry.name === eventName
1117
+ );
1118
+ if (!event) {
1119
+ throw new Error(`Event "${eventName}" not found in ABI`);
1120
+ }
1121
+ const signature = `${event.name}(${event.inputs.map((input) => input.type).join(",")})`;
1122
+ return getEventTopic(signature);
1123
+ }
1124
+
1125
+ // src/utils/format-units.ts
1126
+ function formatUnits(value, decimals = 18) {
1127
+ return formatFixed(toBigInt(value), decimals);
1128
+ }
1129
+
1130
+ // src/utils/get-address.ts
1131
+ function getAddress(address) {
1132
+ return toChecksumAddress(address);
1133
+ }
1134
+
1135
+ // src/utils/id.ts
1136
+ function id(text) {
1137
+ return keccak256(toUtf8Bytes(text));
1138
+ }
1139
+
1140
+ // src/utils/parse-units.ts
1141
+ function parseUnits(value, decimals = 18) {
1142
+ return parseFixed(value, decimals);
1143
+ }
1144
+
1145
+ export { AlchemyProvider, BaseContract, Contract, FallthroughProvider, JsonRpcProvider, decodeBytes32String, decodeEventLog, decodeFunctionResult, encodeBytes32String, encodeFunctionData, formatUnits, getAddress, getEventSignature, getEventTopic, id, jsonRpcProvider, namehash, parseUnits, toUtf8String };
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { d as arrayify, e as computeAddress, f as computePublicKey, g as concat, h as hashMessage, i as hexConcat, j as hexDataLength, k as hexDataSlice, l as hexStripZeros, m as hexValue, n as hexZeroPad, o as hexlify, p as isAddress, q as isBytes, r as isBytesLike, s as isHexString, t as keccak256, u as pack, v as solidityKeccak256, w as splitSignature, x as stripZeros, y as toChecksumAddress, z as toUtf8Bytes, A as zeroPad } from './index-utils-D40THakY.js';
1
+ export { a as arrayify, p as computeAddress, q as computePublicKey, d as concat, r as hashMessage, h as hexConcat, e as hexDataLength, f as hexDataSlice, i as hexStripZeros, j as hexValue, k as hexZeroPad, g as hexlify, t as isAddress, l as isBytes, m as isBytesLike, n as isHexString, u as keccak256, v as pack, w as solidityKeccak256, x as splitSignature, s as stripZeros, y as toChecksumAddress, A as toUtf8Bytes, z as zeroPad } from './index-utils-e8a8adc8.js';
2
2
  export { etherToGwei, etherToWei, gweiToEther, weiToEther } from './conversions.js';
3
- import 'big.js';
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- export { arrayify, computeAddress, computePublicKey, concat, hashMessage, hexConcat, hexDataLength, hexDataSlice, hexStripZeros, hexValue, hexZeroPad, hexlify, isAddress, isBytes, isBytesLike, isHexString, keccak256, pack, solidityKeccak256, splitSignature, stripZeros, toChecksumAddress, toUtf8Bytes, zeroPad } from './chunk-C4VOKUKQ.js';
2
- export { etherToGwei, etherToWei, gweiToEther, weiToEther } from './chunk-UXC5R4JE.js';
1
+ export { arrayify, computeAddress, computePublicKey, concat, hashMessage, hexConcat, hexDataLength, hexDataSlice, hexStripZeros, hexValue, hexZeroPad, hexlify, isAddress, isBytes, isBytesLike, isHexString, keccak256, pack, solidityKeccak256, splitSignature, stripZeros, toChecksumAddress, toUtf8Bytes, zeroPad } from './chunk-CLIQ4S3P.js';
2
+ export { etherToGwei, etherToWei, gweiToEther, weiToEther } from './chunk-GFWRB7PT.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "essential-eth",
3
3
  "description": "Ultralight JS for Ethereum",
4
- "version": "0.13.0",
4
+ "version": "1.0.0",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "types": "./dist/index.d.ts",
28
28
  "engines": {
29
- "node": ">=18"
29
+ "node": ">=16"
30
30
  },
31
31
  "files": [
32
32
  "dist/"
@@ -64,7 +64,7 @@
64
64
  "bn.js": "^5.2.1",
65
65
  "dotenv": "^16.0.0",
66
66
  "eslint": "^8.16.0",
67
- "eslint-plugin-jsdoc": "^38.0.2",
67
+ "eslint-plugin-jsdoc": "^47.0.2",
68
68
  "eslint-plugin-vitest": "^0.1.5",
69
69
  "husky": "^7.0.4",
70
70
  "lint-staged": "^13.2.1",
@@ -72,7 +72,8 @@
72
72
  "perf_hooks": "^0.0.1",
73
73
  "prettier": "^3.2.5",
74
74
  "prettier-plugin-organize-imports": "^3.2.4",
75
- "tsup": "^8.5.1",
75
+ "tsup": "^7.2.0",
76
+ "vite": "^4.5.0",
76
77
  "typedoc": "^0.24.5",
77
78
  "typescript": "^4.9.4",
78
79
  "vitest": "^0.34.6",
@@ -81,8 +82,6 @@
81
82
  "dependencies": {
82
83
  "@noble/hashes": "^2.0.1",
83
84
  "@noble/secp256k1": "^1.5.5",
84
- "@types/big.js": "^6.1.6",
85
- "big.js": "^6.2.1",
86
85
  "ethers": "^5.7.2",
87
86
  "isomorphic-unfetch": "^3.1.0",
88
87
  "sha3": "^2.1.4"