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.cjs CHANGED
@@ -28,20 +28,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  AlchemyProvider: () => AlchemyProvider,
34
34
  BaseContract: () => BaseContract,
35
35
  Contract: () => Contract,
36
36
  FallthroughProvider: () => FallthroughProvider,
37
37
  JsonRpcProvider: () => JsonRpcProvider,
38
- TinyBig: () => TinyBig,
39
38
  arrayify: () => arrayify,
40
39
  computeAddress: () => computeAddress,
41
40
  computePublicKey: () => computePublicKey,
42
41
  concat: () => concat,
42
+ decodeBytes32String: () => decodeBytes32String,
43
+ decodeEventLog: () => decodeEventLog,
44
+ decodeFunctionResult: () => decodeFunctionResult,
45
+ encodeBytes32String: () => encodeBytes32String,
46
+ encodeFunctionData: () => encodeFunctionData,
43
47
  etherToGwei: () => etherToGwei,
44
48
  etherToWei: () => etherToWei,
49
+ formatUnits: () => formatUnits,
50
+ getAddress: () => getAddress,
51
+ getEventSignature: () => getEventSignature,
52
+ getEventTopic: () => getEventTopic,
45
53
  gweiToEther: () => gweiToEther,
46
54
  hashMessage: () => hashMessage,
47
55
  hexConcat: () => hexConcat,
@@ -51,191 +59,31 @@ __export(index_exports, {
51
59
  hexValue: () => hexValue,
52
60
  hexZeroPad: () => hexZeroPad,
53
61
  hexlify: () => hexlify,
62
+ id: () => id,
54
63
  isAddress: () => isAddress,
55
64
  isBytes: () => isBytes,
56
65
  isBytesLike: () => isBytesLike,
57
66
  isHexString: () => isHexString,
58
67
  jsonRpcProvider: () => jsonRpcProvider,
59
68
  keccak256: () => keccak256,
69
+ namehash: () => namehash,
60
70
  pack: () => pack,
71
+ parseUnits: () => parseUnits,
61
72
  solidityKeccak256: () => solidityKeccak256,
62
73
  splitSignature: () => splitSignature,
63
74
  stripZeros: () => stripZeros,
64
- tinyBig: () => tinyBig,
65
75
  toChecksumAddress: () => toChecksumAddress,
66
76
  toUtf8Bytes: () => toUtf8Bytes,
77
+ toUtf8String: () => toUtf8String,
67
78
  weiToEther: () => weiToEther,
68
79
  zeroPad: () => zeroPad
69
80
  });
70
- module.exports = __toCommonJS(index_exports);
81
+ module.exports = __toCommonJS(src_exports);
71
82
 
72
83
  // src/classes/utils/encode-decode-transaction.ts
73
84
  var import_sha32 = require("@noble/hashes/sha3.js");
74
85
  var import_utils2 = require("@noble/hashes/utils.js");
75
86
 
76
- // src/shared/tiny-big/tiny-big.ts
77
- var import_big = __toESM(require("big.js"), 1);
78
-
79
- // src/classes/utils/hex-to-decimal.ts
80
- function hexToDecimal(hex) {
81
- return BigInt(hex).toString();
82
- }
83
-
84
- // src/shared/tiny-big/helpers.ts
85
- function stripTrailingZeroes(numberString) {
86
- const isNegative = numberString.startsWith("-");
87
- numberString = numberString.replace("-", "");
88
- numberString = numberString.replace(
89
- /\.0*$/g,
90
- ""
91
- );
92
- numberString = numberString.replace(/^0+/, "");
93
- if (numberString.includes(".")) {
94
- numberString = numberString.replace(/0+$/, "");
95
- }
96
- if (numberString.startsWith(".")) {
97
- numberString = `0${numberString}`;
98
- }
99
- return `${isNegative ? "-" : ""}${numberString}`;
100
- }
101
- function scientificStrToDecimalStr(scientificString) {
102
- if (!scientificString.match(
103
- /e/i
104
- /* lowercase and uppercase E */
105
- )) {
106
- return stripTrailingZeroes(scientificString);
107
- }
108
- let [base, power] = scientificString.split(
109
- /e/i
110
- );
111
- const isNegative = Number(base) < 0;
112
- base = base.replace("-", "");
113
- base = stripTrailingZeroes(base);
114
- const [wholeNumber, fraction = ""] = base.split(".");
115
- if (Number(power) === 0) {
116
- return `${isNegative ? "-" : ""}${stripTrailingZeroes(base)}`;
117
- } else {
118
- const includesDecimal = base.includes(".");
119
- if (!includesDecimal) {
120
- base = `${base}.`;
121
- }
122
- base = base.replace(".", "");
123
- const baseLength = base.length;
124
- let splitPaddedNumber;
125
- if (Number(power) < 0) {
126
- if (wholeNumber.length < Math.abs(Number(power))) {
127
- base = base.padStart(
128
- baseLength + Math.abs(Number(power)) - wholeNumber.length,
129
- "0"
130
- );
131
- }
132
- splitPaddedNumber = base.split("");
133
- if (wholeNumber.length < Math.abs(Number(power))) {
134
- splitPaddedNumber = [".", ...splitPaddedNumber];
135
- } else {
136
- splitPaddedNumber.splice(
137
- splitPaddedNumber.length - Math.abs(Number(power)),
138
- 0,
139
- "."
140
- );
141
- }
142
- } else {
143
- if (fraction.length < Math.abs(Number(power))) {
144
- base = base.padEnd(
145
- baseLength + Math.abs(Number(power)) - fraction.length,
146
- "0"
147
- );
148
- }
149
- splitPaddedNumber = base.split("");
150
- if (fraction.length > Math.abs(Number(power))) {
151
- splitPaddedNumber.splice(
152
- splitPaddedNumber.length - Math.abs(Number(power)),
153
- 0,
154
- "."
155
- );
156
- }
157
- }
158
- const toReturn = stripTrailingZeroes(splitPaddedNumber.join(""));
159
- return `${isNegative ? "-" : ""}${toReturn}`;
160
- }
161
- }
162
-
163
- // src/shared/tiny-big/tiny-big.ts
164
- var TinyBig = class extends import_big.default {
165
- constructor(value) {
166
- if (typeof value === "string" && value.startsWith("0x")) {
167
- value = hexToDecimal(value);
168
- }
169
- super(value);
170
- }
171
- /**
172
- * Used anytime you're passing in "value" to ethers or web3
173
- * For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
174
- *
175
- * @returns the TinyBig represented as a hex string
176
- * @example
177
- * ```javascript
178
- * tinyBig(293).toHexString();
179
- * // '0x125'
180
- * ```
181
- * @example
182
- * ```javascript
183
- * tinyBig(681365874).toHexString();
184
- * // '0x289cd172'
185
- */
186
- toHexString() {
187
- return `0x${BigInt(this.toString()).toString(16)}`;
188
- }
189
- toNumber() {
190
- return Number(scientificStrToDecimalStr(super.toString()));
191
- }
192
- toString() {
193
- if (this.toNumber() === 0) {
194
- return "0";
195
- }
196
- return scientificStrToDecimalStr(super.toString());
197
- }
198
- /**
199
- * Eithers pads or shortens a string to a specified length
200
- *
201
- * @param str the string to pad or chop
202
- * @param padChar the character to pad the string with
203
- * @param length the desired length of the given string
204
- * @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
205
- * @example
206
- * ```javascript
207
- * padAndChop('essential-eth', 'a', 8);
208
- * // 'tial-eth'
209
- * ```
210
- * @example
211
- * ```javascript
212
- * padAndChop('essential-eth', 'A', 20);
213
- * // 'AAAAAAAessential-eth'
214
- * ```
215
- */
216
- padAndChop = (str, padChar, length) => {
217
- return (Array(length).fill(padChar).join("") + str).slice(length * -1);
218
- };
219
- toTwos(bitCount) {
220
- let binaryStr;
221
- if (this.gte(0)) {
222
- const twosComp = this.toNumber().toString(2);
223
- binaryStr = this.padAndChop(twosComp, "0", bitCount || twosComp.length);
224
- } else {
225
- binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
226
- if (Number(binaryStr) < 0) {
227
- throw new Error("Cannot calculate twos complement");
228
- }
229
- }
230
- const binary = `0b${binaryStr}`;
231
- const decimal = Number(binary);
232
- return tinyBig(decimal);
233
- }
234
- };
235
- function tinyBig(value) {
236
- return new TinyBig(value);
237
- }
238
-
239
87
  // src/utils/to-checksum-address.ts
