essential-eth 0.11.2 → 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,192 +59,34 @@ __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
- var import_sha32 = require("sha3");
74
-
75
- // src/shared/tiny-big/tiny-big.ts
76
- var import_big = __toESM(require("big.js"), 1);
77
-
78
- // src/classes/utils/hex-to-decimal.ts
79
- function hexToDecimal(hex) {
80
- return BigInt(hex).toString();
81
- }
82
-
83
- // src/shared/tiny-big/helpers.ts
84
- function stripTrailingZeroes(numberString) {
85
- const isNegative = numberString.startsWith("-");
86
- numberString = numberString.replace("-", "");
87
- numberString = numberString.replace(
88
- /\.0*$/g,
89
- ""
90
- );
91
- numberString = numberString.replace(/^0+/, "");
92
- if (numberString.includes(".")) {
93
- numberString = numberString.replace(/0+$/, "");
94
- }
95
- if (numberString.startsWith(".")) {
96
- numberString = `0${numberString}`;
97
- }
98
- return `${isNegative ? "-" : ""}${numberString}`;
99
- }
100
- function scientificStrToDecimalStr(scientificString) {
101
- if (!scientificString.match(
102
- /e/i
103
- /* lowercase and uppercase E */
104
- )) {
105
- return stripTrailingZeroes(scientificString);
106
- }
107
- let [base, power] = scientificString.split(
108
- /e/i
109
- );
110
- const isNegative = Number(base) < 0;
111
- base = base.replace("-", "");
112
- base = stripTrailingZeroes(base);
113
- const [wholeNumber, fraction = ""] = base.split(".");
114
- if (Number(power) === 0) {
115
- return `${isNegative ? "-" : ""}${stripTrailingZeroes(base)}`;
116
- } else {
117
- const includesDecimal = base.includes(".");
118
- if (!includesDecimal) {
119
- base = `${base}.`;
120
- }
121
- base = base.replace(".", "");
122
- const baseLength = base.length;
123
- let splitPaddedNumber;
124
- if (Number(power) < 0) {
125
- if (wholeNumber.length < Math.abs(Number(power))) {
126
- base = base.padStart(
127
- baseLength + Math.abs(Number(power)) - wholeNumber.length,
128
- "0"
129
- );
130
- }
131
- splitPaddedNumber = base.split("");
132
- if (wholeNumber.length < Math.abs(Number(power))) {
133
- splitPaddedNumber = [".", ...splitPaddedNumber];
134
- } else {
135
- splitPaddedNumber.splice(
136
- splitPaddedNumber.length - Math.abs(Number(power)),
137
- 0,
138
- "."
139
- );
140
- }
141
- } else {
142
- if (fraction.length < Math.abs(Number(power))) {
143
- base = base.padEnd(
144
- baseLength + Math.abs(Number(power)) - fraction.length,
145
- "0"
146
- );
147
- }
148
- splitPaddedNumber = base.split("");
149
- if (fraction.length > Math.abs(Number(power))) {
150
- splitPaddedNumber.splice(
151
- splitPaddedNumber.length - Math.abs(Number(power)),
152
- 0,
153
- "."
154
- );
155
- }
156
- }
157
- const toReturn = stripTrailingZeroes(splitPaddedNumber.join(""));
158
- return `${isNegative ? "-" : ""}${toReturn}`;
159
- }
160
- }
161
-
162
- // src/shared/tiny-big/tiny-big.ts
163
- var TinyBig = class extends import_big.default {
164
- constructor(value) {
165
- if (typeof value === "string" && value.startsWith("0x")) {
166
- value = hexToDecimal(value);
167
- }
168
- super(value);
169
- }
170
- /**
171
- * Used anytime you're passing in "value" to ethers or web3
172
- * For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
173
- *
174
- * @returns the TinyBig represented as a hex string
175
- * @example
176
- * ```javascript
177
- * tinyBig(293).toHexString();
178
- * // '0x125'
179
- * ```
180
- * @example
181
- * ```javascript
182
- * tinyBig(681365874).toHexString();
183
- * // '0x289cd172'
184
- */
185
- toHexString() {
186
- return `0x${BigInt(this.toString()).toString(16)}`;
187
- }
188
- toNumber() {
189
- return Number(scientificStrToDecimalStr(super.toString()));
190
- }
191
- toString() {
192
- if (this.toNumber() === 0) {
193
- return "0";
194
- }
195
- return scientificStrToDecimalStr(super.toString());
196
- }
197
- /**
198
- * Eithers pads or shortens a string to a specified length
199
- *
200
- * @param str the string to pad or chop
201
- * @param padChar the character to pad the string with
202
- * @param length the desired length of the given string
203
- * @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
204
- * @example
205
- * ```javascript
206
- * padAndChop('essential-eth', 'a', 8);
207
- * // 'tial-eth'
208
- * ```
209
- * @example
210
- * ```javascript
211
- * padAndChop('essential-eth', 'A', 20);
212
- * // 'AAAAAAAessential-eth'
213
- * ```
214
- */
215
- padAndChop = (str, padChar, length) => {
216
- return (Array(length).fill(padChar).join("") + str).slice(length * -1);
217
- };
218
- toTwos(bitCount) {
219
- let binaryStr;
220
- if (this.gte(0)) {
221
- const twosComp = this.toNumber().toString(2);
222
- binaryStr = this.padAndChop(twosComp, "0", bitCount || twosComp.length);
223
- } else {
224
- binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
225
- if (Number(binaryStr) < 0) {
226
- throw new Error("Cannot calculate twos complement");
227
- }
228
- }
229
- const binary = `0b${binaryStr}`;
230
- const decimal = Number(binary);
231
- return tinyBig(decimal);
232
- }
233
- };
234
- function tinyBig(value) {
235
- return new TinyBig(value);
236
- }
84
+ var import_sha32 = require("@noble/hashes/sha3.js");
85
+ var import_utils2 = require("@noble/hashes/utils.js");
237
86
 
