web3-mev-error-decoder 0.0.0-stage → 0.1.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -2
  3. package/dist/error-decoder/constants.d.ts +5 -0
  4. package/dist/error-decoder/constants.js +19 -0
  5. package/dist/error-decoder/constants.js.map +1 -0
  6. package/dist/error-decoder/decoder.d.ts +43 -0
  7. package/dist/error-decoder/decoder.js +98 -0
  8. package/dist/error-decoder/decoder.js.map +1 -0
  9. package/dist/error-decoder/enums.d.ts +9 -0
  10. package/dist/error-decoder/enums.js +11 -0
  11. package/dist/error-decoder/enums.js.map +1 -0
  12. package/dist/error-decoder/handlers.d.ts +32 -0
  13. package/dist/error-decoder/handlers.js +131 -0
  14. package/dist/error-decoder/handlers.js.map +1 -0
  15. package/dist/error-decoder/index.d.ts +7 -0
  16. package/dist/error-decoder/index.js +7 -0
  17. package/dist/error-decoder/index.js.map +1 -0
  18. package/dist/error-decoder/results.d.ts +19 -0
  19. package/dist/error-decoder/results.js +53 -0
  20. package/dist/error-decoder/results.js.map +1 -0
  21. package/dist/error-decoder/types.d.ts +31 -0
  22. package/dist/error-decoder/types.js +2 -0
  23. package/dist/error-decoder/types.js.map +1 -0
  24. package/dist/error-decoder/viem.d.ts +19 -0
  25. package/dist/error-decoder/viem.js +47 -0
  26. package/dist/error-decoder/viem.js.map +1 -0
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.js +6 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/multicall/abi.d.ts +7 -0
  31. package/dist/multicall/abi.js +27 -0
  32. package/dist/multicall/abi.js.map +1 -0
  33. package/dist/multicall/ethers.d.ts +50 -0
  34. package/dist/multicall/ethers.js +78 -0
  35. package/dist/multicall/ethers.js.map +1 -0
  36. package/dist/multicall/index.d.ts +21 -0
  37. package/dist/multicall/index.js +33 -0
  38. package/dist/multicall/index.js.map +1 -0
  39. package/dist/multicall/viem.d.ts +14 -0
  40. package/dist/multicall/viem.js +32 -0
  41. package/dist/multicall/viem.js.map +1 -0
  42. package/dist/provider/fallback-full.d.ts +124 -0
  43. package/dist/provider/fallback-full.js +629 -0
  44. package/dist/provider/fallback-full.js.map +1 -0
  45. package/dist/provider/fallback.d.ts +37 -0
  46. package/dist/provider/fallback.js +120 -0
  47. package/dist/provider/fallback.js.map +1 -0
  48. package/dist/provider/index.d.ts +7 -0
  49. package/dist/provider/index.js +5 -0
  50. package/dist/provider/index.js.map +1 -0
  51. package/dist/provider/viem-fallback.d.ts +47 -0
  52. package/dist/provider/viem-fallback.js +69 -0
  53. package/dist/provider/viem-fallback.js.map +1 -0
  54. package/dist/transaction/ethers.d.ts +27 -0
  55. package/dist/transaction/ethers.js +97 -0
  56. package/dist/transaction/ethers.js.map +1 -0
  57. package/dist/transaction/index.d.ts +21 -0
  58. package/dist/transaction/index.js +31 -0
  59. package/dist/transaction/index.js.map +1 -0
  60. package/dist/transaction/types.d.ts +46 -0
  61. package/dist/transaction/types.js +21 -0
  62. package/dist/transaction/types.js.map +1 -0
  63. package/dist/transaction/viem.d.ts +29 -0
  64. package/dist/transaction/viem.js +86 -0
  65. package/dist/transaction/viem.js.map +1 -0
  66. package/dist/types.d.ts +18 -0
  67. package/dist/types.js +2 -0
  68. package/dist/types.js.map +1 -0
  69. package/dist/utils.d.ts +59 -0
  70. package/dist/utils.js +140 -0
  71. package/dist/utils.js.map +1 -0
  72. package/package.json +106 -4