240
88
  var import_sha3 = require("@noble/hashes/sha3.js");
241
89
  var import_utils = require("@noble/hashes/utils.js");
@@ -272,6 +120,11 @@ function toChecksumAddress(address) {
272
120
  return checksumAddress;
273
121
  }
274
122
 
123
+ // src/classes/utils/hex-to-decimal.ts
124
+ function hexToDecimal(hex) {
125
+ return BigInt(hex).toString();
126
+ }
127
+
275
128
  // src/classes/utils/encode-decode-transaction.ts
276
129
  var hexFalse = "0".repeat(64);
277
130
  var hexTrue = "0".repeat(63) + "1";
@@ -284,7 +137,8 @@ function hexToUtf8(hex) {
284
137
  }
285
138
  for (; i < l; i += 2) {
286
139
  const code = parseInt(hex.substr(i, 2), 16);
287
- if (code === 0) continue;
140
+ if (code === 0)
141
+ continue;
288
142
  str += String.fromCharCode(code);
289
143
  }
290
144
  try {
@@ -398,7 +252,7 @@ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
398
252
  if (rawOutputs?.length === 1 && rawOutputs[0].type === "uint256[]") {
399
253
  const outputs2 = encodedOutputs.slice(2);
400
254
  return outputs2.map((output) => {
401
- return tinyBig(hexToDecimal(`0x${output}`));
255
+ return BigInt(hexToDecimal(`0x${output}`));
402
256
  });
403
257
  }
404
258
  const outputs = encodedOutputs.map((output, i) => {
@@ -408,14 +262,17 @@ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
408
262
  return output === hexTrue;
409
263
  case "address":
410
264
  return toChecksumAddress(`0x${output.slice(24)}`);
411
- case "uint256":
412
- case "uint120":
413
- return tinyBig(hexToDecimal(`0x${output}`));
414
265
  case "bytes32":
415
266
  return `0x${output}`;
416
267
  case "uint8":
417
268
  return Number(hexToDecimal(`0x${output}`));
418
269
  default:
270
+ if (outputType.startsWith("uint")) {
271
+ return BigInt(hexToDecimal(`0x${output}`));
272
+ }
273
+ if (outputType.startsWith("int")) {
274
+ return BigInt(hexToDecimal(`0x${output}`));
275
+ }
419
276
  throw new Error(
420
277
  `essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`
421
278
  );
@@ -497,7 +354,8 @@ function cleanTransaction(transaction) {
497
354
  ...transaction
498
355
  };
499
356
  Object.keys(transaction).forEach((key) => {
500
- if (!transaction[key]) return;
357
+ if (!transaction[key])
358
+ return;
501
359
  switch (key) {
502
360
  case "blockNumber":
503
361
  case "chainId":
@@ -518,7 +376,7 @@ function cleanTransaction(transaction) {
518
376
  case "maxFeePerGas":
519
377
  case "maxPriorityFeePerGas":
520
378
  case "nonce":
521
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
379
+ cleanedTransaction[key] = BigInt(hexToDecimal(transaction[key]));
522
380
  break;
523
381
  }
524
382
  });
@@ -529,7 +387,8 @@ function cleanTransaction(transaction) {
529
387
  function cleanBlock(block, returnTransactionObjects) {
530
388
  const cleanedBlock = { ...block };
531
389
  Object.keys(block).forEach((key) => {
532
- if (!block[key]) return;
390
+ if (!block[key])
391
+ return;
533
392
  switch (key) {
534
393
  case "difficulty":
535
394
  case "totalDifficulty":
@@ -538,7 +397,7 @@ function cleanBlock(block, returnTransactionObjects) {
538
397
  case "size":
539
398
  case "timestamp":
540
399
  case "baseFeePerGas":
541
- cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
400
+ cleanedBlock[key] = BigInt(hexToDecimal(block[key]));
542
401
  break;
543
402
  case "number":
544
403
  cleanedBlock[key] = Number(hexToDecimal(block[key]));
@@ -591,7 +450,8 @@ function cleanTransactionReceipt(transactionReceipt) {
591
450
  ...cleanedTransaction
592
451
  };
593
452
  Object.keys(transactionReceipt).forEach((key) => {
594
- if (!transactionReceipt[key]) return;
453
+ if (!transactionReceipt[key])
454
+ return;
595
455
  switch (key) {
596
456
  case "status":
597
457
  cleanedTransactionReceipt[key] = Number(
@@ -608,7 +468,7 @@ function cleanTransactionReceipt(transactionReceipt) {
608
468
  case "cumulativeGasUsed":
609
469
  case "effectiveGasPrice":
610
470
  case "gasUsed":
611
- cleanedTransactionReceipt[key] = tinyBig(
471
+ cleanedTransactionReceipt[key] = BigInt(
612
472
  hexToDecimal(transactionReceipt[key])
613
473
  );
614
474
  break;
@@ -661,11 +521,8 @@ function buildRPCPostBody(method, params) {
661
521
  };
662
522
  }
663
523
 
664
- // src/classes/utils/prepare-transaction.ts
665
- var import_big2 = __toESM(require("big.js"), 1);
666
-
667
524
  // src/logger/package-version.ts
668
- var version = "0.13.0";
525
+ var version = "1.0.0";
669
526
 
670
527
  // src/logger/logger.ts
671
528
  var Logger = class {
@@ -755,6 +612,15 @@ function arrayify(value, options) {
755
612
  }
756
613
  return new Uint8Array(result);
757
614
  }
615
+ if (typeof value === "bigint") {
616
+ const hex = value.toString(16).padStart(2, "0");
617
+ const padded = hex.length % 2 ? "0" + hex : hex;
618
+ const result = new Uint8Array(padded.length / 2);
619
+ for (let i = 0; i < result.length; i++) {
620
+ result[i] = parseInt(padded.substring(i * 2, i * 2 + 2), 16);
621
+ }
622
+ return result;
623
+ }
758
624
  if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
759
625
  value = "0x" + value;
760
626
  }
@@ -958,15 +824,13 @@ function prepareTransaction(transaction) {
958
824
  case "maxPriorityFeePerGas":
959
825
  case "value": {
960
826
  const value = transaction[key];
961
- if (value instanceof TinyBig) {
962
- preparedTransaction[key] = value.toHexString();
963
- } else if (value instanceof import_big2.default) {
964
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(
965
- 16
966
- )}`;
967
- } else if (typeof transaction[key] === "number")
968
- preparedTransaction[key] = "0x" + transaction[key].toString(16);
969
- else preparedTransaction[key] = transaction[key].toString();
827
+ if (typeof value === "bigint") {
828
+ preparedTransaction[key] = "0x" + value.toString(16);
829
+ } else if (typeof value === "number") {
830
+ preparedTransaction[key] = "0x" + value.toString(16);
831
+ } else {
832
+ preparedTransaction[key] = value.toString();
833
+ }
970
834
  break;
971
835
  }
972
836
  case "data":
@@ -978,6 +842,42 @@ function prepareTransaction(transaction) {
978
842
  return preparedTransaction;
979
843
  }
980
844
 
845
+ // src/utils/keccak256.ts
846
+ var import_sha33 = require("@noble/hashes/sha3.js");
847
+ var import_utils3 = require("@noble/hashes/utils.js");
848
+ function keccak256(data) {
849
+ let bytes;
850
+ if (typeof data === "string") {
851
+ const hex = data.replace(/^0x/, "");
852
+ bytes = new Uint8Array(hex.length / 2);
853
+ for (let i = 0; i < bytes.length; i++) {
854
+ bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
855
+ }
856
+ } else {
857
+ bytes = new Uint8Array(data);
858
+ }
859
+ return "0x" + (0, import_utils3.bytesToHex)((0, import_sha33.keccak_256)(bytes));
860
+ }
861
+
862
+ // src/utils/to-utf8-bytes.ts
863
+ function toUtf8Bytes(data) {
864
+ return new TextEncoder().encode(data);
865
+ }
866
+
867
+ // src/utils/namehash.ts
868
+ function namehash(name) {
869
+ let node = "0x0000000000000000000000000000000000000000000000000000000000000000";
870
+ if (name === "") {
871
+ return node;
872
+ }
873
+ const labels = name.split(".");
874
+ for (let i = labels.length - 1; i >= 0; i--) {
875
+ const labelHash = keccak256(toUtf8Bytes(labels[i]));
876
+ node = keccak256("0x" + node.slice(2) + labelHash.slice(2));
877
+ }
878
+ return node;
879
+ }
880
+
981
881
  // src/providers/utils/chains-info.ts
982
882
  var chains_info_default = {
983
883
  "1": [
@@ -1049,7 +949,7 @@ var chains_info_default = {
1049
949
 
1050
950
  // src/providers/BaseProvider.ts
1051
951
  function prepBlockTag(blockTag) {
1052
- return typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag;
952
+ return typeof blockTag === "number" ? "0x" + blockTag.toString(16) : blockTag;
1053
953
  }
1054
954
  var BaseProvider = class {
1055
955
  /**
@@ -1075,7 +975,6 @@ var BaseProvider = class {
1075
975
  *
1076
976
  * * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
1077
977
  * * [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`
1078
- *
1079
978
  * @returns information about the network this provider is currently connected to
1080
979
  * @example
1081
980
  * ```javascript
@@ -1106,7 +1005,6 @@ var BaseProvider = class {
1106
1005
  *
1107
1006
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
1108
1007
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
1109
- *
1110
1008
  * @returns the number of the most recently mined block
1111
1009
  * @example
1112
1010
  * ```javascript
@@ -1125,7 +1023,6 @@ var BaseProvider = class {
1125
1023
  *
1126
1024
  * * [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
1127
1025
  * * [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
1128
- *
1129
1026
  * @param transactionHash the hash of the transaction to get information about
1130
1027
  * @returns information about the specified transaction
1131
1028
  * @example
@@ -1137,20 +1034,20 @@ var BaseProvider = class {
1137
1034
  * // blockNumber: 14578286,
1138
1035
  * // chainId: 1,
1139
1036
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
1140
- * // gas: { TinyBig: 112163 },
1141
- * // gasPrice: { TinyBig: 48592426858 },
1037
+ * // gas: 112163n,
1038
+ * // gasPrice: 48592426858n,
1142
1039
  * // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
1143
1040
  * // input: "0x83259f17000000000000000000000000000000000000000000...",
1144
- * // maxFeePerGas: { TinyBig: 67681261618 },
1145
- * // maxPriorityFeePerGas: { TinyBig: 1500000000 },
1146
- * // nonce: { TinyBig: 129 },
1041
+ * // maxFeePerGas: 67681261618n,
1042
+ * // maxPriorityFeePerGas: 1500000000n,
1043
+ * // nonce: 129n,
1147
1044
  * // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
1148
1045
  * // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
1149
1046
  * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
1150
1047
  * // transactionIndex: 29,
1151
1048
  * // type: 2,
1152
1049
  * // v: 0,
1153
- * // value: { TinyBig: 0 },
1050
+ * // value: 0n,
1154
1051
  * // confirmations: 298140,
1155
1052
  * // }
1156
1053
  * ```
@@ -1171,7 +1068,6 @@ var BaseProvider = class {
1171
1068
  *
1172
1069
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
1173
1070
  * * [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
1174
- *
1175
1071
  * @param transactionHash the hash of the transaction to get information about
1176
1072
  * @returns information about the specified transaction that has already been mined
1177
1073
  * @example
@@ -1181,10 +1077,10 @@ var BaseProvider = class {
1181
1077
  * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
1182
1078
  * // blockNumber: 14578286,
1183
1079
  * // contractAddress: null,
1184
- * // cumulativeGasUsed: { TinyBig: 3067973 },
1185
- * // effectiveGasPrice: { TinyBig: 48592426858 },
1080
+ * // cumulativeGasUsed: 3067973n,
1081
+ * // effectiveGasPrice: 48592426858n,
1186
1082
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
1187
- * // gasUsed: { TinyBig: 112163 },
1083
+ * // gasUsed: 112163n,
1188
1084
  * // logs: [
1189
1085
  * // {
1190
1086
  * // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
@@ -1242,7 +1138,6 @@ var BaseProvider = class {
1242
1138
  *
1243
1139
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
1244
1140
  * * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
1245
- *
1246
1141
  * @param address the address to count number of sent transactions
1247
1142
  * @param blockTag the block to count transactions up to, inclusive
1248
1143
  * @returns the number of transactions sent by the specified address
@@ -1274,7 +1169,6 @@ var BaseProvider = class {
1274
1169
  *
1275
1170
  * * [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`]
1276
1171
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
1277
- *
1278
1172
  * @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
1279
1173
  * @param returnTransactionObjects Whether to also return data about the transactions on the block.
1280
1174
  * @returns A BlockResponse object with information about the specified block
@@ -1282,11 +1176,11 @@ var BaseProvider = class {
1282
1176
  * ```javascript
1283
1177
  * await provider.getBlock(14879862);
1284
1178
  * // {
1285
- * // baseFeePerGas: { TinyBig: 39095728776 },
1286
- * // difficulty: { TinyBig: 14321294455359973 },
1179
+ * // baseFeePerGas: 39095728776n,
1180
+ * // difficulty: 14321294455359973n,
1287
1181
  * // extraData: "0x486976656f6e2073672d6865617679",
1288
- * // gasLimit: { TinyBig: 29970620 },
1289
- * // gasUsed: { TinyBig: 20951384 },
1182
+ * // gasLimit: 29970620n,
1183
+ * // gasUsed: 20951384n,
1290
1184
  * // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
1291
1185
  * // logsBloom:
1292
1186
  * // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
@@ -1297,10 +1191,10 @@ var BaseProvider = class {
1297
1191
  * // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
1298
1192
  * // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
1299
1193
  * // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
1300
- * // size: { TinyBig: 134483 },
1194
+ * // size: 134483n,
1301
1195
  * // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
1302
- * // timestamp: { TinyBig: 1654016186 },
1303
- * // totalDifficulty: { TinyBig: 50478104614257705213748 },
1196
+ * // timestamp: 1654016186n,
1197
+ * // totalDifficulty: 50478104614257705213748n,
1304
1198
  * // transactions: [
1305
1199
  * // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
1306
1200
  * // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
@@ -1331,8 +1225,7 @@ var BaseProvider = class {
1331
1225
  * Gives an estimate of the current gas price in wei.
1332
1226
  *
1333
1227
  * * [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)
1334
- * * [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
1335
- *
1228
+ * * [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
1336
1229
  * @returns an estimate of the current gas price in wei
1337
1230
  * @example
1338
1231
  * ```javascript
@@ -1344,14 +1237,13 @@ var BaseProvider = class {
1344
1237
  const hexGasPrice = await this.post(
1345
1238
  buildRPCPostBody("eth_gasPrice", [])
1346
1239
  );
1347
- return tinyBig(hexToDecimal(hexGasPrice));
1240
+ return BigInt(hexToDecimal(hexGasPrice));
1348
1241
  }
1349
1242
  /**
1350
1243
  * Returns the balance of the account in wei.
1351
1244
  *
1352
1245
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
1353
- * * [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
1354
- *
1246
+ * * [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
1355
1247
  * @param address the address to check the balance of
1356
1248
  * @param blockTag the block to check the specified address' balance on
1357
1249
  * @returns the balance of the network's native token for the specified address on the specified block
@@ -1366,14 +1258,13 @@ var BaseProvider = class {
1366
1258
  const hexBalance = await this.post(
1367
1259
  buildRPCPostBody("eth_getBalance", [address, blockTag])
1368
1260
  );
1369
- return tinyBig(hexToDecimal(hexBalance));
1261
+ return BigInt(hexToDecimal(hexBalance));
1370
1262
  }
1371
1263
  /**
1372
1264
  * Gets the code of a contract on a specified block.
1373
1265
  *
1374
1266
  * * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
1375
1267
  * * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
1376
- *
1377
1268
  * @param address the contract address to get the contract code from
1378
1269
  * @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
1379
1270
  * @returns the contract creation code for the specified address at the specified block height
@@ -1396,7 +1287,6 @@ var BaseProvider = class {
1396
1287
  *
1397
1288
  * * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
1398
1289
  * * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
1399
- *
1400
1290
  * @param transaction the transaction to check the estimated gas cost for
1401
1291
  * @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
1402
1292
  * @example
@@ -1407,7 +1297,7 @@ var BaseProvider = class {
1407
1297
  * data: "0xd0e30db0",
1408
1298
  * value: etherToWei('1.0').toHexString(),
1409
1299
  * });
1410
- * // { TinyBig: "27938" }
1300
+ * // 27938n
1411
1301
  * ```
1412
1302
  */
1413
1303
  async estimateGas(transaction) {
@@ -1415,7 +1305,7 @@ var BaseProvider = class {
1415
1305
  const gasUsed = await this.post(
1416
1306
  buildRPCPostBody("eth_estimateGas", [rpcTransaction])
1417
1307
  );
1418
- return tinyBig(hexToDecimal(gasUsed));
1308
+ return BigInt(hexToDecimal(gasUsed));
1419
1309
  }
1420
1310
  /**
1421
1311
  * Returns the current recommended FeeData to use in a transaction.
@@ -1423,16 +1313,15 @@ var BaseProvider = class {
1423
1313
  * 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.
1424
1314
  *
1425
1315
  * * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
1426
- *
1427
1316
  * @returns an object with gas estimates for the network currently
1428
1317
  * @example
1429
1318
  * ```javascript
1430
1319
  * await provider.getFeeData();
1431
1320
  * // {
1432
- * // gasPrice: { TinyBig: "14184772639" },
1433
- * // lastBaseFeePerGas: { TinyBig: "14038523098" },
1434
- * // maxFeePerGas: { TinyBig: "29577046196" },
1435
- * // maxPriorityFeePerGas: { TinyBig: "1500000000" }
1321
+ * // gasPrice: 14184772639n,
1322
+ * // lastBaseFeePerGas: 14038523098n,
1323
+ * // maxFeePerGas: 29577046196n,
1324
+ * // maxPriorityFeePerGas: 1500000000n
1436
1325
  * // }
1437
1326
  * ```
1438
1327
  */
@@ -1444,10 +1333,8 @@ var BaseProvider = class {
1444
1333
  let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
1445
1334
  if (block && block.baseFeePerGas) {
1446
1335
  lastBaseFeePerGas = block.baseFeePerGas;
1447
- maxPriorityFeePerGas = tinyBig("1500000000");
1448
- maxFeePerGas = tinyBig(
1449
- block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas)
1450
- );
1336
+ maxPriorityFeePerGas = BigInt("1500000000");
1337
+ maxFeePerGas = block.baseFeePerGas * 2n + maxPriorityFeePerGas;
1451
1338
  }
1452
1339
  return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
1453
1340
  }
@@ -1457,7 +1344,6 @@ var BaseProvider = class {
1457
1344
  *
1458
1345
  * * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
1459
1346
  * * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
1460
- *
1461
1347
  * @param filter parameters to filter the logs by
1462
1348
  * @returns an array of logs matching the specified filter
1463
1349
  * @example
@@ -1509,7 +1395,6 @@ var BaseProvider = class {
1509
1395
  *
1510
1396
  * * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
1511
1397
  * * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
1512
- *
1513
1398
  * @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
1514
1399
  * @param blockTag the block to execute this transaction on
1515
1400
  * @returns the result of executing the transaction on the specified block
@@ -1546,6 +1431,61 @@ var BaseProvider = class {
1546
1431
  );
1547
1432
  return transactionRes;
1548
1433
  }
1434
+ /**
1435
+ * Resolves an ENS name to an Ethereum address.
1436
+ *
1437
+ * Performs the full ENS resolution process:
1438
+ * 1. Computes the namehash of the ENS name
1439
+ * 2. Queries the ENS Registry for the resolver contract
1440
+ * 3. Queries the resolver for the address
1441
+ *
1442
+ * * [Identical](/docs/api#isd) to [`ethers.provider.resolveName`](https://docs.ethers.io/v5/api/providers/provider/#Provider-resolveName) in ethers.js
1443
+ * @param name the ENS name to resolve (e.g. 'vitalik.eth')
1444
+ * @returns the Ethereum address the name resolves to, or null if not found
1445
+ * @example
1446
+ * ```javascript
1447
+ * await provider.resolveName('vitalik.eth');
1448
+ * // '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
1449
+ * ```
1450
+ * @example
1451
+ * ```javascript
1452
+ * await provider.resolveName('thisshouldnotexist12345.eth');
1453
+ * // null
1454
+ * ```
1455
+ */
1456
+ async resolveName(name) {
1457
+ const ENS_REGISTRY = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
1458
+ const RESOLVER_SELECTOR = "0x0178b8bf";
1459
+ const ADDR_SELECTOR = "0x3b3b57de";
1460
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
1461
+ const node = namehash(name);
1462
+ const nodeWithoutPrefix = node.slice(2);
1463
+ const resolverData = RESOLVER_SELECTOR + nodeWithoutPrefix;
1464
+ const resolverResult = await this.call({
1465
+ to: ENS_REGISTRY,
1466
+ data: resolverData
1467
+ });
1468
+ if (!resolverResult || resolverResult === ZERO_ADDRESS) {
1469
+ return null;
1470
+ }
1471
+ const resolverAddress = "0x" + resolverResult.slice(26);
1472
+ if (resolverAddress === "0x0000000000000000000000000000000000000000" || resolverAddress === "0x" + "0".repeat(resolverResult.length - 2)) {
1473
+ return null;
1474
+ }
1475
+ const addrData = ADDR_SELECTOR + nodeWithoutPrefix;
1476
+ const addrResult = await this.call({
1477
+ to: resolverAddress,
1478
+ data: addrData
1479
+ });
1480
+ if (!addrResult || addrResult === ZERO_ADDRESS) {
1481
+ return null;
1482
+ }
1483
+ const rawAddress = "0x" + addrResult.slice(26);
1484
+ if (rawAddress === "0x0000000000000000000000000000000000000000") {
1485
+ return null;
1486
+ }
1487
+ return toChecksumAddress(rawAddress);
1488
+ }
1549
1489
  };
1550
1490
 
1551
1491
  // src/providers/JsonRpcProvider.ts
@@ -1647,6 +1587,51 @@ var FallthroughProvider = class extends BaseProvider {
1647
1587
  };
1648
1588
  };
1649
1589
 
1590
+ // src/utils/abi-encode-decode.ts
1591
+ function findFunctionABI(abi, functionName) {
1592
+ const entry = abi.find(
1593
+ (item) => item.type === "function" && item.name === functionName
1594
+ );
1595
+ if (!entry) {
1596
+ throw new Error(`Function "${functionName}" not found in ABI`);
1597
+ }
1598
+ return entry;
1599
+ }
1600
+ function encodeFunctionData(abi, functionName, args = []) {
1601
+ const abiEntry = findFunctionABI(abi, functionName);
1602
+ return encodeData(abiEntry, args);
1603
+ }
1604
+ function decodeFunctionResult(abi, functionName, data) {
1605
+ const abiEntry = findFunctionABI(abi, functionName);
1606
+ return decodeRPCResponse(abiEntry, data);
1607
+ }
1608
+
1609
+ // src/utils/to-utf8-string.ts
1610
+ function toUtf8String(bytes) {
1611
+ return new TextDecoder().decode(arrayify(bytes));
1612
+ }
1613
+
1614
+ // src/utils/bytes32-string.ts
1615
+ function encodeBytes32String(text) {
1616
+ const bytes = toUtf8Bytes(text);
1617
+ if (bytes.length > 31) {
1618
+ throw new Error("bytes32 string must be less than 32 bytes");
1619
+ }
1620
+ const padded = new Uint8Array(32);
1621
+ padded.set(bytes);
1622
+ return hexlify(padded);
1623
+ }
1624
+ function decodeBytes32String(bytes32) {
1625
+ let hex = bytes32;
1626
+ if (hex.startsWith("0x") || hex.startsWith("0X")) {
1627
+ hex = hex.slice(2);
1628
+ }
1629
+ hex = hex.replace(/(00)+$/, "");
1630
+ if (hex.length === 0)
1631
+ return "";
1632
+ return toUtf8String("0x" + hex);
1633
+ }
1634
+
1650
1635
  // src/utils/compute-public-key.ts
1651
1636
  var import_secp256k1 = require("@noble/secp256k1");
1652
1637
  function computePublicKey(privKey) {
@@ -1654,23 +1639,6 @@ function computePublicKey(privKey) {
1654
1639
  return "0x" + import_secp256k1.Point.fromPrivateKey(privKey).toHex();
1655
1640
  }
1656
1641
 
1657
- // src/utils/keccak256.ts
1658
- var import_sha33 = require("@noble/hashes/sha3.js");
1659
- var import_utils3 = require("@noble/hashes/utils.js");
1660
- function keccak256(data) {
1661
- let bytes;
1662
- if (typeof data === "string") {
1663
- const hex = data.replace(/^0x/, "");
1664
- bytes = new Uint8Array(hex.length / 2);
1665
- for (let i = 0; i < bytes.length; i++) {
1666
- bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
1667
- }
1668
- } else {
1669
- bytes = new Uint8Array(data);
1670
- }
1671
- return "0x" + (0, import_utils3.bytesToHex)((0, import_sha33.keccak_256)(bytes));
1672
- }
1673
-
1674
1642
  // src/utils/compute-address.ts
1675
1643
  function computeAddress(key) {
1676
1644
  if (!key.startsWith("0x04") && !key.startsWith("0x03") && !key.startsWith("0x02")) {
@@ -1679,30 +1647,174 @@ function computeAddress(key) {
1679
1647
  return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
1680
1648
  }
1681
1649
 
1650
+ // src/utils/decode-event-log.ts
1651
+ function computeEventTopic(event) {
1652
+ const types = event.inputs.map((input) => input.type);
1653
+ const signature = `${event.name}(${types.join(",")})`;
1654
+ return keccak256(toUtf8Bytes(signature));
1655
+ }
1656
+ function decodeValue(hexChunk, type) {
1657
+ if (type === "bool") {
1658
+ return hexChunk[hexChunk.length - 1] === "1";
1659
+ }
1660
+ if (type === "address") {
1661
+ return toChecksumAddress(`0x${hexChunk.slice(24)}`);
1662
+ }
1663
+ if (type === "bytes32") {
1664
+ return `0x${hexChunk}`;
1665
+ }
1666
+ if (type === "uint8") {
1667
+ return Number(BigInt(`0x${hexChunk}`));
1668
+ }
1669
+ if (type.startsWith("uint")) {
1670
+ return BigInt(`0x${hexChunk}`);
1671
+ }
1672
+ if (type.startsWith("int")) {
1673
+ return BigInt(`0x${hexChunk}`);
1674
+ }
1675
+ throw new Error(
1676
+ `essential-eth does not yet support decoding "${type}" in event logs. Make a PR today!`
1677
+ );
1678
+ }
1679
+ function decodeEventLog(abi, log) {
1680
+ const topic0 = log.topics[0];
1681
+ const events = abi.filter((entry) => entry.type === "event");
1682
+ let matchedEvent;
1683
+ for (const event of events) {
1684
+ const hash = computeEventTopic(event);
1685
+ if (hash === topic0) {
1686
+ matchedEvent = event;
1687
+ break;
1688
+ }
1689
+ }
1690
+ if (!matchedEvent) {
1691
+ throw new Error(`No matching event found in ABI for topic0: ${topic0}`);
1692
+ }
1693
+ const args = {};
1694
+ let topicIndex = 1;
1695
+ let dataOffset = 0;
1696
+ const rawData = log.data.startsWith("0x") ? log.data.slice(2) : log.data;
1697
+ for (const input of matchedEvent.inputs) {
1698
+ if (input.indexed) {
1699
+ const topicHex = log.topics[topicIndex];
1700
+ const hexChunk = topicHex.startsWith("0x") ? topicHex.slice(2) : topicHex;
1701
+ args[input.name] = decodeValue(hexChunk, input.type);
1702
+ topicIndex++;
1703
+ } else {
1704
+ const hexChunk = rawData.slice(dataOffset, dataOffset + 64);
1705
+ args[input.name] = decodeValue(hexChunk, input.type);
1706
+ dataOffset += 64;
1707
+ }
1708
+ }
1709
+ return {
1710
+ eventName: matchedEvent.name,
1711
+ args
1712
+ };
1713
+ }
1714
+
1715
+ // src/utils/fixed-point.ts
1716
+ function parseFixed(value, decimals) {
1717
+ let negative = false;
1718
+ if (value.startsWith("-")) {
1719
+ negative = true;
1720
+ value = value.substring(1);
1721
+ }
1722
+ if (value === "") {
1723
+ throw new Error("invalid decimal value");
1724
+ }
1725
+ const parts = value.split(".");
1726
+ if (parts.length > 2) {
1727
+ throw new Error("too many decimal points");
1728
+ }
1729
+ const integer = parts[0] || "0";
1730
+ let fraction = parts[1] || "";
1731
+ if (fraction.length > decimals) {
1732
+ const extra = fraction.substring(decimals);
1733
+ if (extra.match(/[^0]/)) {
1734
+ throw new Error("fractional component exceeds decimals");
1735
+ }
1736
+ fraction = fraction.substring(0, decimals);
1737
+ }
1738
+ while (fraction.length < decimals) {
1739
+ fraction += "0";
1740
+ }
1741
+ const result = BigInt(integer + fraction);
1742
+ return negative ? -result : result;
1743
+ }
1744
+ function formatFixed(value, decimals) {
1745
+ let negative = "";
1746
+ if (value < 0n) {
1747
+ negative = "-";
1748
+ value = -value;
1749
+ }
1750
+ let str = value.toString();
1751
+ while (str.length <= decimals) {
1752
+ str = "0" + str;
1753
+ }
1754
+ const integerPart = str.substring(0, str.length - decimals);
1755
+ const fractionPart = str.substring(str.length - decimals);
1756
+ const trimmedFraction = fractionPart.replace(/0+$/, "");
1757
+ if (trimmedFraction) {
1758
+ return `${negative}${integerPart}.${trimmedFraction}`;
1759
+ }
1760
+ return `${negative}${integerPart}`;
1761
+ }
1762
+ function toBigInt(value) {
1763
+ if (typeof value === "bigint")
1764
+ return value;
1765
+ if (typeof value === "string") {
1766
+ if (value.startsWith("0x")) {
1767
+ return BigInt(value);
1768
+ }
1769
+ if (value.includes(".")) {
1770
+ return BigInt(value.split(".")[0] || "0");
1771
+ }
1772
+ return BigInt(value);
1773
+ }
1774
+ return BigInt(value);
1775
+ }
1776
+
1682
1777
  // src/utils/ether-to-gwei.ts
1683
1778
  function etherToGwei(etherQuantity) {
1684
- validateType(etherQuantity, ["string", "number", "object"]);
1685
- const result = tinyBig(etherQuantity).times("1000000000");
1686
- return tinyBig(result);
1779
+ validateType(etherQuantity, ["string", "number", "bigint"]);
1780
+ return parseFixed(String(etherQuantity), 9);
1687
1781
  }
1688
1782
 
1689
1783
  // src/utils/ether-to-wei.ts
1690
1784
  function etherToWei(etherQuantity) {
1691
- validateType(etherQuantity, ["string", "number", "object"]);
1692
- const result = tinyBig(etherQuantity).times("1000000000000000000");
1693
- return tinyBig(result);
1785
+ validateType(etherQuantity, ["string", "number", "bigint"]);
1786
+ return parseFixed(String(etherQuantity), 18);
1694
1787
  }
1695
1788
 
1696
- // src/utils/gwei-to-ether.ts
1697
- function gweiToEther(gweiQuantity) {
1698
- validateType(gweiQuantity, ["string", "number", "object"]);
1699
- const result = tinyBig(gweiQuantity).div("1000000000");
1700
- return tinyBig(result);
1789
+ // src/utils/event-topic.ts
1790
+ function getEventTopic(eventSignature) {
1791
+ return keccak256(toUtf8Bytes(eventSignature));
1792
+ }
1793
+ function getEventSignature(abi, eventName) {
1794
+ const event = abi.find(
1795
+ (entry) => entry.type === "event" && entry.name === eventName
1796
+ );
1797
+ if (!event) {
1798
+ throw new Error(`Event "${eventName}" not found in ABI`);
1799
+ }
1800
+ const signature = `${event.name}(${event.inputs.map((input) => input.type).join(",")})`;
1801
+ return getEventTopic(signature);
1701
1802
  }
1702
1803
 
1703
- // src/utils/to-utf8-bytes.ts
1704
- function toUtf8Bytes(data) {
1705
- return new TextEncoder().encode(data);
1804
+ // src/utils/format-units.ts
1805
+ function formatUnits(value, decimals = 18) {
1806
+ return formatFixed(toBigInt(value), decimals);
1807
+ }
1808
+
1809
+ // src/utils/get-address.ts
1810
+ function getAddress(address) {
1811
+ return toChecksumAddress(address);
1812
+ }
1813
+
1814
+ // src/utils/gwei-to-ether.ts
1815
+ function gweiToEther(gweiQuantity) {
1816
+ validateType(gweiQuantity, ["string", "number", "bigint"]);
1817
+ return formatFixed(toBigInt(gweiQuantity), 9);
1706
1818
  }
1707
1819
 
1708
1820
  // src/utils/hash-message.ts
@@ -1720,6 +1832,11 @@ function hashMessage(message) {
1720
1832
  );
1721
1833
  }
1722
1834
 
1835
+ // src/utils/id.ts
1836
+ function id(text) {
1837
+ return keccak256(toUtf8Bytes(text));
1838
+ }
1839
+
1723
1840
  // src/utils/is-address.ts
1724
1841
  function isAddress(address) {
1725
1842
  validateType(address, ["string"]);
@@ -1731,6 +1848,11 @@ function isAddress(address) {
1731
1848
  }
1732
1849
  }
1733
1850
 
1851
+ // src/utils/parse-units.ts
1852
+ function parseUnits(value, decimals = 18) {
1853
+ return parseFixed(value, decimals);
1854
+ }
1855
+
1734
1856
  // src/utils/solidity-keccak256.ts
1735
1857
  var regexBytes = new RegExp("^bytes([0-9]+)$");
1736
1858
  var regexNumber = new RegExp("^(u?int)([0-9]*)$");
@@ -1762,7 +1884,11 @@ function _pack(type, value, isArray) {
1762
1884
  if (isArray) {
1763
1885
  size = 256;
1764
1886
  }
1765
- value = tinyBig(value).toTwos(size).toNumber();
1887
+ let bigVal = BigInt(value);
1888
+ if (bigVal < 0n) {
1889
+ bigVal = bigVal + (1n << BigInt(size));
1890
+ }
1891
+ value = Number(bigVal);
1766
1892
  const hexValue2 = hexlify(value);
1767
1893
  return zeroPad(hexValue2, size / 8);
1768
1894
  }
@@ -1976,17 +2102,8 @@ function splitSignature(signature) {
1976
2102
 
1977
2103
  // src/utils/wei-to-ether.ts
1978
2104
  function weiToEther(weiQuantity) {
1979
- validateType(weiQuantity, ["string", "number", "object"]);
1980
- try {
1981
- let _weiQuantity = weiQuantity;
1982
- if (typeof weiQuantity === "string" && weiQuantity.slice(0, 2) === "0x") {
1983
- _weiQuantity = BigInt(weiQuantity).toString();
1984
- }
1985
- const result = tinyBig(_weiQuantity).div("1000000000000000000");
1986
- return tinyBig(result);
1987
- } catch (error) {
1988
- throw error;
1989
- }
2105
+ validateType(weiQuantity, ["string", "number", "bigint"]);
2106
+ return formatFixed(toBigInt(weiQuantity), 18);
1990
2107
  }
1991
2108
  // Annotate the CommonJS export names for ESM import in node:
1992
2109
  0 && (module.exports = {
@@ -1995,13 +2112,21 @@ function weiToEther(weiQuantity) {
1995
2112
  Contract,
1996
2113
  FallthroughProvider,
1997
2114
  JsonRpcProvider,
1998
- TinyBig,
1999
2115
  arrayify,
2000
2116
  computeAddress,
2001
2117
  computePublicKey,
2002
2118
  concat,
2119
+ decodeBytes32String,
2120
+ decodeEventLog,
2121
+ decodeFunctionResult,
2122
+ encodeBytes32String,
2123
+ encodeFunctionData,
2003
2124
  etherToGwei,
2004
2125
  etherToWei,
2126
+ formatUnits,
2127
+ getAddress,
2128
+ getEventSignature,
2129
+ getEventTopic,
2005
2130
  gweiToEther,
2006
2131
  hashMessage,
2007
2132
  hexConcat,
@@ -2011,19 +2136,22 @@ function weiToEther(weiQuantity) {
2011
2136
  hexValue,
2012
2137
  hexZeroPad,
2013
2138
  hexlify,
2139
+ id,
2014
2140
  isAddress,
2015
2141
  isBytes,
2016
2142
  isBytesLike,
2017
2143
  isHexString,
2018
2144
  jsonRpcProvider,
2019
2145
  keccak256,
2146
+ namehash,
2020
2147
  pack,
2148
+ parseUnits,
2021
2149
  solidityKeccak256,
2022
2150
  splitSignature,
2023
2151
  stripZeros,
2024
- tinyBig,
2025
2152
  toChecksumAddress,
2026
2153
  toUtf8Bytes,
2154
+ toUtf8String,
2027
2155
  weiToEther,
2028
2156
  zeroPad
2029
2157
  });