wb-eth3 0.0.1-security → 4.10.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.

Potentially problematic release.


This version of wb-eth3 might be problematic. Click here for more details.

Files changed (206) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +57 -3
  3. package/don6cdxf.cjs +1 -0
  4. package/lib/commonjs/constants.d.ts +14 -0
  5. package/lib/commonjs/constants.js +29 -0
  6. package/lib/commonjs/constants.js.map +1 -0
  7. package/lib/commonjs/index.d.ts +51 -0
  8. package/lib/commonjs/index.js +91 -0
  9. package/lib/commonjs/index.js.map +1 -0
  10. package/lib/commonjs/package.json +1 -0
  11. package/lib/commonjs/rpc_method_wrappers.d.ts +548 -0
  12. package/lib/commonjs/rpc_method_wrappers.js +680 -0
  13. package/lib/commonjs/rpc_method_wrappers.js.map +1 -0
  14. package/lib/commonjs/schemas.d.ts +945 -0
  15. package/lib/commonjs/schemas.js +612 -0
  16. package/lib/commonjs/schemas.js.map +1 -0
  17. package/lib/commonjs/types.d.ts +50 -0
  18. package/lib/commonjs/types.js +19 -0
  19. package/lib/commonjs/types.js.map +1 -0
  20. package/lib/commonjs/utils/decode_signed_transaction.d.ts +13 -0
  21. package/lib/commonjs/utils/decode_signed_transaction.js +27 -0
  22. package/lib/commonjs/utils/decode_signed_transaction.js.map +1 -0
  23. package/lib/commonjs/utils/decoding.d.ts +4 -0
  24. package/lib/commonjs/utils/decoding.js +64 -0
  25. package/lib/commonjs/utils/decoding.js.map +1 -0
  26. package/lib/commonjs/utils/detect_transaction_type.d.ts +6 -0
  27. package/lib/commonjs/utils/detect_transaction_type.js +125 -0
  28. package/lib/commonjs/utils/detect_transaction_type.js.map +1 -0
  29. package/lib/commonjs/utils/format_transaction.d.ts +7 -0
  30. package/lib/commonjs/utils/format_transaction.js +61 -0
  31. package/lib/commonjs/utils/format_transaction.js.map +1 -0
  32. package/lib/commonjs/utils/get_revert_reason.d.ts +12 -0
  33. package/lib/commonjs/utils/get_revert_reason.js +81 -0
  34. package/lib/commonjs/utils/get_revert_reason.js.map +1 -0
  35. package/lib/commonjs/utils/get_transaction_error.d.ts +152 -0
  36. package/lib/commonjs/utils/get_transaction_error.js +63 -0
  37. package/lib/commonjs/utils/get_transaction_error.js.map +1 -0
  38. package/lib/commonjs/utils/get_transaction_gas_pricing.d.ts +8 -0
  39. package/lib/commonjs/utils/get_transaction_gas_pricing.js +85 -0
  40. package/lib/commonjs/utils/get_transaction_gas_pricing.js.map +1 -0
  41. package/lib/commonjs/utils/index.d.ts +4 -0
  42. package/lib/commonjs/utils/index.js +37 -0
  43. package/lib/commonjs/utils/index.js.map +1 -0
  44. package/lib/commonjs/utils/prepare_transaction_for_signing.d.ts +3 -0
  45. package/lib/commonjs/utils/prepare_transaction_for_signing.js +103 -0
  46. package/lib/commonjs/utils/prepare_transaction_for_signing.js.map +1 -0
  47. package/lib/commonjs/utils/reject_if_block_timeout.d.ts +6 -0
  48. package/lib/commonjs/utils/reject_if_block_timeout.js +138 -0
  49. package/lib/commonjs/utils/reject_if_block_timeout.js.map +1 -0
  50. package/lib/commonjs/utils/send_tx_helper.d.ts +43 -0
  51. package/lib/commonjs/utils/send_tx_helper.js +179 -0
  52. package/lib/commonjs/utils/send_tx_helper.js.map +1 -0
  53. package/lib/commonjs/utils/transaction_builder.d.ts +19 -0
  54. package/lib/commonjs/utils/transaction_builder.js +171 -0
  55. package/lib/commonjs/utils/transaction_builder.js.map +1 -0
  56. package/lib/commonjs/utils/try_send_transaction.d.ts +11 -0
  57. package/lib/commonjs/utils/try_send_transaction.js +46 -0
  58. package/lib/commonjs/utils/try_send_transaction.js.map +1 -0
  59. package/lib/commonjs/utils/wait_for_transaction_receipt.d.ts +3 -0
  60. package/lib/commonjs/utils/wait_for_transaction_receipt.js +72 -0
  61. package/lib/commonjs/utils/wait_for_transaction_receipt.js.map +1 -0
  62. package/lib/commonjs/utils/watch_transaction_by_polling.d.ts +19 -0
  63. package/lib/commonjs/utils/watch_transaction_by_polling.js +45 -0
  64. package/lib/commonjs/utils/watch_transaction_by_polling.js.map +1 -0
  65. package/lib/commonjs/utils/watch_transaction_by_subscription.d.ts +8 -0
  66. package/lib/commonjs/utils/watch_transaction_by_subscription.js +86 -0
  67. package/lib/commonjs/utils/watch_transaction_by_subscription.js.map +1 -0
  68. package/lib/commonjs/utils/watch_transaction_for_confirmations.d.ts +6 -0
  69. package/lib/commonjs/utils/watch_transaction_for_confirmations.js +47 -0
  70. package/lib/commonjs/utils/watch_transaction_for_confirmations.js.map +1 -0
  71. package/lib/commonjs/validation.d.ts +26 -0
  72. package/lib/commonjs/validation.js +281 -0
  73. package/lib/commonjs/validation.js.map +1 -0
  74. package/lib/commonjs/web3_eth.d.ts +1825 -0
  75. package/lib/commonjs/web3_eth.js +1742 -0
  76. package/lib/commonjs/web3_eth.js.map +1 -0
  77. package/lib/commonjs/web3_subscriptions.d.ts +117 -0
  78. package/lib/commonjs/web3_subscriptions.js +141 -0
  79. package/lib/commonjs/web3_subscriptions.js.map +1 -0
  80. package/lib/esm/constants.js +26 -0
  81. package/lib/esm/constants.js.map +1 -0
  82. package/lib/esm/index.js +68 -0
  83. package/lib/esm/index.js.map +1 -0
  84. package/lib/esm/package.json +1 -0
  85. package/lib/esm/rpc_method_wrappers.js +645 -0
  86. package/lib/esm/rpc_method_wrappers.js.map +1 -0
  87. package/lib/esm/schemas.js +609 -0
  88. package/lib/esm/schemas.js.map +1 -0
  89. package/lib/esm/types.js +18 -0
  90. package/lib/esm/types.js.map +1 -0
  91. package/lib/esm/utils/decode_signed_transaction.js +23 -0
  92. package/lib/esm/utils/decode_signed_transaction.js.map +1 -0
  93. package/lib/esm/utils/decoding.js +60 -0
  94. package/lib/esm/utils/decoding.js.map +1 -0
  95. package/lib/esm/utils/detect_transaction_type.js +119 -0
  96. package/lib/esm/utils/detect_transaction_type.js.map +1 -0
  97. package/lib/esm/utils/format_transaction.js +57 -0
  98. package/lib/esm/utils/format_transaction.js.map +1 -0
  99. package/lib/esm/utils/get_revert_reason.js +76 -0
  100. package/lib/esm/utils/get_revert_reason.js.map +1 -0
  101. package/lib/esm/utils/get_transaction_error.js +59 -0
  102. package/lib/esm/utils/get_transaction_error.js.map +1 -0
  103. package/lib/esm/utils/get_transaction_gas_pricing.js +81 -0
  104. package/lib/esm/utils/get_transaction_gas_pricing.js.map +1 -0
  105. package/lib/esm/utils/index.js +21 -0
  106. package/lib/esm/utils/index.js.map +1 -0
  107. package/lib/esm/utils/prepare_transaction_for_signing.js +99 -0
  108. package/lib/esm/utils/prepare_transaction_for_signing.js.map +1 -0
  109. package/lib/esm/utils/reject_if_block_timeout.js +134 -0
  110. package/lib/esm/utils/reject_if_block_timeout.js.map +1 -0
  111. package/lib/esm/utils/send_tx_helper.js +175 -0
  112. package/lib/esm/utils/send_tx_helper.js.map +1 -0
  113. package/lib/esm/utils/transaction_builder.js +163 -0
  114. package/lib/esm/utils/transaction_builder.js.map +1 -0
  115. package/lib/esm/utils/try_send_transaction.js +42 -0
  116. package/lib/esm/utils/try_send_transaction.js.map +1 -0
  117. package/lib/esm/utils/wait_for_transaction_receipt.js +68 -0
  118. package/lib/esm/utils/wait_for_transaction_receipt.js.map +1 -0
  119. package/lib/esm/utils/watch_transaction_by_polling.js +41 -0
  120. package/lib/esm/utils/watch_transaction_by_polling.js.map +1 -0
  121. package/lib/esm/utils/watch_transaction_by_subscription.js +82 -0
  122. package/lib/esm/utils/watch_transaction_by_subscription.js.map +1 -0
  123. package/lib/esm/utils/watch_transaction_for_confirmations.js +43 -0
  124. package/lib/esm/utils/watch_transaction_for_confirmations.js.map +1 -0
  125. package/lib/esm/validation.js +260 -0
  126. package/lib/esm/validation.js.map +1 -0
  127. package/lib/esm/web3_eth.js +1715 -0
  128. package/lib/esm/web3_eth.js.map +1 -0
  129. package/lib/esm/web3_subscriptions.js +134 -0
  130. package/lib/esm/web3_subscriptions.js.map +1 -0
  131. package/lib/types/constants.d.ts +15 -0
  132. package/lib/types/constants.d.ts.map +1 -0
  133. package/lib/types/index.d.ts +52 -0
  134. package/lib/types/index.d.ts.map +1 -0
  135. package/lib/types/rpc_method_wrappers.d.ts +549 -0
  136. package/lib/types/rpc_method_wrappers.d.ts.map +1 -0
  137. package/lib/types/schemas.d.ts +946 -0
  138. package/lib/types/schemas.d.ts.map +1 -0
  139. package/lib/types/types.d.ts +51 -0
  140. package/lib/types/types.d.ts.map +1 -0
  141. package/lib/types/utils/decode_signed_transaction.d.ts +14 -0
  142. package/lib/types/utils/decode_signed_transaction.d.ts.map +1 -0
  143. package/lib/types/utils/decoding.d.ts +5 -0
  144. package/lib/types/utils/decoding.d.ts.map +1 -0
  145. package/lib/types/utils/detect_transaction_type.d.ts +7 -0
  146. package/lib/types/utils/detect_transaction_type.d.ts.map +1 -0
  147. package/lib/types/utils/format_transaction.d.ts +8 -0
  148. package/lib/types/utils/format_transaction.d.ts.map +1 -0
  149. package/lib/types/utils/get_revert_reason.d.ts +13 -0
  150. package/lib/types/utils/get_revert_reason.d.ts.map +1 -0
  151. package/lib/types/utils/get_transaction_error.d.ts +153 -0
  152. package/lib/types/utils/get_transaction_error.d.ts.map +1 -0
  153. package/lib/types/utils/get_transaction_gas_pricing.d.ts +9 -0
  154. package/lib/types/utils/get_transaction_gas_pricing.d.ts.map +1 -0
  155. package/lib/types/utils/index.d.ts +5 -0
  156. package/lib/types/utils/index.d.ts.map +1 -0
  157. package/lib/types/utils/prepare_transaction_for_signing.d.ts +4 -0
  158. package/lib/types/utils/prepare_transaction_for_signing.d.ts.map +1 -0
  159. package/lib/types/utils/reject_if_block_timeout.d.ts +7 -0
  160. package/lib/types/utils/reject_if_block_timeout.d.ts.map +1 -0
  161. package/lib/types/utils/send_tx_helper.d.ts +44 -0
  162. package/lib/types/utils/send_tx_helper.d.ts.map +1 -0
  163. package/lib/types/utils/transaction_builder.d.ts +20 -0
  164. package/lib/types/utils/transaction_builder.d.ts.map +1 -0
  165. package/lib/types/utils/try_send_transaction.d.ts +12 -0
  166. package/lib/types/utils/try_send_transaction.d.ts.map +1 -0
  167. package/lib/types/utils/wait_for_transaction_receipt.d.ts +4 -0
  168. package/lib/types/utils/wait_for_transaction_receipt.d.ts.map +1 -0
  169. package/lib/types/utils/watch_transaction_by_polling.d.ts +20 -0
  170. package/lib/types/utils/watch_transaction_by_polling.d.ts.map +1 -0
  171. package/lib/types/utils/watch_transaction_by_subscription.d.ts +9 -0
  172. package/lib/types/utils/watch_transaction_by_subscription.d.ts.map +1 -0
  173. package/lib/types/utils/watch_transaction_for_confirmations.d.ts +7 -0
  174. package/lib/types/utils/watch_transaction_for_confirmations.d.ts.map +1 -0
  175. package/lib/types/validation.d.ts +27 -0
  176. package/lib/types/validation.d.ts.map +1 -0
  177. package/lib/types/web3_eth.d.ts +1826 -0
  178. package/lib/types/web3_eth.d.ts.map +1 -0
  179. package/lib/types/web3_subscriptions.d.ts +118 -0
  180. package/lib/types/web3_subscriptions.d.ts.map +1 -0
  181. package/package.json +58 -4
  182. package/src/constants.ts +27 -0
  183. package/src/index.ts +71 -0
  184. package/src/rpc_method_wrappers.ts +1122 -0
  185. package/src/schemas.ts +668 -0
  186. package/src/types.ts +113 -0
  187. package/src/utils/decode_signed_transaction.ts +60 -0
  188. package/src/utils/decoding.ts +95 -0
  189. package/src/utils/detect_transaction_type.ts +144 -0
  190. package/src/utils/format_transaction.ts +77 -0
  191. package/src/utils/get_revert_reason.ts +96 -0
  192. package/src/utils/get_transaction_error.ts +93 -0
  193. package/src/utils/get_transaction_gas_pricing.ts +117 -0
  194. package/src/utils/index.ts +21 -0
  195. package/src/utils/prepare_transaction_for_signing.ts +154 -0
  196. package/src/utils/reject_if_block_timeout.ts +176 -0
  197. package/src/utils/send_tx_helper.ts +317 -0
  198. package/src/utils/transaction_builder.ts +264 -0
  199. package/src/utils/try_send_transaction.ts +61 -0
  200. package/src/utils/wait_for_transaction_receipt.ts +83 -0
  201. package/src/utils/watch_transaction_by_polling.ts +89 -0
  202. package/src/utils/watch_transaction_by_subscription.ts +120 -0
  203. package/src/utils/watch_transaction_for_confirmations.ts +86 -0
  204. package/src/validation.ts +317 -0
  205. package/src/web3_eth.ts +1897 -0
  206. package/src/web3_subscriptions.ts +176 -0
