viem 0.0.1-alpha.1 → 0.0.1-alpha.11

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.
Files changed (40) hide show
  1. package/actions/package.json +1 -1
  2. package/chains/package.json +1 -1
  3. package/clients/package.json +1 -1
  4. package/dist/actions/index.d.ts +6 -6
  5. package/dist/actions/index.js +125 -123
  6. package/dist/actions/index.mjs +125 -0
  7. package/dist/chains.d.ts +651 -21
  8. package/dist/chains.js +76 -75
  9. package/dist/chains.mjs +134 -0
  10. package/dist/chunk-35OJIFIW.js +2619 -0
  11. package/dist/{chunk-Z6LRV6XI.js → chunk-DY4MSK2M.mjs} +1052 -411
  12. package/dist/chunk-GXCYE2PD.js +258 -0
  13. package/dist/{chunk-LLYFXUSV.js → chunk-JXGK2LUM.mjs} +184 -198
  14. package/dist/chunk-PEAG3TIC.js +1084 -0
  15. package/dist/{chunk-OQTFTQTO.js → chunk-TP542F7H.mjs} +44 -63
  16. package/dist/clients/index.d.ts +5 -6
  17. package/dist/clients/index.js +23 -25
  18. package/dist/clients/index.mjs +23 -0
  19. package/dist/{createWalletClient-915223f3.d.ts → createWalletClient-3f9fa8b6.d.ts} +1 -1
  20. package/dist/{eip1193-8f7c22ce.d.ts → eip1193-c001fcd5.d.ts} +3 -3
  21. package/dist/index.d.ts +341 -10
  22. package/dist/index.js +374 -290
  23. package/dist/index.mjs +374 -0
  24. package/dist/{parseGwei-bbc055e4.d.ts → parseGwei-7c87ff41.d.ts} +70 -118
  25. package/dist/{rpc-3c0e3985.d.ts → rpc-26932bae.d.ts} +1 -38
  26. package/dist/{rpc-655c0ba4.d.ts → rpc-b77c5aee.d.ts} +1 -1
  27. package/dist/transactionRequest-08d30731.d.ts +132 -0
  28. package/dist/utils/index.d.ts +41 -7
  29. package/dist/utils/index.js +148 -154
  30. package/dist/utils/index.mjs +148 -0
  31. package/dist/{watchAsset-04ab8db5.d.ts → watchAsset-43255bfd.d.ts} +17 -16
  32. package/dist/{webSocket-c6e0d26f.d.ts → webSocket-3385e295.d.ts} +4 -9
  33. package/dist/window.d.ts +2 -2
  34. package/dist/window.js +1 -0
  35. package/dist/window.mjs +0 -0
  36. package/package.json +9 -62
  37. package/utils/package.json +1 -1
  38. package/window/package.json +1 -1
  39. package/dist/BaseError-7688f84e.d.ts +0 -18
  40. package/dist/transactionRequest-ade896ac.d.ts +0 -44