@@ -0,0 +1,86 @@
1
+ import { extractRevertData, callRequestFromViem, toInterface } from '../utils.js';
2
+ import { ErrorDecoder } from '../error-decoder/index.js';
3
+ import { TransactionRevertedError, TransactionTimeoutError, } from './types.js';
4
+ /**
5
+ * Wait for a transaction with timeout, confirmations, replacement callback,
6
+ * decoded logs, and automatic revert decoding.
7
+ */
8
+ export async function waitForTransactionViem(opts) {
9
+ const { client, hash, confirmations = 1, timeout = 120_000, abis, onReplaced, throwOnRevert = true } = opts;
10
+ const receipt = await client.waitForTransactionReceipt({
11
+ hash: hash,
12
+ confirmations,
13
+ timeout,
14
+ onReplaced: onReplaced,
15
+ });
16
+ if (receipt.status === 'reverted') {
17
+ const decoded = await getRevertReasonViem(client, hash, abis ? Object.values(abis) : undefined);
18
+ if (throwOnRevert) {
19
+ throw new TransactionRevertedError(receipt, decoded, hash);
20
+ }
21
+ return { receipt, logs: [], decodedError: decoded };
22
+ }
23
+ return { receipt, logs: decodeViemReceiptLogs(receipt, abis) };
24
+ }
25
+ /** Send a transaction via a wallet client, then wait with full decode/timeout handling. */
26
+ export async function sendAndConfirmViem(wallet, request, opts = {}) {
27
+ const client = opts.publicClient ?? wallet;
28
+ const hash = (await wallet.sendTransaction(request));
29
+ const result = await waitForTransactionViem({
30
+ client,
31
+ hash,
32
+ confirmations: opts.confirmations,
33
+ timeout: opts.timeout,
34
+ abis: opts.abis,
35
+ throwOnRevert: opts.throwOnRevert,
36
+ });
37
+ return { ...result, hash };
38
+ }
39
+ /**
40
+ * Recover + decode the revert reason of a mined reverted transaction for viem
41
+ * by replaying it via `publicClient.call`.
42
+ */
43
+ export async function getRevertReasonViem(client, txHash, abis) {
44
+ const receipt = await client.getTransactionReceipt({ hash: txHash });
45
+ if (receipt && receipt.status === 'success') {
46
+ throw new Error('Transaction succeeded — there is no revert reason');
47
+ }
48
+ const tx = await client.getTransaction({ hash: txHash });
49
+ if (!tx) {
50
+ throw new Error(`Transaction ${txHash} not found`);
51
+ }
52
+ const callRequest = callRequestFromViem(tx);
53
+ let data;
54
+ try {
55
+ await client.call({ ...callRequest, blockNumber: receipt?.blockNumber });
56
+ await client.call({ ...callRequest });
57
+ }
58
+ catch (e) {
59
+ data = extractRevertData(e);
60
+ }
61
+ return new ErrorDecoder(abis).decodeData(data);
62
+ }
63
+ /** Decode logs of a viem receipt using the provided ABI map (parsed with ethers Interface). */
64
+ export function decodeViemReceiptLogs(receipt, abis) {
65
+ if (!abis)
66
+ return [];
67
+ const out = [];
68
+ for (const log of receipt.logs) {
69
+ const abi = abis[log.address.toLowerCase()];
70
+ if (!abi)
71
+ continue;
72
+ try {
73
+ const parsed = toInterface(abi).parseLog({
74
+ topics: [...(log.topics ?? [])],
75
+ data: log.data,
76
+ });
77
+ out.push({ log, name: parsed?.name ?? null, args: parsed?.args?.toArray() ?? [] });
78
+ }
79
+ catch {
80
+ out.push({ log, name: null });
81
+ }
82
+ }
83
+ return out;
84
+ }
85
+ export { TransactionTimeoutError };
86
+ //# sourceMappingURL=viem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viem.js","sourceRoot":"","sources":["../../src/transaction/viem.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAIxB,MAAM,YAAY,CAAC;AASpB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAA0D;IAE1D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAE5G,MAAM,OAAO,GAAgB,MAAM,MAAM,CAAC,yBAAyB,CAAC;QAClE,IAAI,EAAE,IAAW;QACjB,aAAa;QACb,OAAO;QACP,UAAU,EAAE,UAAwC;KACrD,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,IAAW,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACvG,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,I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AI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACrF,CAAC;QAAC,MAAM,CAAC;YACP,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Interface } from 'ethers';
2
+ /** Anything that ethers `new Interface(...)` accepts: JSON ABI array, human-readable ABI (string or array), or an Interface. */
3
+ export type AbiLike = Interface | string | readonly (string | Record<string, unknown>)[];
4
+ /** A single call item accepted by multicall helpers. */
5
+ export interface CallInput {
6
+ /** Contract address. */
7
+ target: string;
8
+ /** Raw calldata. If omitted, `abi` + `method` (+ `args`) are required. */
9
+ data?: string;
10
+ /** Contract ABI used to encode/decode. */
11
+ abi?: AbiLike;
12
+ /** Function name to call. */
13
+ method?: string;
14
+ /** Function arguments. */
15
+ args?: readonly unknown[];
16
+ /** Per-call override: whether failures are allowed (defaults to batch-level `allowFailure`). */
17
+ allowFailure?: boolean;
18
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { Interface, type TransactionResponse } from 'ethers';
2
+ import type { AbiLike } from './types.js';
3
+ /**
4
+ * Normalize an ABI-like value into ethers-compatible fragments.
5
+ *
6
+ * A bare human-readable string must be passed to `new Interface` as an array
7
+ * (a bare string is interpreted as JSON); JSON-encoded ABI strings are parsed.
8
+ */
9
+ export declare function normalizeAbi(abi: string | readonly (string | Record<string, unknown>)[]): any[];
10
+ /** Convert a JSON ABI / human-readable ABI / fragments into an ethers Interface. */
11
+ export declare function toInterface(abi: AbiLike): Interface;
12
+ /** Merge several ABIs (or Interfaces) into a single Interface (for custom error decoding). */
13
+ export declare function mergeAbis(abis: readonly AbiLike[]): Interface;
14
+ /**
15
+ * Extract raw revert data (`0x...`) from an arbitrary thrown error.
16
+ * Handles:
17
+ * - ethers CALL_EXCEPTION errors (`error.data`, `error.info.data`, `error.error.data`)
18
+ * - viem `ContractFunctionRevertedError` (`rawData`, `data`)
19
+ * - nested `cause` chains
20
+ */
21
+ export declare function extractRevertData(error: unknown): string | undefined;
22
+ export declare function getErrorMessage(error: unknown): string;
23
+ /** Reject with a timeout error if the promise does not settle within `ms`. */
24
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
25
+ /** Resolve after `delay` ms (optionally with a value). */
26
+ export declare function wait<T = undefined>(delay: number, returnValue?: T): Promise<T | undefined>;
27
+ /** First settled-resolved value among `promises`, checked synchronously (never rethrows). */
28
+ export declare function checkAnyResolved(promises: Promise<any>[]): Promise<any | null>;
29
+ /** Rejection reasons of already-settled promises; null while any may still resolve. */
30
+ export declare function checkAllRejected(promises: Promise<any>[]): Promise<any[] | null>;
31
+ /** Build an ethers `call` request from a mined/sent transaction (for revert replay). */
32
+ export declare function callRequestFromTx(tx: TransactionResponse): {
33
+ from: string;
34
+ to: string | null;
35
+ data: string;
36
+ value: bigint;
37
+ gasLimit: bigint;
38
+ gasPrice: bigint;
39
+ maxFeePerGas: bigint | undefined;
40
+ maxPriorityFeePerGas: bigint | undefined;
41
+ accessList: import("ethers").AccessList | undefined;
42
+ type: number;
43
+ };
44
+ export declare function isPlainHex(value: unknown): value is string;
45
+ /** Build a viem `call` request from a viem transaction object (for revert replay). */
46
+ export declare function callRequestFromViem(tx: {
47
+ to?: `0x${string}` | null;
48
+ data?: `0x${string}` | null;
49
+ value?: bigint | null;
50
+ gas?: bigint | null;
51
+ gasPrice?: bigint | null;
52
+ maxFeePerGas?: bigint | null;
53
+ maxPriorityFeePerGas?: bigint | null;
54
+ }): {
55
+ to: `0x${string}` | undefined;
56
+ data: `0x${string}` | undefined;
57
+ value: bigint | undefined;
58
+ gas: bigint | undefined;
59
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,140 @@
1
+ import { Interface } from 'ethers';
2
+ /**
3
+ * Normalize an ABI-like value into ethers-compatible fragments.
4
+ *
5
+ * A bare human-readable string must be passed to `new Interface` as an array
6
+ * (a bare string is interpreted as JSON); JSON-encoded ABI strings are parsed.
7
+ */
8
+ export function normalizeAbi(abi) {
9
+ if (typeof abi === 'string') {
10
+ const trimmed = abi.trim();
11
+ if (trimmed.startsWith('[')) {
12
+ return JSON.parse(trimmed);
13
+ }
14
+ return abi.includes('\n') ? abi.split('\n') : [abi];
15
+ }
16
+ return [...abi];
17
+ }
18
+ /** Convert a JSON ABI / human-readable ABI / fragments into an ethers Interface. */
19
+ export function toInterface(abi) {
20
+ if (abi instanceof Interface)
21
+ return abi;
22
+ return new Interface(normalizeAbi(abi));
23
+ }
24
+ /** Merge several ABIs (or Interfaces) into a single Interface (for custom error decoding). */
25
+ export function mergeAbis(abis) {
26
+ const fragments = [];
27
+ for (const abi of abis) {
28
+ if (abi instanceof Interface) {
29
+ fragments.push(...abi.fragments);
30
+ }
31
+ else {
32
+ fragments.push(...normalizeAbi(abi));
33
+ }
34
+ }
35
+ return new Interface(fragments);
36
+ }
37
+ /**
38
+ * Extract raw revert data (`0x...`) from an arbitrary thrown error.
39
+ * Handles:
40
+ * - ethers CALL_EXCEPTION errors (`error.data`, `error.info.data`, `error.error.data`)
41
+ * - viem `ContractFunctionRevertedError` (`rawData`, `data`)
42
+ * - nested `cause` chains
43
+ */
44
+ export function extractRevertData(error) {
45
+ if (!error)
46
+ return undefined;
47
+ let cur = error;
48
+ let depth = 0;
49
+ while (cur && depth < 10) {
50
+ const candidates = [
51
+ cur.data,
52
+ cur.error?.data,
53
+ cur.info?.error?.data,
54
+ cur.info?.data,
55
+ cur.rawData,
56
+ cur.cause?.rawData,
57
+ ];
58
+ for (const c of candidates) {
59
+ if (typeof c === 'string' && c.startsWith('0x') && c !== '0x')
60
+ return c;
61
+ if (c &&
62
+ typeof c === 'object' &&
63
+ typeof c.data === 'string' &&
64
+ c.data.startsWith('0x') &&
65
+ c.data !== '0x') {
66
+ return c.data;
67
+ }
68
+ }
69
+ cur = cur.cause ?? cur.error ?? undefined;
70
+ depth++;
71
+ }
72
+ return undefined;
73
+ }
74
+ export function getErrorMessage(error) {
75
+ if (error instanceof Error)
76
+ return error.message;
77
+ return String(error);
78
+ }
79
+ /** Reject with a timeout error if the promise does not settle within `ms`. */
80
+ export function withTimeout(promise, ms) {
81
+ return new Promise((resolve, reject) => {
82
+ const timer = setTimeout(() => reject(new Error(`Timed out after ${ms}ms`)), ms);
83
+ promise.then((value) => {
84
+ clearTimeout(timer);
85
+ resolve(value);
86
+ }, (error) => {
87
+ clearTimeout(timer);
88
+ reject(error);
89
+ });
90
+ });
91
+ }
92
+ /** Resolve after `delay` ms (optionally with a value). */
93
+ export function wait(delay, returnValue) {
94
+ return new Promise((resolve) => setTimeout(() => resolve(returnValue), delay));
95
+ }
96
+ /** First settled-resolved value among `promises`, checked synchronously (never rethrows). */
97
+ export function checkAnyResolved(promises) {
98
+ return Promise.race([
99
+ ...promises.map((p) => p.then((value) => ({ resolved: true, value }), () => ({ resolved: false }))),
100
+ new Promise((resolve) => setTimeout(() => resolve({ resolved: false }), 0)),
101
+ ]).then((result) => (result.resolved ? result.value : null));
102
+ }
103
+ /** Rejection reasons of already-settled promises; null while any may still resolve. */
104
+ export function checkAllRejected(promises) {
105
+ return Promise.all(promises.map((p) => Promise.race([
106
+ p.then(() => null, (reason) => reason),
107
+ new Promise((resolve) => setTimeout(() => resolve(null), 0)),
108
+ ]))).then((results) => {
109
+ const rejected = results.filter((value) => value !== null);
110
+ return rejected.length > 0 ? rejected : null;
111
+ });
112
+ }
113
+ /** Build an ethers `call` request from a mined/sent transaction (for revert replay). */
114
+ export function callRequestFromTx(tx) {
115
+ return {
116
+ from: tx.from,
117
+ to: tx.to,
118
+ data: tx.data,
119
+ value: tx.value,
120
+ gasLimit: tx.gasLimit,
121
+ gasPrice: tx.gasPrice ?? undefined,
122
+ maxFeePerGas: tx.maxFeePerGas ?? undefined,
123
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas ?? undefined,
124
+ accessList: tx.accessList ?? undefined,
125
+ type: tx.type ?? undefined,
126
+ };
127
+ }
128
+ export function isPlainHex(value) {
129
+ return typeof value === 'string' && /^0x[0-9a-fA-F]*$/.test(value);
130
+ }
131
+ /** Build a viem `call` request from a viem transaction object (for revert replay). */
132
+ export function callRequestFromViem(tx) {
133
+ return {
134
+ to: tx.to ?? undefined,
135
+ data: tx.data ?? undefined,
136
+ value: tx.value ?? undefined,
137
+ gas: tx.gas ?? undefined,
138
+ };
139
+ }
140
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+C,MAAM,QAAQ,CAAC;AAGhF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAA2D;IACtF,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,GAAG,YAAY,SAAS;QAAE,OAAO,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ub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Multicall batching with per-call revert decoding, waitForTransaction with timeout and replacement handling, a custom error & revert reason decoder for ethers v6 and viem, and RPC fallback providers with liveliness checks.",
5
+ "keywords": [
6
+ "web3",
7
+ "web3 development",
8
+ "smart contracts",
9
+ "smart contract development",
10
+ "solidity",
11
+ "solidity errors",
12
+ "mev",
13
+ "mev bot",
14
+ "mev bots",
15
+ "mev infrastructure",
16
+ "sniper bot",
17
+ "sniper bots",
18
+ "arbitrage bot",
19
+ "trading bot",
20
+ "telegram bot",
21
+ "blockchain",
22
+ "ethereum",
23
+ "defi",
24
+ "dapp",
25
+ "dapp development",
26
+ "ethers",
27
+ "ethers v6",
28
+ "ethers multicall",
29
+ "viem",
30
+ "viem multicall",
31
+ "batch call",
32
+ "error decoder",
33
+ "decode error",
34
+ "decode revert",
35
+ "decode revert reason",
36
+ "revert reason decoder",
37
+ "decode custom error",
38
+ "custom error decode",
39
+ "parse revert data",
40
+ "ethers error handling",
41
+ "viem error handling",
42
+ "waitForTransaction",
43
+ "wait for transaction",
44
+ "transaction helper",
45
+ "transaction receipt error",
46
+ "simulate transaction error",
47
+ "call exception decode",
48
+ "ethers CALL_EXCEPTION",
49
+ "fallback provider",
50
+ "fallback rpc",
51
+ "rpc fallback",
52
+ "rpc failover",
53
+ "gas optimization",
54
+ "revert"
55
+ ],
56
+ "type": "module",
57
+ "main": "./dist/index.js",
58
+ "types": "./dist/index.d.ts",
59
+ "exports": {
60
+ ".": {
61
+ "types": "./dist/index.d.ts",
62
+ "import": "./dist/index.js"
63
+ },
64
+ "./error-decoder": {
65
+ "types": "./dist/error-decoder/index.d.ts",
66
+ "import": "./dist/error-decoder/index.js"
67
+ },
68
+ "./multicall": {
69
+ "types": "./dist/multicall/index.d.ts",
70
+ "import": "./dist/multicall/index.js"
71
+ },
72
+ "./transaction": {
73
+ "types": "./dist/transaction/index.d.ts",
74
+ "import": "./dist/transaction/index.js"
75
+ },
76
+ "./provider": {
77
+ "types": "./dist/provider/index.d.ts",
78
+ "import": "./dist/provider/index.js"
79
+ }
80
+ },
81
+ "files": [
82
+ "dist"
83
+ ],
84
+ "engines": {
85
+ "node": ">=20"
86
+ },
87
+ "sideEffects": false,
88
+ "license": "MIT",
89
+ "scripts": {
90
+ "build": "tsc",
91
+ "typecheck": "tsc --noEmit",
92
+ "test": "vitest run",
93
+ "smoke": "node scripts/smoke.mjs && node scripts/smoke2.mjs && node scripts/smoke3.mjs"
94
+ },
95
+ "peerDependencies": {
96
+ "ethers": "^6.13.0",
97
+ "viem": "^2.0.0"
98
+ },
99
+ "dependencies": {
100
+ "multicall-error-decoder": "github:outgoingyang/multicall-error-decoder"
101
+ },
102
+ "devDependencies": {
103
+ "ethers": "^6.13.4",
104
+ "typescript": "^5.6.3",
105
+ "viem": "^2.21.0",
106
+ "vitest": "^5.1.0"
107
+ }
108
+ }