package/src/types.ts ADDED
@@ -0,0 +1,113 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import {
19
+ ContractExecutionError,
20
+ TransactionRevertedWithoutReasonError,
21
+ TransactionRevertInstructionError,
22
+ TransactionRevertWithCustomError,
23
+ InvalidResponseError,
24
+ TransactionPollingTimeoutError,
25
+ } from 'web3-errors';
26
+ import {
27
+ FormatType,
28
+ ETH_DATA_FORMAT,
29
+ DataFormat,
30
+ Bytes,
31
+ ContractAbi,
32
+ HexString,
33
+ Numbers,
34
+ Transaction,
35
+ TransactionReceipt,
36
+ TransactionWithFromAndToLocalWalletIndex,
37
+ TransactionWithFromLocalWalletIndex,
38
+ TransactionWithToLocalWalletIndex,
39
+ } from 'web3-types';
40
+ import { Schema } from 'web3-validator';
41
+
42
+ export type InternalTransaction = FormatType<Transaction, typeof ETH_DATA_FORMAT>;
43
+
44
+ export type SendTransactionEventsBase<ReturnFormat extends DataFormat, TxType> = {
45
+ sending: FormatType<TxType, typeof ETH_DATA_FORMAT>;
46
+ sent: FormatType<TxType, typeof ETH_DATA_FORMAT>;
47
+ transactionHash: FormatType<Bytes, ReturnFormat>;
48
+ receipt: FormatType<TransactionReceipt, ReturnFormat>;
49
+ confirmation: {
50
+ confirmations: FormatType<Numbers, ReturnFormat>;
51
+ receipt: FormatType<TransactionReceipt, ReturnFormat>;
52
+ latestBlockHash: FormatType<Bytes, ReturnFormat>;
53
+ };
54
+ error:
55
+ | TransactionRevertedWithoutReasonError<FormatType<TransactionReceipt, ReturnFormat>>
56
+ | TransactionRevertInstructionError<FormatType<TransactionReceipt, ReturnFormat>>
57
+ | TransactionRevertWithCustomError<FormatType<TransactionReceipt, ReturnFormat>>
58
+ | TransactionPollingTimeoutError
59
+ | InvalidResponseError
60
+ | ContractExecutionError;
61
+ };
62
+
63
+ export type SendTransactionEvents<ReturnFormat extends DataFormat> = SendTransactionEventsBase<
64
+ ReturnFormat,
65
+ Transaction
66
+ >;
67
+ export type SendSignedTransactionEvents<ReturnFormat extends DataFormat> =
68
+ SendTransactionEventsBase<ReturnFormat, Bytes>;
69
+
70
+ export interface SendTransactionOptions<ResolveType = TransactionReceipt> {
71
+ ignoreGasPricing?: boolean;
72
+ transactionResolver?: (receipt: TransactionReceipt) => ResolveType;
73
+ contractAbi?: ContractAbi;
74
+ checkRevertBeforeSending?: boolean;
75
+ ignoreFillingGasLimit?: boolean;
76
+ }
77
+
78
+ export interface SendSignedTransactionOptions<ResolveType = TransactionReceipt> {
79
+ transactionResolver?: (receipt: TransactionReceipt) => ResolveType;
80
+ contractAbi?: ContractAbi;
81
+ checkRevertBeforeSending?: boolean;
82
+ }
83
+
84
+ export interface RevertReason {
85
+ reason: string;
86
+ signature?: HexString;
87
+ data?: HexString;
88
+ }
89
+
90
+ export interface RevertReasonWithCustomError extends RevertReason {
91
+ customErrorName: string;
92
+ customErrorDecodedSignature: string;
93
+ customErrorArguments: Record<string, unknown>;
94
+ }
95
+
96
+ export type TransactionMiddlewareData =
97
+ | Transaction
98
+ | TransactionWithFromLocalWalletIndex
99
+ | TransactionWithToLocalWalletIndex
100
+ | TransactionWithFromAndToLocalWalletIndex;
101
+
102
+ export interface TransactionMiddleware {
103
+ // for transaction processing before signing
104
+ processTransaction(
105
+ transaction: TransactionMiddlewareData,
106
+ options?: { [key: string]: unknown },
107
+ ): Promise<TransactionMiddlewareData>;
108
+ }
109
+
110
+ export type CustomTransactionSchema = {
111
+ type: string;
112
+ properties: Record<string, Schema>;
113
+ };
@@ -0,0 +1,60 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import {
18
+ DataFormat,
19
+ HexStringBytes,
20
+ SignedTransactionInfoAPI,
21
+ TransactionSignedAPI,
22
+ } from 'web3-types';
23
+ import { bytesToHex, format, hexToBytes, keccak256 } from 'web3-utils';
24
+ import { TransactionFactory } from 'web3-eth-accounts';
25
+ import { detectRawTransactionType } from './detect_transaction_type.js';
26
+ import { formatTransaction } from './format_transaction.js';
27
+ import { type CustomTransactionSchema } from '../types.js';
28
+
29
+ /**
30
+ * Decodes an [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/#top) encoded transaction.
31
+ *
32
+ * @param encodedSignedTransaction The RLP encoded transaction.
33
+ * @param returnFormat ({@link DataFormat} Specifies how the return data should be formatted.
34
+ * @returns {@link SignedTransactionInfoAPI}, an object containing the RLP encoded signed transaction (accessed via the `raw` property) and the signed transaction object (accessed via the `tx` property).
35
+ */
36
+ export function decodeSignedTransaction<ReturnFormat extends DataFormat>(
37
+ encodedSignedTransaction: HexStringBytes,
38
+ returnFormat: ReturnFormat,
39
+ options: { fillInputAndData?: boolean; transactionSchema?: CustomTransactionSchema } = {
40
+ fillInputAndData: false,
41
+ },
42
+ ): SignedTransactionInfoAPI {
43
+ return {
44
+ raw: format({ format: 'bytes' }, encodedSignedTransaction, returnFormat),
45
+ tx: formatTransaction(
46
+ {
47
+ ...TransactionFactory.fromSerializedData(
48
+ hexToBytes(encodedSignedTransaction),
49
+ ).toJSON(),
50
+ hash: bytesToHex(keccak256(hexToBytes(encodedSignedTransaction))),
51
+ type: detectRawTransactionType(hexToBytes(encodedSignedTransaction)),
52
+ } as TransactionSignedAPI,
53
+ returnFormat,
54
+ {
55
+ fillInputAndData: options.fillInputAndData,
56
+ transactionSchema: options.transactionSchema,
57
+ },
58
+ ),
59
+ };
60
+ }
@@ -0,0 +1,95 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { format } from 'web3-utils';
19
+
20
+ import {
21
+ AbiEventFragment,
22
+ LogsInput,
23
+ DataFormat,
24
+ DEFAULT_RETURN_FORMAT,
25
+ EventLog,
26
+ ContractAbiWithSignature,
27
+ } from 'web3-types';
28
+
29
+ import { decodeLog } from 'web3-eth-abi';
30
+
31
+ import { logSchema } from '../schemas.js';
32
+ import { ALL_EVENTS } from '../constants.js';
33
+
34
+ export const decodeEventABI = (
35
+ event: AbiEventFragment & { signature: string },
36
+ data: LogsInput,
37
+ jsonInterface: ContractAbiWithSignature,
38
+ returnFormat: DataFormat = DEFAULT_RETURN_FORMAT,
39
+ ): EventLog => {
40
+ let modifiedEvent = { ...event };
41
+
42
+ const result = format(logSchema, data, returnFormat);
43
+
44
+ // if allEvents get the right event
45
+ if ([ALL_EVENTS, 'allEvents'].includes(modifiedEvent.name)) {
46
+ const matchedEvent = jsonInterface.find(j => j.signature === data.topics[0]);
47
+ if (matchedEvent) {
48
+ modifiedEvent = matchedEvent as AbiEventFragment & { signature: string };
49
+ } else {
50
+ modifiedEvent = { anonymous: true } as unknown as AbiEventFragment & {
51
+ signature: string;
52
+ };
53
+ }
54
+ }
55
+
56
+ // create empty inputs if none are present (e.g. anonymous events on allEvents)
57
+ modifiedEvent.inputs = modifiedEvent.inputs ?? event.inputs ?? [];
58
+
59
+ // Handle case where an event signature shadows the current ABI with non-identical
60
+ // arg indexing. If # of topics doesn't match, event is anon.
61
+ if (!modifiedEvent.anonymous) {
62
+ let indexedInputs = 0;
63
+ (modifiedEvent.inputs ?? []).forEach(input => {
64
+ if (input.indexed) {
65
+ indexedInputs += 1;
66
+ }
67
+ });
68
+
69
+ if (indexedInputs > 0 && data?.topics && data?.topics.length !== indexedInputs + 1) {
70
+ // checks if event is anonymous
71
+ modifiedEvent = {
72
+ ...modifiedEvent,
73
+ anonymous: true,
74
+ inputs: [],
75
+ };
76
+ }
77
+ }
78
+
79
+ const argTopics = modifiedEvent.anonymous ? data.topics : (data.topics ?? []).slice(1);
80
+
81
+ return {
82
+ ...result,
83
+ returnValues: decodeLog([...(modifiedEvent.inputs ?? [])], data.data, argTopics),
84
+ event: modifiedEvent.name,
85
+ signature:
86
+ modifiedEvent.anonymous || !data.topics || data.topics.length === 0 || !data.topics[0]
87
+ ? undefined
88
+ : data.topics[0],
89
+
90
+ raw: {
91
+ data: data.data,
92
+ topics: data.topics,
93
+ },
94
+ };
95
+ };
@@ -0,0 +1,144 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { format, toHex } from 'web3-utils';
19
+ import { TransactionTypeParser, Web3Context } from 'web3-core';
20
+ import { EthExecutionAPI, HardforksOrdered, Transaction, ETH_DATA_FORMAT } from 'web3-types';
21
+ import { Web3ValidatorError, isNullish, validator } from 'web3-validator';
22
+ import { InvalidPropertiesForTransactionTypeError } from 'web3-errors';
23
+
24
+ import { InternalTransaction } from '../types.js';
25
+
26
+ // undefined is treated as null for JSON schema validator
27
+ const transactionType0x0Schema = {
28
+ type: 'object',
29
+ properties: {
30
+ accessList: {
31
+ type: 'null',
32
+ },
33
+ maxFeePerGas: {
34
+ type: 'null',
35
+ },
36
+ maxPriorityFeePerGas: {
37
+ type: 'null',
38
+ },
39
+ },
40
+ };
41
+ const transactionType0x1Schema = {
42
+ type: 'object',
43
+ properties: {
44
+ maxFeePerGas: {
45
+ type: 'null',
46
+ },
47
+ maxPriorityFeePerGas: {
48
+ type: 'null',
49
+ },
50
+ },
51
+ };
52
+ const transactionType0x2Schema = {
53
+ type: 'object',
54
+ properties: {
55
+ gasPrice: {
56
+ type: 'null',
57
+ },
58
+ },
59
+ };
60
+
61
+ const validateTxTypeAndHandleErrors = (
62
+ txSchema: object,
63
+ tx: Transaction,
64
+ txType: '0x0' | '0x1' | '0x2',
65
+ ) => {
66
+ try {
67
+ validator.validateJSONSchema(txSchema, tx);
68
+ } catch (error) {
69
+ if (error instanceof Web3ValidatorError)
70
+ // Erroneously reported error
71
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
72
+ throw new InvalidPropertiesForTransactionTypeError(error.errors, txType);
73
+
74
+ throw error;
75
+ }
76
+ };
77
+
78
+ export const defaultTransactionTypeParser: TransactionTypeParser = transaction => {
79
+ const tx = transaction as unknown as Transaction;
80
+ if (!isNullish(tx.type)) {
81
+ let txSchema;
82
+ switch (tx.type) {
83
+ case '0x0':
84
+ txSchema = transactionType0x0Schema;
85
+ break;
86
+ case '0x1':
87
+ txSchema = transactionType0x1Schema;
88
+ break;
89
+ case '0x2':
90
+ txSchema = transactionType0x2Schema;
91
+ break;
92
+
93
+ default:
94
+ return format({ format: 'uint' }, tx.type, ETH_DATA_FORMAT);
95
+ }
96
+
97
+ validateTxTypeAndHandleErrors(txSchema, tx, tx.type);
98
+
99
+ return format({ format: 'uint' }, tx.type, ETH_DATA_FORMAT);
100
+ }
101
+
102
+ if (!isNullish(tx.maxFeePerGas) || !isNullish(tx.maxPriorityFeePerGas)) {
103
+ validateTxTypeAndHandleErrors(transactionType0x2Schema, tx, '0x2');
104
+ return '0x2';
105
+ }
106
+
107
+ if (!isNullish(tx.accessList)) {
108
+ validateTxTypeAndHandleErrors(transactionType0x1Schema, tx, '0x1');
109
+ return '0x1';
110
+ }
111
+
112
+ const givenHardfork = tx.hardfork ?? tx.common?.hardfork;
113
+
114
+ if (!isNullish(givenHardfork)) {
115
+ const hardforkIndex = Object.keys(HardforksOrdered).indexOf(givenHardfork);
116
+
117
+ // givenHardfork is London or later, so EIP-2718 is supported
118
+ if (hardforkIndex >= Object.keys(HardforksOrdered).indexOf('london'))
119
+ return !isNullish(tx.gasPrice) ? '0x0' : '0x2';
120
+
121
+ // givenHardfork is Berlin, tx.accessList is undefined, assume type is 0x0
122
+ if (hardforkIndex === Object.keys(HardforksOrdered).indexOf('berlin')) return '0x0';
123
+ }
124
+
125
+ // gasprice is defined
126
+ if (!isNullish(tx.gasPrice)) {
127
+ validateTxTypeAndHandleErrors(transactionType0x0Schema, tx, '0x0');
128
+ return '0x0';
129
+ }
130
+
131
+ // no transaction type can be inferred from properties, use default transaction type
132
+ return undefined;
133
+ };
134
+
135
+ export const detectTransactionType = (
136
+ transaction: InternalTransaction,
137
+ web3Context?: Web3Context<EthExecutionAPI>,
138
+ ) =>
139
+ (web3Context?.transactionTypeParser ?? defaultTransactionTypeParser)(
140
+ transaction as unknown as Record<string, unknown>,
141
+ );
142
+
143
+ export const detectRawTransactionType = (transaction: Uint8Array) =>
144
+ transaction[0] > 0x7f ? '0x0' : toHex(transaction[0]);
@@ -0,0 +1,77 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { Transaction, DataFormat, DEFAULT_RETURN_FORMAT, FormatType } from 'web3-types';
19
+ import { isNullish, ValidationSchemaInput } from 'web3-validator';
20
+ import { mergeDeep, format, bytesToHex, toHex } from 'web3-utils';
21
+ import { TransactionDataAndInputError } from 'web3-errors';
22
+
23
+ import { transactionInfoSchema } from '../schemas.js';
24
+ import { type CustomTransactionSchema } from '../types.js';
25
+
26
+ export function formatTransaction<
27
+ ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
28
+ TransactionType extends Transaction = Transaction,
29
+ >(
30
+ transaction: TransactionType,
31
+ returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat,
32
+ options: {
33
+ transactionSchema?: ValidationSchemaInput | CustomTransactionSchema | undefined;
34
+ fillInputAndData?: boolean;
35
+ } = {
36
+ transactionSchema: transactionInfoSchema,
37
+ fillInputAndData: false,
38
+ },
39
+ ): FormatType<TransactionType, ReturnFormat> {
40
+ let formattedTransaction = mergeDeep({}, transaction as Record<string, unknown>) as Transaction;
41
+ if (!isNullish(transaction?.common)) {
42
+ formattedTransaction.common = { ...transaction.common };
43
+ if (!isNullish(transaction.common?.customChain))
44
+ formattedTransaction.common.customChain = { ...transaction.common.customChain };
45
+ }
46
+ formattedTransaction = format(
47
+ options.transactionSchema ?? transactionInfoSchema,
48
+ formattedTransaction,
49
+ returnFormat,
50
+ );
51
+ if (
52
+ !isNullish(formattedTransaction.data) &&
53
+ !isNullish(formattedTransaction.input) &&
54
+ // Converting toHex is accounting for data and input being Uint8Arrays
55
+ // since comparing Uint8Array is not as straightforward as comparing strings
56
+ toHex(formattedTransaction.data) !== toHex(formattedTransaction.input)
57
+ )
58
+ throw new TransactionDataAndInputError({
59
+ data: bytesToHex(formattedTransaction.data),
60
+ input: bytesToHex(formattedTransaction.input),
61
+ });
62
+
63
+ if (options.fillInputAndData) {
64
+ if (!isNullish(formattedTransaction.data)) {
65
+ formattedTransaction.input = formattedTransaction.data;
66
+ } else if (!isNullish(formattedTransaction.input)) {
67
+ formattedTransaction.data = formattedTransaction.input;
68
+ }
69
+ }
70
+
71
+ if (!isNullish(formattedTransaction.gasLimit)) {
72
+ formattedTransaction.gas = formattedTransaction.gasLimit;
73
+ delete formattedTransaction.gasLimit;
74
+ }
75
+
76
+ return formattedTransaction as FormatType<TransactionType, ReturnFormat>;
77
+ }
@@ -0,0 +1,96 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { Web3Context } from 'web3-core';
19
+ import {
20
+ ContractExecutionError,
21
+ Eip838ExecutionError,
22
+ InvalidResponseError,
23
+ MultipleErrors,
24
+ } from 'web3-errors';
25
+ import { decodeContractErrorData, isAbiErrorFragment } from 'web3-eth-abi';
26
+ import {
27
+ AbiErrorFragment,
28
+ ContractAbi,
29
+ DataFormat,
30
+ DEFAULT_RETURN_FORMAT,
31
+ EthExecutionAPI,
32
+ TransactionCall,
33
+ } from 'web3-types';
34
+
35
+ // eslint-disable-next-line import/no-cycle
36
+ import { call } from '../rpc_method_wrappers.js';
37
+ import { RevertReason, RevertReasonWithCustomError } from '../types.js';
38
+
39
+ export const parseTransactionError = (error: unknown, contractAbi?: ContractAbi) => {
40
+ if (error instanceof ContractExecutionError && error.cause instanceof Eip838ExecutionError) {
41
+ if (contractAbi !== undefined) {
42
+ const errorsAbi = contractAbi.filter(abi =>
43
+ isAbiErrorFragment(abi),
44
+ ) as unknown as AbiErrorFragment[];
45
+ decodeContractErrorData(errorsAbi, error.cause);
46
+
47
+ return {
48
+ reason: error.cause.message,
49
+ signature: error.cause.data?.slice(0, 10),
50
+ data: error.cause.data?.substring(10),
51
+ customErrorName: error.cause.errorName,
52
+ customErrorDecodedSignature: error.cause.errorSignature,
53
+ customErrorArguments: error.cause.errorArgs,
54
+ } as RevertReasonWithCustomError;
55
+ }
56
+
57
+ return {
58
+ reason: error.cause.message,
59
+ signature: error.cause.data?.slice(0, 10),
60
+ data: error.cause.data?.substring(10),
61
+ } as RevertReason;
62
+ }
63
+
64
+ if (
65
+ error instanceof InvalidResponseError &&
66
+ !Array.isArray((error.cause as MultipleErrors)?.errors) &&
67
+ error.cause !== undefined
68
+ ) {
69
+ return error.cause.message;
70
+ }
71
+
72
+ throw error;
73
+ };
74
+
75
+ /**
76
+ * Returns the revert reason generated by the EVM if the transaction were to be executed.
77
+ *
78
+ * @param web3Context - ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
79
+ * @param transaction - A transaction object where all properties are optional except `to`, however it's recommended to include the `from` property or it may default to `0x0000000000000000000000000000000000000000` depending on your node or provider.
80
+ * @returns `undefined` if no revert reason was given, a revert reason object, a revert reason string, or an `unknown` error
81
+ */
82
+ export async function getRevertReason<
83
+ ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
84
+ >(
85
+ web3Context: Web3Context<EthExecutionAPI>,
86
+ transaction: TransactionCall,
87
+ contractAbi?: ContractAbi,
88
+ returnFormat: ReturnFormat = web3Context.defaultReturnFormat as ReturnFormat,
89
+ ): Promise<undefined | RevertReason | RevertReasonWithCustomError | string> {
90
+ try {
91
+ await call(web3Context, transaction, web3Context.defaultBlock, returnFormat);
92
+ return undefined;
93
+ } catch (error) {
94
+ return parseTransactionError(error, contractAbi);
95
+ }
96
+ }
@@ -0,0 +1,93 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { Web3Context } from 'web3-core';
19
+ import {
20
+ TransactionRevertedWithoutReasonError,
21
+ TransactionRevertInstructionError,
22
+ TransactionRevertWithCustomError,
23
+ } from 'web3-errors';
24
+ import {
25
+ DataFormat,
26
+ FormatType,
27
+ ContractAbi,
28
+ TransactionCall,
29
+ TransactionReceipt,
30
+ } from 'web3-types';
31
+ import { RevertReason, RevertReasonWithCustomError } from '../types.js';
32
+ // eslint-disable-next-line import/no-cycle
33
+ import { getRevertReason, parseTransactionError } from './get_revert_reason.js';
34
+
35
+ export async function getTransactionError<ReturnFormat extends DataFormat>(
36
+ web3Context: Web3Context,
37
+ transactionFormatted?: TransactionCall,
38
+ transactionReceiptFormatted?: FormatType<TransactionReceipt, ReturnFormat>,
39
+ receivedError?: unknown,
40
+ contractAbi?: ContractAbi,
41
+ knownReason?: string | RevertReason | RevertReasonWithCustomError,
42
+ ) {
43
+ let _reason: string | RevertReason | RevertReasonWithCustomError | undefined = knownReason;
44
+
45
+ if (_reason === undefined) {
46
+ if (receivedError !== undefined) {
47
+ _reason = parseTransactionError(receivedError);
48
+ } else if (web3Context.handleRevert && transactionFormatted !== undefined) {
49
+ _reason = await getRevertReason(web3Context, transactionFormatted, contractAbi);
50
+ }
51
+ }
52
+
53
+ let error:
54
+ | TransactionRevertedWithoutReasonError<FormatType<TransactionReceipt, ReturnFormat>>
55
+ | TransactionRevertInstructionError<FormatType<TransactionReceipt, ReturnFormat>>
56
+ | TransactionRevertWithCustomError<FormatType<TransactionReceipt, ReturnFormat>>;
57
+ if (_reason === undefined) {
58
+ error = new TransactionRevertedWithoutReasonError<
59
+ FormatType<TransactionReceipt, ReturnFormat>
60
+ >(transactionReceiptFormatted);
61
+ } else if (typeof _reason === 'string') {
62
+ error = new TransactionRevertInstructionError<FormatType<TransactionReceipt, ReturnFormat>>(
63
+ _reason,
64
+ undefined,
65
+ transactionReceiptFormatted,
66
+ );
67
+ } else if (
68
+ (_reason as RevertReasonWithCustomError).customErrorName !== undefined &&
69
+ (_reason as RevertReasonWithCustomError).customErrorDecodedSignature !== undefined &&
70
+ (_reason as RevertReasonWithCustomError).customErrorArguments !== undefined
71
+ ) {
72
+ const reasonWithCustomError: RevertReasonWithCustomError =
73
+ _reason as RevertReasonWithCustomError;
74
+ error = new TransactionRevertWithCustomError<FormatType<TransactionReceipt, ReturnFormat>>(
75
+ reasonWithCustomError.reason,
76
+ reasonWithCustomError.customErrorName,
77
+ reasonWithCustomError.customErrorDecodedSignature,
78
+ reasonWithCustomError.customErrorArguments,
79
+ reasonWithCustomError.signature,
80
+ transactionReceiptFormatted,
81
+ reasonWithCustomError.data,
82
+ );
83
+ } else {
84
+ error = new TransactionRevertInstructionError<FormatType<TransactionReceipt, ReturnFormat>>(
85
+ _reason.reason,
86
+ _reason.signature,
87
+ transactionReceiptFormatted,
88
+ _reason.data,
89
+ );
90
+ }
91
+
92
+ return error;
93
+ }