238
87
  // src/utils/to-checksum-address.ts
239
- var import_sha3 = require("sha3");
88
+ var import_sha3 = require("@noble/hashes/sha3.js");
89
+ var import_utils = require("@noble/hashes/utils.js");
240
90
 
241
91
  // src/shared/validate-type.ts
242
92
  var validateType = (value, allowedTypes) => {
@@ -254,8 +104,8 @@ function toChecksumAddress(address) {
254
104
  throw new Error(`Invalid Ethereum address "${address}"`);
255
105
  }
256
106
  const _address = address.toLowerCase().replace(/^0x/i, "");
257
- const keccak = new import_sha3.Keccak(256);
258
- const addressHash = keccak.update(_address).digest("hex").replace(/^0x/i, "");
107
+ const addressBytes = new TextEncoder().encode(_address);
108
+ const addressHash = (0, import_utils.bytesToHex)((0, import_sha3.keccak_256)(addressBytes));
259
109
  let checksumAddress = "0x";
260
110
  for (let i = 0; i < _address.length; i++) {
261
111
  if (parseInt(addressHash[i], 16) > 7) {
@@ -270,6 +120,11 @@ function toChecksumAddress(address) {
270
120
  return checksumAddress;
271
121
  }
272
122
 
123
+ // src/classes/utils/hex-to-decimal.ts
124
+ function hexToDecimal(hex) {
125
+ return BigInt(hex).toString();
126
+ }
127
+
273
128
  // src/classes/utils/encode-decode-transaction.ts
274
129
  var hexFalse = "0".repeat(64);
275
130
  var hexTrue = "0".repeat(63) + "1";
@@ -282,7 +137,8 @@ function hexToUtf8(hex) {
282
137
  }
283
138
  for (; i < l; i += 2) {
284
139
  const code = parseInt(hex.substr(i, 2), 16);
285
- if (code === 0) continue;
140
+ if (code === 0)
141
+ continue;
286
142
  str += String.fromCharCode(code);
287
143
  }
288
144
  try {
@@ -301,11 +157,12 @@ function expandType(type) {
301
157
  return type;
302
158
  }
303
159
  function encodeData(jsonABIArgument, args) {
304
- const hash = new import_sha32.Keccak(256);
305
160
  const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map(
306
161
  (input) => expandType(input.type)
307
162
  )})`;
308
- const functionHash = hash.update(functionString).digest("hex");
163
+ const functionHash = (0, import_utils2.bytesToHex)(
164
+ (0, import_sha32.keccak_256)(new TextEncoder().encode(functionString))
165
+ );
309
166
  const jsonABIInputsLength = jsonABIArgument.inputs.length;
310
167
  let shouldValidateInputLength = true;
311
168
  if (jsonABIArgument.inputs.find((input) => input.type.includes("["))) {
@@ -395,7 +252,7 @@ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
395
252
  if (rawOutputs?.length === 1 && rawOutputs[0].type === "uint256[]") {
396
253
  const outputs2 = encodedOutputs.slice(2);
397
254
  return outputs2.map((output) => {
398
- return tinyBig(hexToDecimal(`0x${output}`));
255
+ return BigInt(hexToDecimal(`0x${output}`));
399
256
  });
400
257
  }
401
258
  const outputs = encodedOutputs.map((output, i) => {
@@ -405,14 +262,17 @@ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
405
262
  return output === hexTrue;
406
263
  case "address":
407
264
  return toChecksumAddress(`0x${output.slice(24)}`);
408
- case "uint256":
409
- case "uint120":
410
- return tinyBig(hexToDecimal(`0x${output}`));
411
265
  case "bytes32":
412
266
  return `0x${output}`;
413
267
  case "uint8":
414
268
  return Number(hexToDecimal(`0x${output}`));
415
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
+ }
416
276
  throw new Error(
417
277
  `essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`
418
278
  );
@@ -494,7 +354,8 @@ function cleanTransaction(transaction) {
494
354
  ...transaction
495
355
  };
496
356
  Object.keys(transaction).forEach((key) => {
497
- if (!transaction[key]) return;
357
+ if (!transaction[key])
358
+ return;
498
359
  switch (key) {
499
360
  case "blockNumber":
500
361
  case "chainId":
@@ -515,7 +376,7 @@ function cleanTransaction(transaction) {
515
376
  case "maxFeePerGas":
516
377
  case "maxPriorityFeePerGas":
517
378
  case "nonce":
518
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
379
+ cleanedTransaction[key] = BigInt(hexToDecimal(transaction[key]));
519
380
  break;
520
381
  }
521
382
  });
@@ -526,7 +387,8 @@ function cleanTransaction(transaction) {
526
387
  function cleanBlock(block, returnTransactionObjects) {
527
388
  const cleanedBlock = { ...block };
528
389
  Object.keys(block).forEach((key) => {
529
- if (!block[key]) return;
390
+ if (!block[key])
391
+ return;
530
392
  switch (key) {
531
393
  case "difficulty":
532
394
  case "totalDifficulty":
@@ -535,7 +397,7 @@ function cleanBlock(block, returnTransactionObjects) {
535
397
  case "size":
536
398
  case "timestamp":
537
399
  case "baseFeePerGas":
538
- cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
400
+ cleanedBlock[key] = BigInt(hexToDecimal(block[key]));
539
401
  break;
540
402
  case "number":
541
403
  cleanedBlock[key] = Number(hexToDecimal(block[key]));
@@ -588,7 +450,8 @@ function cleanTransactionReceipt(transactionReceipt) {
588
450
  ...cleanedTransaction
589
451
  };
590
452
  Object.keys(transactionReceipt).forEach((key) => {
591
- if (!transactionReceipt[key]) return;
453
+ if (!transactionReceipt[key])
454
+ return;
592
455
  switch (key) {
593
456
  case "status":
594
457
  cleanedTransactionReceipt[key] = Number(
@@ -605,7 +468,7 @@ function cleanTransactionReceipt(transactionReceipt) {
605
468
  case "cumulativeGasUsed":
606
469
  case "effectiveGasPrice":
607
470
  case "gasUsed":
608
- cleanedTransactionReceipt[key] = tinyBig(
471
+ cleanedTransactionReceipt[key] = BigInt(
609
472
  hexToDecimal(transactionReceipt[key])
610
473
  );
611
474
  break;
@@ -658,11 +521,8 @@ function buildRPCPostBody(method, params) {
658
521
  };
659
522
  }
660
523
 
661
- // src/classes/utils/prepare-transaction.ts
662
- var import_big2 = __toESM(require("big.js"), 1);
663
-
664
524
  // src/logger/package-version.ts
665
- var version = "0.11.2";
525
+ var version = "1.0.0";
666
526
 
667
527
  // src/logger/logger.ts
668
528
  var Logger = class {
@@ -752,6 +612,15 @@ function arrayify(value, options) {
752
612
  }
753
613
  return new Uint8Array(result);
754
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
+ }
755
624
  if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
756
625
  value = "0x" + value;
757
626
  }
@@ -955,15 +824,13 @@ function prepareTransaction(transaction) {
955
824
  case "maxPriorityFeePerGas":
956
825
  case "value": {
957
826
  const value = transaction[key];
958
- if (value instanceof TinyBig) {
959
- preparedTransaction[key] = value.toHexString();
960
- } else if (value instanceof import_big2.default) {
961
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(
962
- 16
963
- )}`;
964
- } else if (typeof transaction[key] === "number")
965
- preparedTransaction[key] = "0x" + transaction[key].toString(16);
966
- 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
+ }
967
834
  break;
968
835
  }