@@ -8,10 +8,10 @@ var __publicField = (obj, key, value) => {
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "viem",
11
- description: "TypeScript (& JavaScript) Interface for Ethereum",
12
- version: "0.0.1-alpha.1",
11
+ description: "TypeScript Interface for Ethereum",
12
+ version: "0.0.1-alpha.11",
13
13
  scripts: {
14
- anvil: "source .env && anvil --fork-url $ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
14
+ anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
15
15
  bench: "vitest bench --no-threads",
16
16
  "bench:ci": "CI=true vitest bench --no-threads",
17
17
  build: "tsup",
@@ -26,11 +26,14 @@ var package_default = {
26
26
  playground: "pnpm --filter playground-dev dev",
27
27
  "playground:benchmark": "pnpm --filter playground-benchmark dev",
28
28
  postinstall: "pnpm dev",
29
+ postpublish: "pnpm ts-node scripts/restore-package-json.ts",
29
30
  preinstall: "npx only-allow pnpm",
31
+ prepublishOnly: "pnpm ts-node scripts/generate-package-json.ts",
30
32
  prepare: "npx simple-git-hooks",
31
33
  test: "vitest dev --coverage --no-threads",
32
34
  "test:ci": "CI=true vitest --coverage --no-threads",
33
35
  "test:ui": "vitest dev --ui --no-threads",
36
+ "ts-node": "node --loader esbuild-register/loader -r esbuild-register",
34
37
  typecheck: "tsc --noEmit"
35
38
  },
36
39
  files: [
@@ -45,37 +48,43 @@ var package_default = {
45
48
  exports: {
46
49
  ".": {
47
50
  types: "./dist/index.d.ts",
51
+ module: "./dist/index.mjs",
48
52
  default: "./dist/index.js"
49
53
  },
50
54
  "./actions": {
51
55
  types: "./dist/actions/index.d.ts",
56
+ module: "./dist/actions/index.mjs",
52
57
  default: "./dist/actions/index.js"
53
58
  },
54
59
  "./chains": {
55
60
  types: "./dist/chains.d.ts",
61
+ module: "./dist/chains.mjs",
56
62
  default: "./dist/chains.js"
57
63
  },
58
64
  "./clients": {
59
65
  types: "./dist/clients/index.d.ts",
66
+ module: "./dist/clients/index.mjs",
60
67
  default: "./dist/clients/index.js"
61
68
  },
62
69
  "./utils": {
63
70
  types: "./dist/utils/index.d.ts",
71
+ module: "./dist/utils/index.mjs",
64
72
  default: "./dist/utils/index.js"
65
73
  },
66
74
  "./window": {
67
75
  types: "./dist/window.d.ts",
76
+ module: "./dist/window.mjs",
68
77
  default: "./dist/window.js"
69
78
  },
70
79
  "./package.json": "./package.json"
71
80
  },
72
- type: "module",
73
81
  main: "dist/index.js",
82
+ module: "dist/index.mjs",
74
83
  types: "dist/index.d.ts",
75
84
  sideEffects: false,
76
85
  dependencies: {
77
86
  "@noble/hashes": "^1.1.2",
78
- "@wagmi/chains": "^0.1.0",
87
+ "@wagmi/chains": "0.0.0-20230201210619",
79
88
  abitype: "^0.2.5"
80
89
  },
81
90
  devDependencies: {
@@ -129,19 +138,27 @@ var package_default = {
129
138
  }
130
139
  };
131
140
 
132
- // src/utils/BaseError.ts
141
+ // src/utils/stringify.ts
142
+ function stringify(value) {
143
+ return JSON.stringify(
144
+ value,
145
+ (_, value2) => typeof value2 === "bigint" ? value2.toString() : value2
146
+ );
147
+ }
148
+
149
+ // src/errors/base.ts
133
150
  var version = process.env.TEST ? "1.0.2" : package_default.version;
134
151
  var BaseError = class extends Error {
135
152
  constructor(humanMessage, args = {}) {
136
153
  const details = args.cause instanceof BaseError ? args.cause.details : args.cause?.message ? args.cause.message : args.details;
137
- const docsPath = args.cause instanceof BaseError ? args.cause.docsPath || args.docsPath : args.docsPath;
154
+ const docsPath5 = args.cause instanceof BaseError ? args.cause.docsPath || args.docsPath : args.docsPath;
138
155
  const message = [
139
156
  humanMessage,
140
- ...docsPath ? ["", `Docs: https://viem.sh${docsPath}`] : [],
157
+ ...docsPath5 ? ["", `Docs: https://viem.sh${docsPath5}`] : [],
141
158
  "",
142
159
  ...details ? [`Details: ${details}`] : [],
143
160
  `Version: viem@${version}`,
144
- ...args.cause && !(args.cause instanceof BaseError) && Object.keys(args.cause).length > 0 ? [`Internal Error: ${JSON.stringify(args.cause)}`] : []
161
+ ...args.cause && !(args.cause instanceof BaseError) && Object.keys(args.cause).length > 0 ? [`Internal Error: ${stringify(args.cause)}`] : []
145
162
  ].join("\n");
146
163
  super(message);
147
164
  __publicField(this, "humanMessage");
@@ -151,11 +168,679 @@ var BaseError = class extends Error {
151
168
  if (args.cause)
152
169
  this.cause = args.cause;
153
170
  this.details = details;
154
- this.docsPath = docsPath;
171
+ this.docsPath = docsPath5;
155
172
  this.humanMessage = humanMessage;
156
173
  }
157
174
  };
158
175
 
176
+ // src/errors/abi.ts
177
+ var AbiConstructorNotFoundError = class extends BaseError {
178
+ constructor({ docsPath: docsPath5 }) {
179
+ super(
180
+ [
181
+ "A constructor was not found on the ABI.",
182
+ "Make sure you are using the correct ABI and that the constructor exists on it."
183
+ ].join("\n"),
184
+ {
185
+ docsPath: docsPath5
186
+ }
187
+ );
188
+ __publicField(this, "name", "AbiConstructorNotFoundError");
189
+ }
190
+ };
191
+ var AbiConstructorParamsNotFoundError = class extends BaseError {
192
+ constructor({ docsPath: docsPath5 }) {
193
+ super(
194
+ [
195
+ "Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.",
196
+ "Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."
197
+ ].join("\n"),
198
+ {
199
+ docsPath: docsPath5
200
+ }
201
+ );
202
+ __publicField(this, "name", "AbiConstructorParamsNotFoundError");
203
+ }
204
+ };
205
+ var AbiDecodingDataSizeInvalidError = class extends BaseError {
206
+ constructor(size2) {
207
+ super(
208
+ [
209
+ `Data size of ${size2} bytes is invalid.`,
210
+ "Size must be in increments of 32 bytes (size % 32 === 0)."
211
+ ].join("\n")
212
+ );
213
+ __publicField(this, "name", "AbiDecodingDataSizeInvalidError");
214
+ }
215
+ };
216
+ var AbiDecodingZeroDataError = class extends BaseError {
217
+ constructor() {
218
+ super('Cannot decode zero data ("0x") with ABI parameters.');
219
+ __publicField(this, "name", "AbiDecodingZeroDataError");
220
+ }
221
+ };
222
+ var AbiEncodingArrayLengthMismatchError = class extends BaseError {
223
+ constructor({
224
+ expectedLength,
225
+ givenLength,
226
+ type
227
+ }) {
228
+ super(
229
+ [
230
+ `ABI encoding array length mismatch for type ${type}.`,
231
+ `Expected length: ${expectedLength}`,
232
+ `Given length: ${givenLength}`
233
+ ].join("\n")
234
+ );
235
+ __publicField(this, "name", "AbiEncodingArrayLengthMismatchError");
236
+ }
237
+ };
238
+ var AbiEncodingLengthMismatchError = class extends BaseError {
239
+ constructor({
240
+ expectedLength,
241
+ givenLength
242
+ }) {
243
+ super(
244
+ [
245
+ "ABI encoding params/values length mismatch.",
246
+ `Expected length (params): ${expectedLength}`,
247
+ `Given length (values): ${givenLength}`
248
+ ].join("\n")
249
+ );
250
+ __publicField(this, "name", "AbiEncodingLengthMismatchError");
251
+ }
252
+ };
253
+ var AbiErrorInputsNotFoundError = class extends BaseError {
254
+ constructor(errorName, { docsPath: docsPath5 }) {
255
+ super(
256
+ [
257
+ `Arguments (\`args\`) were provided to "${errorName}", but "${errorName}" on the ABI does not contain any parameters (\`inputs\`).`,
258
+ "Cannot encode error result without knowing what the parameter types are.",
259
+ "Make sure you are using the correct ABI and that the inputs exist on it."
260
+ ].join("\n"),
261
+ {
262
+ docsPath: docsPath5
263
+ }
264
+ );
265
+ __publicField(this, "name", "AbiErrorInputsNotFoundError");
266
+ }
267
+ };
268
+ var AbiErrorNotFoundError = class extends BaseError {
269
+ constructor(errorName, { docsPath: docsPath5 }) {
270
+ super(
271
+ [
272
+ `Error "${errorName}" not found on ABI.`,
273
+ "Make sure you are using the correct ABI and that the error exists on it."
274
+ ].join("\n"),
275
+ {
276
+ docsPath: docsPath5
277
+ }
278
+ );
279
+ __publicField(this, "name", "AbiErrorNotFoundError");
280
+ }
281
+ };
282
+ var AbiErrorSignatureNotFoundError = class extends BaseError {
283
+ constructor(signature, { docsPath: docsPath5 }) {
284
+ super(
285
+ [
286
+ `Encoded error signature "${signature}" not found on ABI.`,
287
+ "Make sure you are using the correct ABI and that the error exists on it.",
288
+ `You can look up the signature "${signature}" here: https://sig.eth.samczsun.com/.`
289
+ ].join("\n"),
290
+ {
291
+ docsPath: docsPath5
292
+ }
293
+ );
294
+ __publicField(this, "name", "AbiErrorSignatureNotFoundError");
295
+ }
296
+ };
297
+ var AbiEventNotFoundError = class extends BaseError {
298
+ constructor(eventName, { docsPath: docsPath5 }) {
299
+ super(
300
+ [
301
+ `Event "${eventName}" not found on ABI.`,
302
+ "Make sure you are using the correct ABI and that the event exists on it."
303
+ ].join("\n"),
304
+ {
305
+ docsPath: docsPath5
306
+ }
307
+ );
308
+ __publicField(this, "name", "AbiEventNotFoundError");
309
+ }
310
+ };
311
+ var AbiFunctionNotFoundError = class extends BaseError {
312
+ constructor(functionName, { docsPath: docsPath5 }) {
313
+ super(
314
+ [
315
+ `Function "${functionName}" not found on ABI.`,
316
+ "Make sure you are using the correct ABI and that the function exists on it."
317
+ ].join("\n"),
318
+ {
319
+ docsPath: docsPath5
320
+ }
321
+ );
322
+ __publicField(this, "name", "AbiFunctionNotFoundError");
323
+ }
324
+ };
325
+ var AbiFunctionOutputsNotFoundError = class extends BaseError {
326
+ constructor(functionName, { docsPath: docsPath5 }) {
327
+ super(
328
+ [
329
+ `Function "${functionName}" does not contain any \`outputs\` on ABI.`,
330
+ "Cannot decode function result without knowing what the parameter types are.",
331
+ "Make sure you are using the correct ABI and that the function exists on it."
332
+ ].join("\n"),
333
+ {
334
+ docsPath: docsPath5
335
+ }
336
+ );
337
+ __publicField(this, "name", "AbiFunctionOutputsNotFoundError");
338
+ }
339
+ };
340
+ var AbiFunctionSignatureNotFoundError = class extends BaseError {
341
+ constructor(signature, { docsPath: docsPath5 }) {
342
+ super(
343
+ [
344
+ `Encoded function signature "${signature}" not found on ABI.`,
345
+ "Make sure you are using the correct ABI and that the function exists on it.",
346
+ `You can look up the signature "${signature}" here: https://sig.eth.samczsun.com/.`
347
+ ].join("\n"),
348
+ {
349
+ docsPath: docsPath5
350
+ }
351
+ );
352
+ __publicField(this, "name", "AbiFunctionSignatureNotFoundError");
353
+ }
354
+ };
355
+ var InvalidAbiEncodingTypeError = class extends BaseError {
356
+ constructor(type, { docsPath: docsPath5 }) {
357
+ super(
358
+ [
359
+ `Type "${type}" is not a valid encoding type.`,
360
+ "Please provide a valid ABI type."
361
+ ].join("\n"),
362
+ { docsPath: docsPath5 }
363
+ );
364
+ __publicField(this, "name", "InvalidAbiEncodingType");
365
+ }
366
+ };
367
+ var InvalidAbiDecodingTypeError = class extends BaseError {
368
+ constructor(type, { docsPath: docsPath5 }) {
369
+ super(
370
+ [
371
+ `Type "${type}" is not a valid decoding type.`,
372
+ "Please provide a valid ABI type."
373
+ ].join("\n"),
374
+ { docsPath: docsPath5 }
375
+ );
376
+ __publicField(this, "name", "InvalidAbiDecodingType");
377
+ }
378
+ };
379
+ var InvalidArrayError = class extends BaseError {
380
+ constructor(value) {
381
+ super([`Value "${value}" is not a valid array.`].join("\n"));
382
+ __publicField(this, "name", "InvalidArrayError");
383
+ }
384
+ };
385
+ var InvalidDefinitionTypeError = class extends BaseError {
386
+ constructor(type) {
387
+ super(
388
+ [
389
+ `"${type}" is not a valid definition type.`,
390
+ 'Valid types: "function", "event", "error"'
391
+ ].join("\n")
392
+ );
393
+ __publicField(this, "name", "InvalidDefinitionTypeError");
394
+ }
395
+ };
396
+
397
+ // src/errors/address.ts
398
+ var InvalidAddressError = class extends BaseError {
399
+ constructor({ address }) {
400
+ super(`Address "${address}" is invalid.`);
401
+ __publicField(this, "name", "InvalidAddressError");
402
+ }
403
+ };
404
+
405
+ // src/errors/block.ts
406
+ var BlockNotFoundError = class extends BaseError {
407
+ constructor({
408
+ blockHash,
409
+ blockNumber
410
+ }) {
411
+ let identifier = "Block";
412
+ if (blockHash)
413
+ identifier = `Block at hash "${blockHash}"`;
414
+ if (blockNumber)
415
+ identifier = `Block at number "${blockNumber}"`;
416
+ super(`${identifier} could not be found.`);
417
+ __publicField(this, "name", "BlockNotFoundError");
418
+ }
419
+ };
420
+
421
+ // src/errors/contract.ts
422
+ var ContractMethodExecutionError = class extends BaseError {
423
+ constructor(message, {
424
+ abi,
425
+ args,
426
+ cause,
427
+ contractAddress,
428
+ formattedArgs,
429
+ functionName,
430
+ functionWithParams,
431
+ sender
432
+ } = {}) {
433
+ super(
434
+ [
435
+ message,
436
+ " ",
437
+ sender && `Sender: ${sender}`,
438
+ contractAddress && `Contract: ${process.env.TEST ? "0x0000000000000000000000000000000000000000" : contractAddress}`,
439
+ functionWithParams && `Function: ${functionWithParams}`,
440
+ formattedArgs && `Arguments: ${[...Array(functionName?.length ?? 0).keys()].map(() => " ").join("")}${formattedArgs}`
441
+ ].filter(Boolean).join("\n"),
442
+ {
443
+ cause
444
+ }
445
+ );
446
+ __publicField(this, "abi");
447
+ __publicField(this, "args");
448
+ __publicField(this, "contractAddress");
449
+ __publicField(this, "formattedArgs");
450
+ __publicField(this, "functionName");
451
+ __publicField(this, "reason");
452
+ __publicField(this, "sender");
453
+ __publicField(this, "name", "ContractMethodExecutionError");
454
+ if (message)
455
+ this.reason = message;
456
+ this.abi = abi;
457
+ this.args = args;
458
+ this.contractAddress = contractAddress;
459
+ this.functionName = functionName;
460
+ this.sender = sender;
461
+ }
462
+ };
463
+ var ContractMethodZeroDataError = class extends BaseError {
464
+ constructor({
465
+ abi,
466
+ args,
467
+ cause,
468
+ contractAddress,
469
+ functionName,
470
+ functionWithParams
471
+ } = {}) {
472
+ super(
473
+ [
474
+ `The contract method "${functionName}" returned no data ("0x"). This could be due to any of the following:`,
475
+ `- The contract does not have the function "${functionName}",`,
476
+ "- The parameters passed to the contract function may be invalid, or",
477
+ "- The address is not a contract.",
478
+ " ",
479
+ contractAddress && `Contract: ${process.env.TEST ? "0x0000000000000000000000000000000000000000" : contractAddress}`,
480
+ functionWithParams && `Function: ${functionWithParams}`,
481
+ functionWithParams && ` > "0x"`
482
+ ].filter(Boolean).join("\n"),
483
+ {
484
+ cause
485
+ }
486
+ );
487
+ __publicField(this, "abi");
488
+ __publicField(this, "args");
489
+ __publicField(this, "contractAddress");
490
+ __publicField(this, "functionName");
491
+ __publicField(this, "functionWithParams");
492
+ __publicField(this, "name", "ContractMethodZeroDataError");
493
+ this.abi = abi;
494
+ this.args = args;
495
+ this.contractAddress = contractAddress;
496
+ this.functionName = functionName;
497
+ }
498
+ };
499
+
500
+ // src/errors/data.ts
501
+ var SizeExceedsPaddingSizeError = class extends BaseError {
502
+ constructor({
503
+ size: size2,
504
+ targetSize,
505
+ type
506
+ }) {
507
+ super(
508
+ `${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size2}) exceeds padding size (${targetSize}).`
509
+ );
510
+ __publicField(this, "name", "SizeExceedsPaddingSizeError");
511
+ }
512
+ };
513
+
514
+ // src/errors/encoding.ts
515
+ var DataLengthTooLongError = class extends BaseError {
516
+ constructor({ consumed, length }) {
517
+ super(
518
+ `Consumed bytes (${consumed}) is shorter than data length (${length - 1}).`
519
+ );
520
+ __publicField(this, "name", "DataLengthTooLongError");
521
+ }
522
+ };
523
+ var DataLengthTooShortError = class extends BaseError {
524
+ constructor({ length, dataLength }) {
525
+ super(
526
+ `Data length (${dataLength - 1}) is shorter than prefix length (${length - 1}).`
527
+ );
528
+ __publicField(this, "name", "DataLengthTooShortError");
529
+ }
530
+ };
531
+ var InvalidBytesBooleanError = class extends BaseError {
532
+ constructor(bytes) {
533
+ super(
534
+ `Bytes value "${bytes}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`
535
+ );
536
+ __publicField(this, "name", "InvalidBytesBooleanError");
537
+ }
538
+ };
539
+ var InvalidHexBooleanError = class extends BaseError {
540
+ constructor(hex) {
541
+ super(
542
+ `Hex value "${hex}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`
543
+ );
544
+ __publicField(this, "name", "InvalidHexBooleanError");
545
+ }
546
+ };
547
+ var InvalidHexValueError = class extends BaseError {
548
+ constructor(value) {
549
+ super(
550
+ `Hex value "${value}" is an odd length (${value.length}). It must be an even length.`
551
+ );
552
+ __publicField(this, "name", "InvalidHexValueError");
553
+ }
554
+ };
555
+ var OffsetOutOfBoundsError = class extends BaseError {
556
+ constructor({ nextOffset, offset }) {
557
+ super(
558
+ `Next offset (${nextOffset}) is greater than previous offset + consumed bytes (${offset})`
559
+ );
560
+ __publicField(this, "name", "OffsetOutOfBoundsError");
561
+ }
562
+ };
563
+
564
+ // src/errors/log.ts
565
+ var FilterTypeNotSupportedError = class extends BaseError {
566
+ constructor(type) {
567
+ super(`Filter type "${type}" is not supported.`);
568
+ __publicField(this, "name", "FilterTypeNotSupportedError");
569
+ }
570
+ };
571
+
572
+ // src/errors/request.ts
573
+ var RequestError = class extends BaseError {
574
+ constructor(err, { docsPath: docsPath5, humanMessage }) {
575
+ super(humanMessage, {
576
+ cause: err,
577
+ docsPath: docsPath5
578
+ });
579
+ this.name = err.name;
580
+ }
581
+ };
582
+ var RpcRequestError = class extends RequestError {
583
+ constructor(err, { docsPath: docsPath5, humanMessage }) {
584
+ super(err, { docsPath: docsPath5, humanMessage });
585
+ __publicField(this, "code");
586
+ this.code = err.code;
587
+ this.name = err.name;
588
+ }
589
+ };
590
+ var ParseRpcError = class extends RpcRequestError {
591
+ constructor(err) {
592
+ super(err, {
593
+ humanMessage: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
594
+ });
595
+ __publicField(this, "name", "ParseRpcError");
596
+ __publicField(this, "code", -32700);
597
+ }
598
+ };
599
+ var InvalidRequestRpcError = class extends RpcRequestError {
600
+ constructor(err) {
601
+ super(err, { humanMessage: "JSON is not a valid request object." });
602
+ __publicField(this, "name", "InvalidRequestRpcError");
603
+ __publicField(this, "code", -32600);
604
+ }
605
+ };
606
+ var MethodNotFoundRpcError = class extends RpcRequestError {
607
+ constructor(err) {
608
+ super(err, {
609
+ humanMessage: "The method does not exist / is not available."
610
+ });
611
+ __publicField(this, "name", "MethodNotFoundRpcError");
612
+ __publicField(this, "code", -32601);
613
+ }
614
+ };
615
+ var InvalidParamsRpcError = class extends RpcRequestError {
616
+ constructor(err) {
617
+ super(err, {
618
+ humanMessage: [
619
+ "Invalid parameters were provided to the RPC method.",
620
+ "Double check you have provided the correct parameters."
621
+ ].join("\n")
622
+ });
623
+ __publicField(this, "name", "InvalidParamsRpcError");
624
+ __publicField(this, "code", -32602);
625
+ }
626
+ };
627
+ var InternalRpcError = class extends RpcRequestError {
628
+ constructor(err) {
629
+ super(err, { humanMessage: "An internal error was received." });
630
+ __publicField(this, "name", "InternalRpcError");
631
+ __publicField(this, "code", -32603);
632
+ }
633
+ };
634
+ var InvalidInputRpcError = class extends RpcRequestError {
635
+ constructor(err) {
636
+ super(err, {
637
+ humanMessage: [
638
+ "Missing or invalid parameters.",
639
+ "Double check you have provided the correct parameters."
640
+ ].join("\n")
641
+ });
642
+ __publicField(this, "name", "InvalidInputRpcError");
643
+ __publicField(this, "code", -32e3);
644
+ }
645
+ };
646
+ var ResourceNotFoundRpcError = class extends RpcRequestError {
647
+ constructor(err) {
648
+ super(err, { humanMessage: "Requested resource not found." });
649
+ __publicField(this, "name", "ResourceNotFoundRpcError");
650
+ __publicField(this, "code", -32001);
651
+ }
652
+ };
653
+ var ResourceUnavailableRpcError = class extends RpcRequestError {
654
+ constructor(err) {
655
+ super(err, { humanMessage: "Requested resource not available." });
656
+ __publicField(this, "name", "ResourceUnavailableRpcError");
657
+ __publicField(this, "code", -32002);
658
+ }
659
+ };
660
+ var TransactionRejectedRpcError = class extends RpcRequestError {
661
+ constructor(err) {
662
+ super(err, { humanMessage: "Transaction creation failed." });
663
+ __publicField(this, "name", "TransactionRejectedRpcError");
664
+ __publicField(this, "code", -32003);
665
+ }
666
+ };
667
+ var MethodNotSupportedRpcError = class extends RpcRequestError {
668
+ constructor(err) {
669
+ super(err, { humanMessage: "Method is not implemented." });
670
+ __publicField(this, "name", "MethodNotSupportedRpcError");
671
+ __publicField(this, "code", -32004);
672
+ }
673
+ };
674
+ var LimitExceededRpcError = class extends RpcRequestError {
675
+ constructor(err) {
676
+ super(err, { humanMessage: "Request exceeds defined limit." });
677
+ __publicField(this, "name", "LimitExceededRpcError");
678
+ __publicField(this, "code", -32005);
679
+ }
680
+ };
681
+ var JsonRpcVersionUnsupportedError = class extends RpcRequestError {
682
+ constructor(err) {
683
+ super(err, {
684
+ humanMessage: "Version of JSON-RPC protocol is not supported."
685
+ });
686
+ __publicField(this, "name", "JsonRpcVersionUnsupportedError");
687
+ __publicField(this, "code", -32006);
688
+ }
689
+ };
690
+ var UnknownRpcError = class extends RequestError {
691
+ constructor(err) {
692
+ super(err, {
693
+ humanMessage: "An unknown RPC error occurred."
694
+ });
695
+ __publicField(this, "name", "UnknownRpcError");
696
+ }
697
+ };
698
+
699
+ // src/errors/rpc.ts
700
+ var HttpRequestError = class extends BaseError {
701
+ constructor({
702
+ body,
703
+ details,
704
+ status,
705
+ url
706
+ }) {
707
+ super(
708
+ [
709
+ "HTTP request failed.",
710
+ "",
711
+ `Status: ${status}`,
712
+ `URL: ${url}`,
713
+ `Request body: ${stringify(body)}`
714
+ ].join("\n"),
715
+ {
716
+ details
717
+ }
718
+ );
719
+ __publicField(this, "name", "HttpRequestError");
720
+ __publicField(this, "status");
721
+ this.status = status;
722
+ }
723
+ };
724
+ var WebSocketRequestError = class extends BaseError {
725
+ constructor({
726
+ body,
727
+ details,
728
+ url
729
+ }) {
730
+ super(
731
+ [
732
+ "WebSocket request failed.",
733
+ "",
734
+ `URL: ${url}`,
735
+ `Request body: ${stringify(body)}`
736
+ ].join("\n"),
737
+ {
738
+ details
739
+ }
740
+ );
741
+ __publicField(this, "name", "WebSocketRequestError");
742
+ }
743
+ };
744
+ var RpcError = class extends BaseError {
745
+ constructor({
746
+ body,
747
+ error,
748
+ url
749
+ }) {
750
+ super(
751
+ [
752
+ "RPC Request failed.",
753
+ "",
754
+ `URL: ${url}`,
755
+ `Request body: ${stringify(body)}`
756
+ ].join("\n"),
757
+ {
758
+ cause: error,
759
+ details: error.message
760
+ }
761
+ );
762
+ __publicField(this, "code");
763
+ __publicField(this, "name", "RpcError");
764
+ this.code = error.code;
765
+ }
766
+ };
767
+ var TimeoutError = class extends BaseError {
768
+ constructor({
769
+ body,
770
+ url
771
+ }) {
772
+ super(
773
+ [
774
+ "The request took too long to respond.",
775
+ "",
776
+ `URL: ${url}`,
777
+ `Request body: ${stringify(body)}`
778
+ ].join("\n"),
779
+ {
780
+ details: "The request timed out."
781
+ }
782
+ );
783
+ __publicField(this, "name", "TimeoutError");
784
+ }
785
+ };
786
+
787
+ // src/errors/transaction.ts
788
+ var InvalidGasArgumentsError = class extends BaseError {
789
+ constructor() {
790
+ super("`maxFeePerGas` cannot be less than `maxPriorityFeePerGas`");
791
+ __publicField(this, "name", "InvalidGasArgumentsError");
792
+ }
793
+ };
794
+ var TransactionNotFoundError = class extends BaseError {
795
+ constructor({
796
+ blockHash,
797
+ blockNumber,
798
+ blockTag,
799
+ hash: hash2,
800
+ index
801
+ }) {
802
+ let identifier = "Transaction";
803
+ if (blockTag && index !== void 0)
804
+ identifier = `Transaction at block time "${blockTag}" at index "${index}"`;
805
+ if (blockHash && index !== void 0)
806
+ identifier = `Transaction at block hash "${blockHash}" at index "${index}"`;
807
+ if (blockNumber && index !== void 0)
808
+ identifier = `Transaction at block number "${blockNumber}" at index "${index}"`;
809
+ if (hash2)
810
+ identifier = `Transaction with hash "${hash2}"`;
811
+ super(`${identifier} could not be found.`);
812
+ __publicField(this, "name", "TransactionNotFoundError");
813
+ }
814
+ };
815
+ var TransactionReceiptNotFoundError = class extends BaseError {
816
+ constructor({ hash: hash2 }) {
817
+ super(
818
+ `Transaction receipt with hash "${hash2}" could not be found. The Transaction may not be processed on a block yet.`
819
+ );
820
+ __publicField(this, "name", "TransactionReceiptNotFoundError");
821
+ }
822
+ };
823
+ var WaitForTransactionReceiptTimeoutError = class extends BaseError {
824
+ constructor({ hash: hash2 }) {
825
+ super(
826
+ `Timed out while waiting for transaction with hash "${hash2}" to be confirmed.`
827
+ );
828
+ __publicField(this, "name", "WaitForTransactionReceiptTimeoutError");
829
+ }
830
+ };
831
+
832
+ // src/errors/transport.ts
833
+ var UrlRequiredError = class extends BaseError {
834
+ constructor() {
835
+ super(
836
+ "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",
837
+ {
838
+ docsPath: "/docs/clients/intro"
839
+ }
840
+ );
841
+ }
842
+ };
843
+
159
844
  // src/utils/data/concat.ts
160
845
  function concat(values) {
161
846
  if (typeof values[0] === "string")
@@ -233,18 +918,6 @@ function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
233
918
  }
234
919
  return paddedBytes;
235
920
  }
236
- var SizeExceedsPaddingSizeError = class extends BaseError {
237
- constructor({
238
- size: size2,
239
- targetSize,
240
- type
241
- }) {
242
- super(
243
- `${type.charAt(0).toUpperCase()}${type.slice(1).toLowerCase()} size (${size2}) exceeds padding size (${targetSize}).`
244
- );
245
- __publicField(this, "name", "SizeExceedsPaddingSizeError");
246
- }
247
- };
248
921
 
249
922
  // src/utils/data/trim.ts
250
923
  function trim(hexOrBytes, { dir = "left" } = {}) {
@@ -457,14 +1130,6 @@ function hexToString(hex) {
457
1130
  const bytes = hexToBytes(hex);
458
1131
  return new TextDecoder().decode(bytes);
459
1132
  }
460
- var InvalidHexBooleanError = class extends BaseError {
461
- constructor(hex) {
462
- super(
463
- `Hex value "${hex}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`
464
- );
465
- __publicField(this, "name", "InvalidHexBooleanError");
466
- }
467
- };
468
1133
 
469
1134
  // src/utils/encoding/decodeBytes.ts
470
1135
  function decodeBytes(bytes, to) {
@@ -494,14 +1159,6 @@ function bytesToNumber(bytes) {
494
1159
  function bytesToString(bytes) {
495
1160
  return new TextDecoder().decode(bytes);
496
1161
  }
497
- var InvalidBytesBooleanError = class extends BaseError {
498
- constructor(bytes) {
499
- super(
500
- `Bytes value "${bytes}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`
501
- );
502
- __publicField(this, "name", "InvalidBytesBooleanError");
503
- }
504
- };
505
1162
 
506
1163
  // src/utils/encoding/decodeRlp.ts
507
1164
  function decodeRlp(value, to) {
@@ -583,40 +1240,8 @@ function rlpToBytes(bytes, offset = 0) {
583
1240
  }
584
1241
  return [result, consumed];
585
1242
  }
586
- var DataLengthTooLongError = class extends BaseError {
587
- constructor({ consumed, length }) {
588
- super(
589
- `Consumed bytes (${consumed}) is shorter than data length (${length - 1}).`
590
- );
591
- __publicField(this, "name", "DataLengthTooLongError");
592
- }
593
- };
594
- var DataLengthTooShortError = class extends BaseError {
595
- constructor({ length, dataLength }) {
596
- super(
597
- `Data length (${dataLength - 1}) is shorter than prefix length (${length - 1}).`
598
- );
599
- __publicField(this, "name", "DataLengthTooShortError");
600
- }
601
- };
602
- var InvalidHexValueError = class extends BaseError {
603
- constructor(value) {
604
- super(
605
- `Hex value "${value}" is an odd length (${value.length}). It must be an even length.`
606
- );
607
- __publicField(this, "name", "InvalidHexValueError");
608
- }
609
- };
610
- var OffsetOutOfBoundsError = class extends BaseError {
611
- constructor({ nextOffset, offset }) {
612
- super(
613
- `Next offset (${nextOffset}) is greater than previous offset + consumed bytes (${offset})`
614
- );
615
- __publicField(this, "name", "OffsetOutOfBoundsError");
616
- }
617
- };
618
1243
 
619
- // src/utils/solidity.ts
1244
+ // src/utils/contract/extractFunctionParts.ts
620
1245
  var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
621
1246
  function extractFunctionParts(def) {
622
1247
  const parts = def.match(paramsRegex);
@@ -641,6 +1266,49 @@ function extractFunctionType(def) {
641
1266
  return extractFunctionParts(def).type;
642
1267
  }
643
1268
 
1269
+ // src/utils/contract/getContractError.ts
1270
+ function getContractError(err, {
1271
+ abi,
1272
+ address,
1273
+ args,
1274
+ functionName,
1275
+ sender
1276
+ }) {
1277
+ const { code, message } = err.cause || {};
1278
+ const abiItem = getAbiItem({ abi, name: functionName });
1279
+ const formattedArgs = abiItem ? formatAbiItemWithArgs({
1280
+ abiItem,
1281
+ args,
1282
+ includeFunctionName: false,
1283
+ includeName: false
1284
+ }) : void 0;
1285
+ const functionWithParams = abiItem ? formatAbiItemWithParams(abiItem, { includeName: true }) : void 0;
1286
+ if (err instanceof AbiDecodingZeroDataError) {
1287
+ return new ContractMethodZeroDataError({
1288
+ abi,
1289
+ args,
1290
+ cause: err,
1291
+ contractAddress: address,
1292
+ functionName,
1293
+ functionWithParams
1294
+ });
1295
+ }
1296
+ if (code === 3 || message?.includes("execution reverted")) {
1297
+ const message_ = message?.replace("execution reverted: ", "");
1298
+ return new ContractMethodExecutionError(message_, {
1299
+ abi,
1300
+ args,
1301
+ cause: err,
1302
+ contractAddress: address,
1303
+ formattedArgs,
1304
+ functionName,
1305
+ functionWithParams,
1306
+ sender
1307
+ });
1308
+ }
1309
+ return err;
1310
+ }
1311
+
644
1312
  // src/utils/hash/keccak256.ts
645
1313
  import { keccak_256 } from "@noble/hashes/sha3";
646
1314
  function keccak256(value, to_) {
@@ -665,7 +1333,7 @@ function hashFunction(def) {
665
1333
  var getEventSignature = (event) => hashFunction(event);
666
1334
 
667
1335
  // src/utils/hash/getFunctionSignature.ts
668
- var getFunctionSignature = (fn) => hashFunction(fn).slice(0, 10);
1336
+ var getFunctionSignature = (fn) => slice(hashFunction(fn), 0, 4);
669
1337
 
670
1338
  // src/utils/address/getAddress.ts
671
1339
  var addressRegex = /^(0x)?[a-fA-F0-9]{40}$/;
@@ -674,10 +1342,10 @@ function checksumAddress(address_) {
674
1342
  const hash2 = keccak256(stringToBytes(hexAddress), "bytes");
675
1343
  let address = hexAddress.split("");
676
1344
  for (let i = 0; i < 40; i += 2) {
677
- if (hash2?.[i >> 1] >> 4 >= 8) {
1345
+ if (hash2?.[i >> 1] >> 4 >= 8 && address[i]) {
678
1346
  address[i] = address[i].toUpperCase();
679
1347
  }
680
- if ((hash2[i >> 1] & 15) >= 8) {
1348
+ if ((hash2[i >> 1] & 15) >= 8 && address[i + 1]) {
681
1349
  address[i + 1] = address[i + 1].toUpperCase();
682
1350
  }
683
1351
  }
@@ -688,12 +1356,6 @@ function getAddress(address) {
688
1356
  throw new InvalidAddressError({ address });
689
1357
  return checksumAddress(address);
690
1358
  }
691
- var InvalidAddressError = class extends BaseError {
692
- constructor({ address }) {
693
- super(`Address "${address}" is invalid.`);
694
- __publicField(this, "name", "InvalidAddressError");
695
- }
696
- };
697
1359
 
698
1360
  // src/utils/address/getContractAddress.ts
699
1361
  function getContractAddress(opts) {
@@ -754,7 +1416,10 @@ function encodeAbi({
754
1416
  givenLength: values.length
755
1417
  });
756
1418
  const preparedParams = prepareParams({ params, values });
757
- return encodeParams(preparedParams);
1419
+ const data = encodeParams(preparedParams);
1420
+ if (data.length === 0)
1421
+ return "0x";
1422
+ return data;
758
1423
  }
759
1424
  function prepareParams({
760
1425
  params,
@@ -796,7 +1461,9 @@ function prepareParam({
796
1461
  if (param.type === "string") {
797
1462
  return encodeString(value);
798
1463
  }
799
- throw new InvalidAbiEncodingTypeError(param.type);
1464
+ throw new InvalidAbiEncodingTypeError(param.type, {
1465
+ docsPath: "/docs/contract/encodeAbi"
1466
+ });
800
1467
  }
801
1468
  function encodeParams(preparedParams) {
802
1469
  let staticSize = 0;
@@ -822,6 +1489,9 @@ function encodeParams(preparedParams) {
822
1489
  }
823
1490
  return concat([...staticParams, ...dynamicParams]);
824
1491
  }
1492
+ function encodeAddress(value) {
1493
+ return { dynamic: false, encoded: padHex(value.toLowerCase()) };
1494
+ }
825
1495
  function encodeArray(value, {
826
1496
  length,
827
1497
  param
@@ -860,27 +1530,6 @@ function encodeArray(value, {
860
1530
  encoded: concat(preparedParams.map(({ encoded }) => encoded))
861
1531
  };
862
1532
  }
863
- function encodeTuple(value, { param }) {
864
- let dynamic = false;
865
- let preparedParams = [];
866
- for (let i = 0; i < param.components.length; i++) {
867
- const param_ = param.components[i];
868
- const index = Array.isArray(value) ? i : param_.name;
869
- const preparedParam = prepareParam({
870
- param: param_,
871
- value: value[index]
872
- });
873
- preparedParams.push(preparedParam);
874
- dynamic = preparedParam.dynamic;
875
- }
876
- return {
877
- dynamic,
878
- encoded: dynamic ? encodeParams(preparedParams) : concat(preparedParams.map(({ encoded }) => encoded))
879
- };
880
- }
881
- function encodeAddress(value) {
882
- return { dynamic: false, encoded: padHex(value.toLowerCase()) };
883
- }
884
1533
  function encodeBytes2(value, { param }) {
885
1534
  const [_, size_] = param.type.split("bytes");
886
1535
  if (!size_)
@@ -914,71 +1563,45 @@ function encodeString(value) {
914
1563
  ])
915
1564
  };
916
1565
  }
1566
+ function encodeTuple(value, { param }) {
1567
+ let dynamic = false;
1568
+ let preparedParams = [];
1569
+ for (let i = 0; i < param.components.length; i++) {
1570
+ const param_ = param.components[i];
1571
+ const index = Array.isArray(value) ? i : param_.name;
1572
+ const preparedParam = prepareParam({
1573
+ param: param_,
1574
+ value: value[index]
1575
+ });
1576
+ preparedParams.push(preparedParam);
1577
+ dynamic = preparedParam.dynamic;
1578
+ }
1579
+ return {
1580
+ dynamic,
1581
+ encoded: dynamic ? encodeParams(preparedParams) : concat(preparedParams.map(({ encoded }) => encoded))
1582
+ };
1583
+ }
917
1584
  function getArrayComponents(type) {
918
1585
  const matches = type.match(/^(.*)\[(\d+)?\]$/);
919
1586
  return matches ? [matches[2] ? Number(matches[2]) : null, matches[1]] : void 0;
920
1587
  }
921
- var AbiEncodingArrayLengthMismatchError = class extends BaseError {
922
- constructor({
923
- expectedLength,
924
- givenLength,
925
- type
926
- }) {
927
- super(
928
- [
929
- `ABI encoding array length mismatch for type ${type}.`,
930
- `Expected length: ${expectedLength}`,
931
- `Given length: ${givenLength}`
932
- ].join("\n")
933
- );
934
- __publicField(this, "name", "AbiEncodingArrayLengthMismatchError");
935
- }
936
- };
937
- var AbiEncodingLengthMismatchError = class extends BaseError {
938
- constructor({
939
- expectedLength,
940
- givenLength
941
- }) {
942
- super(
943
- [
944
- "ABI encoding params/values length mismatch.",
945
- `Expected length (params): ${expectedLength}`,
946
- `Given length (values): ${givenLength}`
947
- ].join("\n")
948
- );
949
- __publicField(this, "name", "AbiEncodingLengthMismatchError");
950
- }
951
- };
952
- var InvalidAbiEncodingTypeError = class extends BaseError {
953
- constructor(type) {
954
- super(
955
- [
956
- `Type "${type}" is not a valid encoding type.`,
957
- "Please provide a valid ABI type."
958
- ].join("\n"),
959
- { docsPath: "/docs/contract/encodeAbi#params" }
960
- );
961
- __publicField(this, "name", "InvalidAbiEncodingType");
962
- }
963
- };
964
- var InvalidArrayError = class extends BaseError {
965
- constructor(value) {
966
- super([`Value "${value}" is not a valid array.`].join("\n"));
967
- __publicField(this, "name", "InvalidArrayError");
968
- }
969
- };
970
1588
 
971
1589
  // src/utils/abi/decodeAbi.ts
972
1590
  function decodeAbi({
973
1591
  data,
974
1592
  params
975
1593
  }) {
1594
+ if (data === "0x" && params.length > 0)
1595
+ throw new AbiDecodingZeroDataError();
976
1596
  if (size(data) % 32 !== 0)
977
1597
  throw new AbiDecodingDataSizeInvalidError(size(data));
978
- return decodeParams({
1598
+ const values = decodeParams({
979
1599
  data,
980
1600
  params
981
1601
  });
1602
+ if (values.length === 0)
1603
+ return void 0;
1604
+ return values;
982
1605
  }
983
1606
  function decodeParams({
984
1607
  data,
@@ -1027,7 +1650,12 @@ function decodeParam({
1027
1650
  if (param.type === "bool") {
1028
1651
  return decodeBool(value);
1029
1652
  }
1030
- throw new InvalidAbiDecodingTypeError(param.type);
1653
+ throw new InvalidAbiDecodingTypeError(param.type, {
1654
+ docsPath: "/docs/contract/decodeAbi"
1655
+ });
1656
+ }
1657
+ function decodeAddress(value) {
1658
+ return { consumed: 32, value: checksumAddress(slice(value, -20)) };
1031
1659
  }
1032
1660
  function decodeArray(data, {
1033
1661
  param,
@@ -1080,9 +1708,6 @@ function decodeArray(data, {
1080
1708
  }
1081
1709
  return { value, consumed };
1082
1710
  }
1083
- function decodeAddress(value) {
1084
- return { consumed: 32, value: checksumAddress(trim(value)) };
1085
- }
1086
1711
  function decodeBool(value) {
1087
1712
  return { consumed: 32, value: hexToBool(value) };
1088
1713
  }
@@ -1158,29 +1783,209 @@ function hasDynamicChild(param) {
1158
1783
  return true;
1159
1784
  return false;
1160
1785
  }
1161
- var AbiDecodingDataSizeInvalidError = class extends BaseError {
1162
- constructor(size2) {
1163
- super(
1164
- [
1165
- `Data size of ${size2} bytes is invalid.`,
1166
- "Size must be in increments of 32 bytes (size % 32 === 0)."
1167
- ].join("\n")
1168
- );
1169
- __publicField(this, "name", "AbiDecodingDataSizeInvalidError");
1170
- }
1171
- };
1172
- var InvalidAbiDecodingTypeError = class extends BaseError {
1173
- constructor(type) {
1174
- super(
1175
- [
1176
- `Type "${type}" is not a valid decoding type.`,
1177
- "Please provide a valid ABI type."
1178
- ].join("\n"),
1179
- { docsPath: "/docs/contract/decodeAbi#params" }
1180
- );
1181
- __publicField(this, "name", "InvalidAbiDecodingType");
1182
- }
1183
- };
1786
+
1787
+ // src/utils/abi/formatAbiItemWithParams.ts
1788
+ function formatAbiItemWithParams(abiItem, { includeName = false } = {}) {
1789
+ if (abiItem.type !== "function" && abiItem.type !== "event" && abiItem.type !== "error")
1790
+ throw new InvalidDefinitionTypeError(abiItem.type);
1791
+ return `${abiItem.name}(${getParams(abiItem.inputs, { includeName })})`;
1792
+ }
1793
+ function getParams(params, { includeName }) {
1794
+ if (!params)
1795
+ return "";
1796
+ return params.map((param) => getParam(param, { includeName })).join(includeName ? ", " : ",");
1797
+ }
1798
+ function getParam(param, { includeName }) {
1799
+ if (param.type.startsWith("tuple")) {
1800
+ return `(${getParams(
1801
+ param.components,
1802
+ { includeName }
1803
+ )})${param.type.slice("tuple".length)}`;
1804
+ }
1805
+ return param.type + (includeName && param.name ? ` ${param.name}` : "");
1806
+ }
1807
+
1808
+ // src/utils/abi/decodeErrorResult.ts
1809
+ function decodeErrorResult({ abi, data }) {
1810
+ const signature = slice(data, 0, 4);
1811
+ const description = abi.find(
1812
+ (x) => signature === getFunctionSignature(formatAbiItemWithParams(x))
1813
+ );
1814
+ if (!description)
1815
+ throw new AbiErrorSignatureNotFoundError(signature, {
1816
+ docsPath: "/docs/contract/decodeErrorResult"
1817
+ });
1818
+ return {
1819
+ errorName: description.name,
1820
+ args: "inputs" in description && description.inputs && description.inputs.length > 0 ? decodeAbi({ data: slice(data, 4), params: description.inputs }) : void 0
1821
+ };
1822
+ }
1823
+
1824
+ // src/utils/abi/decodeFunctionData.ts
1825
+ function decodeFunctionData({ abi, data }) {
1826
+ const signature = slice(data, 0, 4);
1827
+ const description = abi.find(
1828
+ (x) => signature === getFunctionSignature(formatAbiItemWithParams(x))
1829
+ );
1830
+ if (!description)
1831
+ throw new AbiFunctionSignatureNotFoundError(signature, {
1832
+ docsPath: "/docs/contract/decodeFunctionData"
1833
+ });
1834
+ return {
1835
+ functionName: description.name,
1836
+ args: "inputs" in description && description.inputs && description.inputs.length > 0 ? decodeAbi({ data: slice(data, 4), params: description.inputs }) : void 0
1837
+ };
1838
+ }
1839
+
1840
+ // src/utils/abi/decodeFunctionResult.ts
1841
+ var docsPath = "/docs/contract/decodeFunctionResult";
1842
+ function decodeFunctionResult({
1843
+ abi,
1844
+ functionName,
1845
+ data
1846
+ }) {
1847
+ const description = abi.find(
1848
+ (x) => "name" in x && x.name === functionName
1849
+ );
1850
+ if (!description)
1851
+ throw new AbiFunctionNotFoundError(functionName, { docsPath });
1852
+ if (!("outputs" in description))
1853
+ throw new AbiFunctionOutputsNotFoundError(functionName, { docsPath });
1854
+ const values = decodeAbi({ data, params: description.outputs });
1855
+ if (values && values.length > 1)
1856
+ return values;
1857
+ if (values && values.length === 1)
1858
+ return values[0];
1859
+ return void 0;
1860
+ }
1861
+
1862
+ // src/utils/abi/encodeDeployData.ts
1863
+ var docsPath2 = "/docs/contract/encodeDeployData";
1864
+ function encodeDeployData({
1865
+ abi,
1866
+ args,
1867
+ bytecode
1868
+ }) {
1869
+ if (!args || args.length === 0)
1870
+ return bytecode;
1871
+ const description = abi.find((x) => "type" in x && x.type === "constructor");
1872
+ if (!description)
1873
+ throw new AbiConstructorNotFoundError({ docsPath: docsPath2 });
1874
+ if (!("inputs" in description))
1875
+ throw new AbiConstructorParamsNotFoundError({ docsPath: docsPath2 });
1876
+ if (!description.inputs || description.inputs.length === 0)
1877
+ throw new AbiConstructorParamsNotFoundError({ docsPath: docsPath2 });
1878
+ const data = encodeAbi({
1879
+ params: description.inputs,
1880
+ values: args
1881
+ });
1882
+ return concatHex([bytecode, data]);
1883
+ }
1884
+
1885
+ // src/utils/abi/getAbiItem.ts
1886
+ function getAbiItem({ abi, name }) {
1887
+ return abi.find((x) => "name" in x && x.name === name);
1888
+ }
1889
+
1890
+ // src/utils/abi/encodeErrorResult.ts
1891
+ var docsPath3 = "/docs/contract/encodeErrorResult";
1892
+ function encodeErrorResult({ abi, errorName, args }) {
1893
+ const description = getAbiItem({ abi, name: errorName });
1894
+ if (!description)
1895
+ throw new AbiErrorNotFoundError(errorName, { docsPath: docsPath3 });
1896
+ const definition = formatAbiItemWithParams(description);
1897
+ const signature = getFunctionSignature(definition);
1898
+ let data = "0x";
1899
+ if (args && args.length > 0) {
1900
+ if (!("inputs" in description && description.inputs))
1901
+ throw new AbiErrorInputsNotFoundError(errorName, { docsPath: docsPath3 });
1902
+ data = encodeAbi({ params: description.inputs, values: args });
1903
+ }
1904
+ return concatHex([signature, data]);
1905
+ }
1906
+
1907
+ // src/utils/abi/encodeEventTopics.ts
1908
+ function encodeEventTopics({ abi, eventName, args }) {
1909
+ const abiItem = getAbiItem({ abi, name: eventName });
1910
+ if (!abiItem)
1911
+ throw new AbiEventNotFoundError(eventName, {
1912
+ docsPath: "/docs/contract/encodeEventTopics"
1913
+ });
1914
+ const definition = formatAbiItemWithParams(abiItem);
1915
+ const signature = getEventSignature(definition);
1916
+ let topics = [];
1917
+ if (args && "inputs" in abiItem) {
1918
+ const args_ = Array.isArray(args) ? args : abiItem.inputs?.map((x) => args[x.name]) ?? [];
1919
+ topics = abiItem.inputs?.filter((param) => "indexed" in param && param.indexed).map(
1920
+ (param, i) => Array.isArray(args_[i]) ? args_[i].map(
1921
+ (_, j) => encodeArg({ param, value: args_[i][j] })
1922
+ ) : args_[i] ? encodeArg({ param, value: args_[i] }) : null
1923
+ ) ?? [];
1924
+ }
1925
+ return [signature, ...topics];
1926
+ }
1927
+ function encodeArg({
1928
+ param,
1929
+ value
1930
+ }) {
1931
+ if (param.type === "string" || param.type === "bytes")
1932
+ return keccak256(encodeBytes(value));
1933
+ if (param.type === "tuple" || param.type.match(/^(.*)\[(\d+)?\]$/))
1934
+ throw new FilterTypeNotSupportedError(param.type);
1935
+ return encodeAbi({ params: [param], values: [value] });
1936
+ }
1937
+
1938
+ // src/utils/abi/encodeFunctionData.ts
1939
+ function encodeFunctionData({ abi, args, functionName }) {
1940
+ const description = getAbiItem({ abi, name: functionName });
1941
+ if (!description)
1942
+ throw new AbiFunctionNotFoundError(functionName, {
1943
+ docsPath: "/docs/contract/encodeFunctionData"
1944
+ });
1945
+ const definition = formatAbiItemWithParams(description);
1946
+ const signature = getFunctionSignature(definition);
1947
+ const data = "inputs" in description && description.inputs ? encodeAbi({
1948
+ params: description.inputs,
1949
+ values: args ?? []
1950
+ }) : void 0;
1951
+ return concatHex([signature, data ?? "0x"]);
1952
+ }
1953
+
1954
+ // src/utils/abi/encodeFunctionResult.ts
1955
+ var docsPath4 = "/docs/contract/encodeFunctionResult";
1956
+ function encodeFunctionResult({
1957
+ abi,
1958
+ functionName,
1959
+ result
1960
+ }) {
1961
+ const description = abi.find((x) => "name" in x && x.name === functionName);
1962
+ if (!description)
1963
+ throw new AbiFunctionNotFoundError(functionName, { docsPath: docsPath4 });
1964
+ if (!("outputs" in description))
1965
+ throw new AbiFunctionOutputsNotFoundError(functionName, { docsPath: docsPath4 });
1966
+ let values = Array.isArray(result) ? result : [result];
1967
+ if (description.outputs.length === 0 && !values[0])
1968
+ values = [];
1969
+ return encodeAbi({ params: description.outputs, values });
1970
+ }
1971
+
1972
+ // src/utils/abi/formatAbiItemWithArgs.ts
1973
+ function formatAbiItemWithArgs({
1974
+ abiItem,
1975
+ args,
1976
+ includeFunctionName = true,
1977
+ includeName = false
1978
+ }) {
1979
+ if (!("name" in abiItem))
1980
+ return;
1981
+ if (!("inputs" in abiItem))
1982
+ return;
1983
+ if (!abiItem.inputs)
1984
+ return;
1985
+ return `${includeFunctionName ? abiItem.name : ""}(${abiItem.inputs.map(
1986
+ (input, i) => `${includeName && input.name ? `${input.name}: ` : ""}${typeof args[i] === "object" ? stringify(args[i]) : args[i]}`
1987
+ ).join(", ")})`;
1988
+ }
1184
1989
 
1185
1990
  // src/utils/buildRequest.ts
1186
1991
  function buildRequest(request) {
@@ -1219,131 +2024,6 @@ function buildRequest(request) {
1219
2024
  }
1220
2025
  };
1221
2026
  }
1222
- var RequestError = class extends BaseError {
1223
- constructor(err, { docsPath, humanMessage }) {
1224
- super(humanMessage, {
1225
- cause: err,
1226
- docsPath
1227
- });
1228
- this.name = err.name;
1229
- }
1230
- };
1231
- var RpcRequestError = class extends RequestError {
1232
- constructor(err, { docsPath, humanMessage }) {
1233
- super(err, { docsPath, humanMessage });
1234
- __publicField(this, "code");
1235
- this.code = err.code;
1236
- this.name = err.name;
1237
- }
1238
- };
1239
- var ParseRpcError = class extends RpcRequestError {
1240
- constructor(err) {
1241
- super(err, {
1242
- humanMessage: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
1243
- });
1244
- __publicField(this, "name", "ParseRpcError");
1245
- __publicField(this, "code", -32700);
1246
- }
1247
- };
1248
- var InvalidRequestRpcError = class extends RpcRequestError {
1249
- constructor(err) {
1250
- super(err, { humanMessage: "JSON is not a valid request object." });
1251
- __publicField(this, "name", "InvalidRequestRpcError");
1252
- __publicField(this, "code", -32600);
1253
- }
1254
- };
1255
- var MethodNotFoundRpcError = class extends RpcRequestError {
1256
- constructor(err) {
1257
- super(err, {
1258
- humanMessage: "The method does not exist / is not available."
1259
- });
1260
- __publicField(this, "name", "MethodNotFoundRpcError");
1261
- __publicField(this, "code", -32601);
1262
- }
1263
- };
1264
- var InvalidParamsRpcError = class extends RpcRequestError {
1265
- constructor(err) {
1266
- super(err, {
1267
- humanMessage: [
1268
- "Invalid parameters were provided to the RPC method.",
1269
- "Double check you have provided the correct parameters."
1270
- ].join("\n")
1271
- });
1272
- __publicField(this, "name", "InvalidParamsRpcError");
1273
- __publicField(this, "code", -32602);
1274
- }
1275
- };
1276
- var InternalRpcError = class extends RpcRequestError {
1277
- constructor(err) {
1278
- super(err, { humanMessage: "An internal error was received." });
1279
- __publicField(this, "name", "InternalRpcError");
1280
- __publicField(this, "code", -32603);
1281
- }
1282
- };
1283
- var InvalidInputRpcError = class extends RpcRequestError {
1284
- constructor(err) {
1285
- super(err, {
1286
- humanMessage: [
1287
- "Missing or invalid parameters.",
1288
- "Double check you have provided the correct parameters."
1289
- ].join("\n")
1290
- });
1291
- __publicField(this, "name", "InvalidInputRpcError");
1292
- __publicField(this, "code", -32e3);
1293
- }
1294
- };
1295
- var ResourceNotFoundRpcError = class extends RpcRequestError {
1296
- constructor(err) {
1297
- super(err, { humanMessage: "Requested resource not found." });
1298
- __publicField(this, "name", "ResourceNotFoundRpcError");
1299
- __publicField(this, "code", -32001);
1300
- }
1301
- };
1302
- var ResourceUnavailableRpcError = class extends RpcRequestError {
1303
- constructor(err) {
1304
- super(err, { humanMessage: "Requested resource not available." });
1305
- __publicField(this, "name", "ResourceUnavailableRpcError");
1306
- __publicField(this, "code", -32002);
1307
- }
1308
- };
1309
- var TransactionRejectedRpcError = class extends RpcRequestError {
1310
- constructor(err) {
1311
- super(err, { humanMessage: "Transaction creation failed." });
1312
- __publicField(this, "name", "TransactionRejectedRpcError");
1313
- __publicField(this, "code", -32003);
1314
- }
1315
- };
1316
- var MethodNotSupportedRpcError = class extends RpcRequestError {
1317
- constructor(err) {
1318
- super(err, { humanMessage: "Method is not implemented." });
1319
- __publicField(this, "name", "MethodNotSupportedRpcError");
1320
- __publicField(this, "code", -32004);
1321
- }
1322
- };
1323
- var LimitExceededRpcError = class extends RpcRequestError {
1324
- constructor(err) {
1325
- super(err, { humanMessage: "Request exceeds defined limit." });
1326
- __publicField(this, "name", "LimitExceededRpcError");
1327
- __publicField(this, "code", -32005);
1328
- }
1329
- };
1330
- var JsonRpcVersionUnsupportedError = class extends RpcRequestError {
1331
- constructor(err) {
1332
- super(err, {
1333
- humanMessage: "Version of JSON-RPC protocol is not supported."
1334
- });
1335
- __publicField(this, "name", "JsonRpcVersionUnsupportedError");
1336
- __publicField(this, "code", -32006);
1337
- }
1338
- };
1339
- var UnknownRpcError = class extends RequestError {
1340
- constructor(err) {
1341
- super(err, {
1342
- humanMessage: "An unknown RPC error occurred."
1343
- });
1344
- __publicField(this, "name", "UnknownRpcError");
1345
- }
1346
- };
1347
2027
 
1348
2028
  // src/constants.ts
1349
2029
  var etherUnits = {
@@ -1597,7 +2277,7 @@ async function http(url, {
1597
2277
  "Content-Type": "application/json"
1598
2278
  },
1599
2279
  method: "POST",
1600
- body: JSON.stringify({ jsonrpc: "2.0", id: id++, ...body }),
2280
+ body: stringify({ jsonrpc: "2.0", id: id++, ...body }),
1601
2281
  signal: timeout > 0 ? signal : void 0
1602
2282
  });
1603
2283
  return response2;
@@ -1634,7 +2314,7 @@ async function http(url, {
1634
2314
  if (!response.ok) {
1635
2315
  throw new HttpRequestError({
1636
2316
  body,
1637
- details: JSON.stringify(data.error) || response.statusText,
2317
+ details: stringify(data.error) || response.statusText,
1638
2318
  status: response.status,
1639
2319
  url
1640
2320
  });
@@ -1742,92 +2422,6 @@ var rpc = {
1742
2422
  webSocket,
1743
2423
  webSocketAsync
1744
2424
  };
1745
- var HttpRequestError = class extends BaseError {
1746
- constructor({
1747
- body,
1748
- details,
1749
- status,
1750
- url
1751
- }) {
1752
- super(
1753
- [
1754
- "HTTP request failed.",
1755
- "",
1756
- `Status: ${status}`,
1757
- `URL: ${url}`,
1758
- `Request body: ${JSON.stringify(body)}`
1759
- ].join("\n"),
1760
- {
1761
- details
1762
- }
1763
- );
1764
- __publicField(this, "name", "HttpRequestError");
1765
- __publicField(this, "status");
1766
- this.status = status;
1767
- }
1768
- };
1769
- var WebSocketRequestError = class extends BaseError {
1770
- constructor({
1771
- body,
1772
- details,
1773
- url
1774
- }) {
1775
- super(
1776
- [
1777
- "WebSocket request failed.",
1778
- "",
1779
- `URL: ${url}`,
1780
- `Request body: ${JSON.stringify(body)}`
1781
- ].join("\n"),
1782
- {
1783
- details
1784
- }
1785
- );
1786
- __publicField(this, "name", "WebSocketRequestError");
1787
- }
1788
- };
1789
- var RpcError = class extends BaseError {
1790
- constructor({
1791
- body,
1792
- error,
1793
- url
1794
- }) {
1795
- super(
1796
- [
1797
- "RPC Request failed.",
1798
- "",
1799
- `URL: ${url}`,
1800
- `Request body: ${JSON.stringify(body)}`
1801
- ].join("\n"),
1802
- {
1803
- cause: error,
1804
- details: error.message
1805
- }
1806
- );
1807
- __publicField(this, "code");
1808
- __publicField(this, "name", "RpcError");
1809
- this.code = error.code;
1810
- }
1811
- };
1812
- var TimeoutError = class extends BaseError {
1813
- constructor({
1814
- body,
1815
- url
1816
- }) {
1817
- super(
1818
- [
1819
- "The request took too long to respond.",
1820
- "",
1821
- `URL: ${url}`,
1822
- `Request body: ${JSON.stringify(body)}`
1823
- ].join("\n"),
1824
- {
1825
- details: "The request timed out."
1826
- }
1827
- );
1828
- __publicField(this, "name", "TimeoutError");
1829
- }
1830
- };
1831
2425
 
1832
2426
  // src/utils/unit/formatUnit.ts
1833
2427
  function formatUnit(value, decimals) {
@@ -1887,8 +2481,49 @@ function parseGwei(ether, unit = "wei") {
1887
2481
  }
1888
2482
 
1889
2483
  export {
1890
- __publicField,
2484
+ stringify,
1891
2485
  BaseError,
2486
+ AbiConstructorNotFoundError,
2487
+ AbiConstructorParamsNotFoundError,
2488
+ AbiDecodingDataSizeInvalidError,
2489
+ AbiEncodingArrayLengthMismatchError,
2490
+ AbiEncodingLengthMismatchError,
2491
+ AbiErrorInputsNotFoundError,
2492
+ AbiErrorNotFoundError,
2493
+ AbiErrorSignatureNotFoundError,
2494
+ AbiEventNotFoundError,
2495
+ AbiFunctionNotFoundError,
2496
+ AbiFunctionOutputsNotFoundError,
2497
+ AbiFunctionSignatureNotFoundError,
2498
+ InvalidAbiEncodingTypeError,
2499
+ InvalidAbiDecodingTypeError,
2500
+ InvalidArrayError,
2501
+ InvalidDefinitionTypeError,
2502
+ InvalidAddressError,
2503
+ BlockNotFoundError,
2504
+ SizeExceedsPaddingSizeError,
2505
+ DataLengthTooLongError,
2506
+ DataLengthTooShortError,
2507
+ InvalidBytesBooleanError,
2508
+ InvalidHexBooleanError,
2509
+ InvalidHexValueError,
2510
+ OffsetOutOfBoundsError,
2511
+ FilterTypeNotSupportedError,
2512
+ RequestError,
2513
+ RpcRequestError,
2514
+ ParseRpcError,
2515
+ InvalidRequestRpcError,
2516
+ MethodNotFoundRpcError,
2517
+ InvalidParamsRpcError,
2518
+ InternalRpcError,
2519
+ InvalidInputRpcError,
2520
+ ResourceNotFoundRpcError,
2521
+ ResourceUnavailableRpcError,
2522
+ TransactionRejectedRpcError,
2523
+ MethodNotSupportedRpcError,
2524
+ LimitExceededRpcError,
2525
+ JsonRpcVersionUnsupportedError,
2526
+ UnknownRpcError,
1892
2527
  isBytes,
1893
2528
  isHex,
1894
2529
  pad,
@@ -1921,9 +2556,11 @@ export {
1921
2556
  bytesToNumber,
1922
2557
  bytesToString,
1923
2558
  decodeRlp,
2559
+ extractFunctionParts,
1924
2560
  extractFunctionName,
1925
2561
  extractFunctionParams,
1926
2562
  extractFunctionType,
2563
+ getContractError,
1927
2564
  keccak256,
1928
2565
  getEventSignature,
1929
2566
  getFunctionSignature,
@@ -1936,20 +2573,18 @@ export {
1936
2573
  isAddressEqual,
1937
2574
  encodeAbi,
1938
2575
  decodeAbi,
2576
+ formatAbiItemWithParams,
2577
+ decodeErrorResult,
2578
+ decodeFunctionData,
2579
+ decodeFunctionResult,
2580
+ encodeDeployData,
2581
+ getAbiItem,
2582
+ encodeErrorResult,
2583
+ encodeEventTopics,
2584
+ encodeFunctionData,
2585
+ encodeFunctionResult,
2586
+ formatAbiItemWithArgs,
1939
2587
  buildRequest,
1940
- RpcRequestError,
1941
- ParseRpcError,
1942
- InvalidRequestRpcError,
1943
- MethodNotFoundRpcError,
1944
- InvalidParamsRpcError,
1945
- InternalRpcError,
1946
- InvalidInputRpcError,
1947
- ResourceNotFoundRpcError,
1948
- ResourceUnavailableRpcError,
1949
- TransactionRejectedRpcError,
1950
- MethodNotSupportedRpcError,
1951
- LimitExceededRpcError,
1952
- JsonRpcVersionUnsupportedError,
1953
2588
  etherUnits,
1954
2589
  gweiUnits,
1955
2590
  weiUnits,
@@ -1966,13 +2601,19 @@ export {
1966
2601
  wait,
1967
2602
  getSocket,
1968
2603
  rpc,
1969
- HttpRequestError,
1970
- RpcError,
1971
- TimeoutError,
1972
2604
  formatUnit,
1973
2605
  formatEther,
1974
2606
  formatGwei,
1975
2607
  parseUnit,
1976
2608
  parseEther,
1977
- parseGwei
2609
+ parseGwei,
2610
+ HttpRequestError,
2611
+ WebSocketRequestError,
2612
+ RpcError,
2613
+ TimeoutError,
2614
+ InvalidGasArgumentsError,
2615
+ TransactionNotFoundError,
2616
+ TransactionReceiptNotFoundError,
2617
+ WaitForTransactionReceiptTimeoutError,
2618
+ UrlRequiredError
1978
2619
  };