969
836
  case "data":
@@ -975,6 +842,42 @@ function prepareTransaction(transaction) {
975
842
  return preparedTransaction;
976
843
  }
977
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
+
978
881
  // src/providers/utils/chains-info.ts
979
882
  var chains_info_default = {
980
883
  "1": [
@@ -1046,7 +949,7 @@ var chains_info_default = {
1046
949
 
1047
950
  // src/providers/BaseProvider.ts
1048
951
  function prepBlockTag(blockTag) {
1049
- return typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag;
952
+ return typeof blockTag === "number" ? "0x" + blockTag.toString(16) : blockTag;
1050
953
  }
1051
954
  var BaseProvider = class {
1052
955
  /**
@@ -1072,7 +975,6 @@ var BaseProvider = class {
1072
975
  *
1073
976
  * * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
1074
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`
1075
- *
1076
978
  * @returns information about the network this provider is currently connected to
1077
979
  * @example
1078
980
  * ```javascript
@@ -1103,7 +1005,6 @@ var BaseProvider = class {
1103
1005
  *
1104
1006
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
1105
1007
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
1106
- *
1107
1008
  * @returns the number of the most recently mined block
1108
1009
  * @example
1109
1010
  * ```javascript
@@ -1122,7 +1023,6 @@ var BaseProvider = class {
1122
1023
  *
1123
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
1124
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
1125
- *
1126
1026
  * @param transactionHash the hash of the transaction to get information about
1127
1027
  * @returns information about the specified transaction
1128
1028
  * @example
@@ -1134,20 +1034,20 @@ var BaseProvider = class {
1134
1034
  * // blockNumber: 14578286,
1135
1035
  * // chainId: 1,
1136
1036
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
1137
- * // gas: { TinyBig: 112163 },
1138
- * // gasPrice: { TinyBig: 48592426858 },
1037
+ * // gas: 112163n,
1038
+ * // gasPrice: 48592426858n,
1139
1039
  * // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
1140
1040
  * // input: "0x83259f17000000000000000000000000000000000000000000...",
1141
- * // maxFeePerGas: { TinyBig: 67681261618 },
1142
- * // maxPriorityFeePerGas: { TinyBig: 1500000000 },
1143
- * // nonce: { TinyBig: 129 },
1041
+ * // maxFeePerGas: 67681261618n,
1042
+ * // maxPriorityFeePerGas: 1500000000n,
1043
+ * // nonce: 129n,
1144
1044
  * // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
1145
1045
  * // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
1146
1046
  * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
1147
1047
  * // transactionIndex: 29,
1148
1048
  * // type: 2,
1149
1049
  * // v: 0,
1150
- * // value: { TinyBig: 0 },
1050
+ * // value: 0n,
1151
1051
  * // confirmations: 298140,
1152
1052
  * // }
1153
1053
  * ```
@@ -1168,7 +1068,6 @@ var BaseProvider = class {
1168
1068
  *
1169
1069
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
1170
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
1171
- *
1172
1071
  * @param transactionHash the hash of the transaction to get information about
1173
1072
  * @returns information about the specified transaction that has already been mined
1174
1073
  * @example
@@ -1178,10 +1077,10 @@ var BaseProvider = class {
1178
1077
  * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
1179
1078
  * // blockNumber: 14578286,
1180
1079
  * // contractAddress: null,
1181
- * // cumulativeGasUsed: { TinyBig: 3067973 },
1182
- * // effectiveGasPrice: { TinyBig: 48592426858 },
1080
+ * // cumulativeGasUsed: 3067973n,
1081
+ * // effectiveGasPrice: 48592426858n,
1183
1082
  * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
1184
- * // gasUsed: { TinyBig: 112163 },
1083
+ * // gasUsed: 112163n,
1185
1084
  * // logs: [
1186
1085
  * // {
1187
1086
  * // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
@@ -1239,7 +1138,6 @@ var BaseProvider = class {
1239
1138
  *
1240
1139
  * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
1241
1140
  * * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
1242
- *
1243
1141
  * @param address the address to count number of sent transactions
1244
1142
  * @param blockTag the block to count transactions up to, inclusive
1245
1143
  * @returns the number of transactions sent by the specified address
@@ -1271,7 +1169,6 @@ var BaseProvider = class {
1271
1169
  *
1272
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`]
1273
1171
  * * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
1274
- *
1275
1172
  * @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
1276
1173
  * @param returnTransactionObjects Whether to also return data about the transactions on the block.
1277
1174
  * @returns A BlockResponse object with information about the specified block
@@ -1279,11 +1176,11 @@ var BaseProvider = class {
1279
1176
  * ```javascript
1280
1177
  * await provider.getBlock(14879862);
1281
1178
  * // {
1282
- * // baseFeePerGas: { TinyBig: 39095728776 },
1283
- * // difficulty: { TinyBig: 14321294455359973 },
1179
+ * // baseFeePerGas: 39095728776n,
1180
+ * // difficulty: 14321294455359973n,
1284
1181
  * // extraData: "0x486976656f6e2073672d6865617679",
1285
- * // gasLimit: { TinyBig: 29970620 },
1286
- * // gasUsed: { TinyBig: 20951384 },
1182
+ * // gasLimit: 29970620n,
1183
+ * // gasUsed: 20951384n,
1287
1184
  * // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
1288
1185
  * // logsBloom:
1289
1186
  * // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
@@ -1294,10 +1191,10 @@ var BaseProvider = class {
1294
1191
  * // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
1295
1192
  * // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
1296
1193
  * // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
1297
- * // size: { TinyBig: 134483 },
1194
+ * // size: 134483n,
1298
1195
  * // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
1299
- * // timestamp: { TinyBig: 1654016186 },
1300
- * // totalDifficulty: { TinyBig: 50478104614257705213748 },
1196
+ * // timestamp: 1654016186n,
1197
+ * // totalDifficulty: 50478104614257705213748n,
1301
1198
  * // transactions: [
1302
1199
  * // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
1303
1200
  * // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
@@ -1328,8 +1225,7 @@ var BaseProvider = class {
1328
1225
  * Gives an estimate of the current gas price in wei.
1329
1226
  *
1330
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)
1331
- * * [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
1332
- *
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
1333
1229
  * @returns an estimate of the current gas price in wei
1334
1230
  * @example
1335
1231
  * ```javascript
@@ -1341,14 +1237,13 @@ var BaseProvider = class {
1341
1237
  const hexGasPrice = await this.post(
1342
1238
  buildRPCPostBody("eth_gasPrice", [])
1343
1239
  );
1344
- return tinyBig(hexToDecimal(hexGasPrice));
1240
+ return BigInt(hexToDecimal(hexGasPrice));
1345
1241
  }
1346
1242
  /**
1347
1243
  * Returns the balance of the account in wei.
1348
1244
  *
1349
1245
  * * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
1350
- * * [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
1351
- *
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
1352
1247
  * @param address the address to check the balance of
1353
1248
  * @param blockTag the block to check the specified address' balance on
1354
1249
  * @returns the balance of the network's native token for the specified address on the specified block
@@ -1363,14 +1258,13 @@ var BaseProvider = class {
1363
1258
  const hexBalance = await this.post(
1364
1259
  buildRPCPostBody("eth_getBalance", [address, blockTag])
1365
1260
  );
1366
- return tinyBig(hexToDecimal(hexBalance));
1261
+ return BigInt(hexToDecimal(hexBalance));
1367
1262
  }
1368
1263
  /**
1369
1264
  * Gets the code of a contract on a specified block.
1370
1265
  *
1371
1266
  * * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
1372
1267
  * * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
1373
- *
1374
1268
  * @param address the contract address to get the contract code from
1375
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
1376
1270
  * @returns the contract creation code for the specified address at the specified block height
@@ -1393,7 +1287,6 @@ var BaseProvider = class {
1393
1287
  *
1394
1288
  * * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
1395
1289
  * * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
1396
- *
1397
1290
  * @param transaction the transaction to check the estimated gas cost for
1398
1291
  * @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
1399
1292
  * @example
@@ -1404,7 +1297,7 @@ var BaseProvider = class {
1404
1297
  * data: "0xd0e30db0",
1405
1298
  * value: etherToWei('1.0').toHexString(),
1406
1299
  * });
1407
- * // { TinyBig: "27938" }
1300
+ * // 27938n
1408
1301
  * ```
1409
1302
  */
1410
1303
  async estimateGas(transaction) {
@@ -1412,7 +1305,7 @@ var BaseProvider = class {
1412
1305
  const gasUsed = await this.post(
1413
1306
  buildRPCPostBody("eth_estimateGas", [rpcTransaction])
1414
1307
  );
1415
- return tinyBig(hexToDecimal(gasUsed));
1308
+ return BigInt(hexToDecimal(gasUsed));
1416
1309
  }
1417
1310
  /**
1418
1311
  * Returns the current recommended FeeData to use in a transaction.
@@ -1420,16 +1313,15 @@ var BaseProvider = class {
1420
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.
1421
1314
  *
1422
1315
  * * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
1423
- *
1424
1316
  * @returns an object with gas estimates for the network currently
1425
1317
  * @example
1426
1318
  * ```javascript
1427
1319
  * await provider.getFeeData();
1428
1320
  * // {
1429
- * // gasPrice: { TinyBig: "14184772639" },
1430
- * // lastBaseFeePerGas: { TinyBig: "14038523098" },
1431
- * // maxFeePerGas: { TinyBig: "29577046196" },
1432
- * // maxPriorityFeePerGas: { TinyBig: "1500000000" }
1321
+ * // gasPrice: 14184772639n,
1322
+ * // lastBaseFeePerGas: 14038523098n,
1323
+ * // maxFeePerGas: 29577046196n,
1324
+ * // maxPriorityFeePerGas: 1500000000n
1433
1325
  * // }
1434
1326
  * ```
1435
1327
  */
@@ -1441,10 +1333,8 @@ var BaseProvider = class {
1441
1333
  let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
1442
1334
  if (block && block.baseFeePerGas) {
1443
1335
  lastBaseFeePerGas = block.baseFeePerGas;
1444
- maxPriorityFeePerGas = tinyBig("1500000000");
1445
- maxFeePerGas = tinyBig(
1446
- block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas)
1447
- );
1336
+ maxPriorityFeePerGas = BigInt("1500000000");
1337
+ maxFeePerGas = block.baseFeePerGas * 2n + maxPriorityFeePerGas;
1448
1338
  }
1449
1339
  return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
1450
1340
  }
@@ -1454,7 +1344,6 @@ var BaseProvider = class {
1454
1344
  *
1455
1345
  * * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
1456
1346
  * * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
1457
- *
1458
1347
  * @param filter parameters to filter the logs by
1459
1348
  * @returns an array of logs matching the specified filter
1460
1349
  * @example
@@ -1506,7 +1395,6 @@ var BaseProvider = class {
1506
1395
  *
1507
1396
  * * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
1508
1397
  * * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
1509
- *
1510
1398
  * @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
1511
1399
  * @param blockTag the block to execute this transaction on
1512
1400
  * @returns the result of executing the transaction on the specified block
@@ -1543,6 +1431,61 @@ var BaseProvider = class {
1543
1431
  );
1544
1432
  return transactionRes;
1545
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
+ }
1546
1489
  };
1547
1490
 
1548
1491
  // src/providers/JsonRpcProvider.ts
@@ -1644,6 +1587,51 @@ var FallthroughProvider = class extends BaseProvider {
1644
1587
  };
1645
1588
  };
1646
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
+
1647
1635
  // src/utils/compute-public-key.ts
1648
1636
  var import_secp256k1 = require("@noble/secp256k1");
1649
1637
  function computePublicKey(privKey) {
@@ -1651,20 +1639,6 @@ function computePublicKey(privKey) {
1651
1639
  return "0x" + import_secp256k1.Point.fromPrivateKey(privKey).toHex();
1652
1640
  }
1653
1641
 
1654
- // src/utils/keccak256.ts
1655
- var import_sha33 = require("sha3");
1656
- function keccak256(data) {
1657
- let bufferableData;
1658
- if (typeof data === "string") {
1659
- bufferableData = Buffer.from(data.replace(/^0x/, ""), "hex");
1660
- } else {
1661
- bufferableData = Buffer.from(data);
1662
- }
1663
- const keccak = new import_sha33.Keccak(256);
1664
- const addressHash = "0x" + keccak.update(bufferableData).digest("hex");
1665
- return addressHash;
1666
- }
1667
-
1668
1642
  // src/utils/compute-address.ts
1669
1643
  function computeAddress(key) {
1670
1644
  if (!key.startsWith("0x04") && !key.startsWith("0x03") && !key.startsWith("0x02")) {
@@ -1673,30 +1647,174 @@ function computeAddress(key) {
1673
1647
  return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
1674
1648
  }
1675
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
+
1676
1777
  // src/utils/ether-to-gwei.ts
1677
1778
  function etherToGwei(etherQuantity) {
1678
- validateType(etherQuantity, ["string", "number", "object"]);
1679
- const result = tinyBig(etherQuantity).times("1000000000");
1680
- return tinyBig(result);
1779
+ validateType(etherQuantity, ["string", "number", "bigint"]);
1780
+ return parseFixed(String(etherQuantity), 9);
1681
1781
  }
1682
1782
 
1683
1783
  // src/utils/ether-to-wei.ts
1684
1784
  function etherToWei(etherQuantity) {
1685
- validateType(etherQuantity, ["string", "number", "object"]);
1686
- const result = tinyBig(etherQuantity).times("1000000000000000000");
1687
- return tinyBig(result);
1785
+ validateType(etherQuantity, ["string", "number", "bigint"]);
1786
+ return parseFixed(String(etherQuantity), 18);
1688
1787
  }
1689
1788
 
1690
- // src/utils/gwei-to-ether.ts
1691
- function gweiToEther(gweiQuantity) {
1692
- validateType(gweiQuantity, ["string", "number", "object"]);
1693
- const result = tinyBig(gweiQuantity).div("1000000000");
1694
- 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);
1695
1802
  }
1696
1803
 
1697
- // src/utils/to-utf8-bytes.ts
1698
- function toUtf8Bytes(data) {
1699
- return new Uint8Array(Buffer.from(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);
1700
1818
  }
1701
1819
 
1702
1820
  // src/utils/hash-message.ts
@@ -1714,6 +1832,11 @@ function hashMessage(message) {
1714
1832
  );
1715
1833
  }
1716
1834
 
1835
+ // src/utils/id.ts
1836
+ function id(text) {
1837
+ return keccak256(toUtf8Bytes(text));
1838
+ }
1839
+
1717
1840
  // src/utils/is-address.ts
1718
1841
  function isAddress(address) {
1719
1842
  validateType(address, ["string"]);
@@ -1725,8 +1848,12 @@ function isAddress(address) {
1725
1848
  }
1726
1849
  }
1727
1850
 
1851
+ // src/utils/parse-units.ts
1852
+ function parseUnits(value, decimals = 18) {
1853
+ return parseFixed(value, decimals);
1854
+ }
1855
+
1728
1856
  // src/utils/solidity-keccak256.ts
1729
- var import_buffer = require("buffer");
1730
1857
  var regexBytes = new RegExp("^bytes([0-9]+)$");
1731
1858
  var regexNumber = new RegExp("^(u?int)([0-9]*)$");
1732
1859
  var regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
@@ -1738,7 +1865,7 @@ function _pack(type, value, isArray) {
1738
1865
  }
1739
1866
  return arrayify(value);
1740
1867
  case "string":
1741
- return import_buffer.Buffer.from(value);
1868
+ return new TextEncoder().encode(value);
1742
1869
  case "bytes":
1743
1870
  return arrayify(value);
1744
1871
  case "bool":
@@ -1757,7 +1884,11 @@ function _pack(type, value, isArray) {
1757
1884
  if (isArray) {
1758
1885
  size = 256;
1759
1886
  }
1760
- 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);
1761
1892
  const hexValue2 = hexlify(value);
1762
1893
  return zeroPad(hexValue2, size / 8);
1763
1894
  }
@@ -1971,17 +2102,8 @@ function splitSignature(signature) {
1971
2102
 
1972
2103
  // src/utils/wei-to-ether.ts
1973
2104
  function weiToEther(weiQuantity) {
1974
- validateType(weiQuantity, ["string", "number", "object"]);
1975
- try {
1976
- let _weiQuantity = weiQuantity;
1977
- if (typeof weiQuantity === "string" && weiQuantity.slice(0, 2) === "0x") {
1978
- _weiQuantity = BigInt(weiQuantity).toString();
1979
- }
1980
- const result = tinyBig(_weiQuantity).div("1000000000000000000");
1981
- return tinyBig(result);
1982
- } catch (error) {
1983
- throw error;
1984
- }
2105
+ validateType(weiQuantity, ["string", "number", "bigint"]);
2106
+ return formatFixed(toBigInt(weiQuantity), 18);
1985
2107
  }
1986
2108
  // Annotate the CommonJS export names for ESM import in node:
1987
2109
  0 && (module.exports = {
@@ -1990,13 +2112,21 @@ function weiToEther(weiQuantity) {
1990
2112
  Contract,
1991
2113
  FallthroughProvider,
1992
2114
  JsonRpcProvider,
1993
- TinyBig,
1994
2115
  arrayify,
1995
2116
  computeAddress,
1996
2117
  computePublicKey,
1997
2118
  concat,
2119
+ decodeBytes32String,
2120
+ decodeEventLog,
2121
+ decodeFunctionResult,
2122
+ encodeBytes32String,
2123
+ encodeFunctionData,
1998
2124
  etherToGwei,
1999
2125
  etherToWei,
2126
+ formatUnits,
2127
+ getAddress,
2128
+ getEventSignature,
2129
+ getEventTopic,
2000
2130
  gweiToEther,
2001
2131
  hashMessage,
2002
2132
  hexConcat,
@@ -2006,19 +2136,22 @@ function weiToEther(weiQuantity) {
2006
2136
  hexValue,
2007
2137
  hexZeroPad,
2008
2138
  hexlify,
2139
+ id,
2009
2140
  isAddress,
2010
2141
  isBytes,
2011
2142
  isBytesLike,
2012
2143
  isHexString,
2013
2144
  jsonRpcProvider,
2014
2145
  keccak256,
2146
+ namehash,
2015
2147
  pack,
2148
+ parseUnits,
2016
2149
  solidityKeccak256,
2017
2150
  splitSignature,
2018
2151
  stripZeros,
2019
- tinyBig,
2020
2152
  toChecksumAddress,
2021
2153
  toUtf8Bytes,
2154
+ toUtf8String,
2022
2155
  weiToEther,
2023
2156
  zeroPad
2024
2157
  });