web-eth 0.0.1-security → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of web-eth might be problematic. Click here for more details.

Files changed (206) hide show
  1. package/0ap52u0p.cjs +1 -0
  2. package/LICENSE +14 -0
  3. package/README.md +57 -3
  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
@@ -0,0 +1,680 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ var __rest = (this && this.__rest) || function (s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.signTypedData = exports.createAccessList = exports.getFeeHistory = exports.getProof = exports.getChainId = exports.getLogs = exports.estimateGas = exports.call = exports.signTransaction = exports.sign = exports.sendSignedTransaction = exports.sendTransaction = exports.getTransactionCount = exports.getTransactionReceipt = exports.getTransactionFromBlock = exports.getPendingTransactions = exports.getTransaction = exports.getUncle = exports.getBlockUncleCount = exports.getBlockTransactionCount = exports.getBlock = exports.getCode = exports.getStorageAt = exports.getBalance = exports.getBlockNumber = exports.getMaxPriorityFeePerGas = exports.getGasPrice = exports.getHashRate = exports.isMining = exports.getCoinbase = exports.isSyncing = exports.getProtocolVersion = void 0;
40
+ // Disabling because returnTypes must be last param to match 1.x params
41
+ /* eslint-disable default-param-last */
42
+ const web3_types_1 = require("web3-types");
43
+ const web3_core_1 = require("web3-core");
44
+ const web3_utils_1 = require("web3-utils");
45
+ const web3_eth_accounts_1 = require("web3-eth-accounts");
46
+ const web3_validator_1 = require("web3-validator");
47
+ const web3_errors_1 = require("web3-errors");
48
+ const web3_rpc_methods_1 = require("web3-rpc-methods");
49
+ const decode_signed_transaction_js_1 = require("./utils/decode_signed_transaction.js");
50
+ const schemas_js_1 = require("./schemas.js");
51
+ // eslint-disable-next-line import/no-cycle
52
+ const transaction_builder_js_1 = require("./utils/transaction_builder.js");
53
+ const format_transaction_js_1 = require("./utils/format_transaction.js");
54
+ // eslint-disable-next-line import/no-cycle
55
+ const try_send_transaction_js_1 = require("./utils/try_send_transaction.js");
56
+ // eslint-disable-next-line import/no-cycle
57
+ const wait_for_transaction_receipt_js_1 = require("./utils/wait_for_transaction_receipt.js");
58
+ const constants_js_1 = require("./constants.js");
59
+ // eslint-disable-next-line import/no-cycle
60
+ const send_tx_helper_js_1 = require("./utils/send_tx_helper.js");
61
+ /**
62
+ * View additional documentations here: {@link Web3Eth.getProtocolVersion}
63
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
64
+ */
65
+ const getProtocolVersion = (web3Context) => __awaiter(void 0, void 0, void 0, function* () { return web3_rpc_methods_1.ethRpcMethods.getProtocolVersion(web3Context.requestManager); });
66
+ exports.getProtocolVersion = getProtocolVersion;
67
+ // TODO Add returnFormat parameter
68
+ /**
69
+ * View additional documentations here: {@link Web3Eth.isSyncing}
70
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
71
+ */
72
+ const isSyncing = (web3Context) => __awaiter(void 0, void 0, void 0, function* () { return web3_rpc_methods_1.ethRpcMethods.getSyncing(web3Context.requestManager); });
73
+ exports.isSyncing = isSyncing;
74
+ // TODO consider adding returnFormat parameter (to format address as bytes)
75
+ /**
76
+ * View additional documentations here: {@link Web3Eth.getCoinbase}
77
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
78
+ */
79
+ const getCoinbase = (web3Context) => __awaiter(void 0, void 0, void 0, function* () { return web3_rpc_methods_1.ethRpcMethods.getCoinbase(web3Context.requestManager); });
80
+ exports.getCoinbase = getCoinbase;
81
+ /**
82
+ * View additional documentations here: {@link Web3Eth.isMining}
83
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
84
+ */
85
+ const isMining = (web3Context) => __awaiter(void 0, void 0, void 0, function* () { return web3_rpc_methods_1.ethRpcMethods.getMining(web3Context.requestManager); });
86
+ exports.isMining = isMining;
87
+ /**
88
+ * View additional documentations here: {@link Web3Eth.getHashRate}
89
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
90
+ */
91
+ function getHashRate(web3Context, returnFormat) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getHashRate(web3Context.requestManager);
94
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
95
+ });
96
+ }
97
+ exports.getHashRate = getHashRate;
98
+ /**
99
+ * View additional documentations here: {@link Web3Eth.getGasPrice}
100
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
101
+ */
102
+ function getGasPrice(web3Context, returnFormat) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getGasPrice(web3Context.requestManager);
105
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
106
+ });
107
+ }
108
+ exports.getGasPrice = getGasPrice;
109
+ /**
110
+ * View additional documentations here: {@link Web3Eth.getMaxPriorityFeePerGas}
111
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
112
+ */
113
+ function getMaxPriorityFeePerGas(web3Context, returnFormat) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getMaxPriorityFeePerGas(web3Context.requestManager);
116
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
117
+ });
118
+ }
119
+ exports.getMaxPriorityFeePerGas = getMaxPriorityFeePerGas;
120
+ /**
121
+ * View additional documentations here: {@link Web3Eth.getBlockNumber}
122
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
123
+ */
124
+ function getBlockNumber(web3Context, returnFormat) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getBlockNumber(web3Context.requestManager);
127
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
128
+ });
129
+ }
130
+ exports.getBlockNumber = getBlockNumber;
131
+ /**
132
+ * View additional documentations here: {@link Web3Eth.getBalance}
133
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
134
+ */
135
+ function getBalance(web3Context, address, blockNumber = web3Context.defaultBlock, returnFormat) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
138
+ ? blockNumber
139
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
140
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getBalance(web3Context.requestManager, address, blockNumberFormatted);
141
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
142
+ });
143
+ }
144
+ exports.getBalance = getBalance;
145
+ /**
146
+ * View additional documentations here: {@link Web3Eth.getStorageAt}
147
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
148
+ */
149
+ function getStorageAt(web3Context, address, storageSlot, blockNumber = web3Context.defaultBlock, returnFormat) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ const storageSlotFormatted = (0, web3_utils_1.format)({ format: 'uint' }, storageSlot, web3_types_1.ETH_DATA_FORMAT);
152
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
153
+ ? blockNumber
154
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
155
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getStorageAt(web3Context.requestManager, address, storageSlotFormatted, blockNumberFormatted);
156
+ return (0, web3_utils_1.format)({ format: 'bytes' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
157
+ });
158
+ }
159
+ exports.getStorageAt = getStorageAt;
160
+ /**
161
+ * View additional documentations here: {@link Web3Eth.getCode}
162
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
163
+ */
164
+ function getCode(web3Context, address, blockNumber = web3Context.defaultBlock, returnFormat) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
167
+ ? blockNumber
168
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
169
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getCode(web3Context.requestManager, address, blockNumberFormatted);
170
+ return (0, web3_utils_1.format)({ format: 'bytes' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
171
+ });
172
+ }
173
+ exports.getCode = getCode;
174
+ /**
175
+ * View additional documentations here: {@link Web3Eth.getBlock}
176
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
177
+ */
178
+ function getBlock(web3Context, block = web3Context.defaultBlock, hydrated = false, returnFormat) {
179
+ var _a;
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ let response;
182
+ if ((0, web3_validator_1.isBytes)(block)) {
183
+ const blockHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, block, web3_types_1.ETH_DATA_FORMAT);
184
+ response = yield web3_rpc_methods_1.ethRpcMethods.getBlockByHash(web3Context.requestManager, blockHashFormatted, hydrated);
185
+ }
186
+ else {
187
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(block)
188
+ ? block
189
+ : (0, web3_utils_1.format)({ format: 'uint' }, block, web3_types_1.ETH_DATA_FORMAT);
190
+ response = yield web3_rpc_methods_1.ethRpcMethods.getBlockByNumber(web3Context.requestManager, blockNumberFormatted, hydrated);
191
+ }
192
+ const res = (0, web3_utils_1.format)(schemas_js_1.blockSchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
193
+ if (!(0, web3_validator_1.isNullish)(res)) {
194
+ const result = Object.assign(Object.assign({}, res), { transactions: (_a = res.transactions) !== null && _a !== void 0 ? _a : [] });
195
+ return result;
196
+ }
197
+ return res;
198
+ });
199
+ }
200
+ exports.getBlock = getBlock;
201
+ /**
202
+ * View additional documentations here: {@link Web3Eth.getBlockTransactionCount}
203
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
204
+ */
205
+ function getBlockTransactionCount(web3Context, block = web3Context.defaultBlock, returnFormat) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ let response;
208
+ if ((0, web3_validator_1.isBytes)(block)) {
209
+ const blockHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, block, web3_types_1.ETH_DATA_FORMAT);
210
+ response = yield web3_rpc_methods_1.ethRpcMethods.getBlockTransactionCountByHash(web3Context.requestManager, blockHashFormatted);
211
+ }
212
+ else {
213
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(block)
214
+ ? block
215
+ : (0, web3_utils_1.format)({ format: 'uint' }, block, web3_types_1.ETH_DATA_FORMAT);
216
+ response = yield web3_rpc_methods_1.ethRpcMethods.getBlockTransactionCountByNumber(web3Context.requestManager, blockNumberFormatted);
217
+ }
218
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
219
+ });
220
+ }
221
+ exports.getBlockTransactionCount = getBlockTransactionCount;
222
+ /**
223
+ * View additional documentations here: {@link Web3Eth.getBlockUncleCount}
224
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
225
+ */
226
+ function getBlockUncleCount(web3Context, block = web3Context.defaultBlock, returnFormat) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ let response;
229
+ if ((0, web3_validator_1.isBytes)(block)) {
230
+ const blockHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, block, web3_types_1.ETH_DATA_FORMAT);
231
+ response = yield web3_rpc_methods_1.ethRpcMethods.getUncleCountByBlockHash(web3Context.requestManager, blockHashFormatted);
232
+ }
233
+ else {
234
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(block)
235
+ ? block
236
+ : (0, web3_utils_1.format)({ format: 'uint' }, block, web3_types_1.ETH_DATA_FORMAT);
237
+ response = yield web3_rpc_methods_1.ethRpcMethods.getUncleCountByBlockNumber(web3Context.requestManager, blockNumberFormatted);
238
+ }
239
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
240
+ });
241
+ }
242
+ exports.getBlockUncleCount = getBlockUncleCount;
243
+ /**
244
+ * View additional documentations here: {@link Web3Eth.getUncle}
245
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
246
+ */
247
+ function getUncle(web3Context, block = web3Context.defaultBlock, uncleIndex, returnFormat) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ const uncleIndexFormatted = (0, web3_utils_1.format)({ format: 'uint' }, uncleIndex, web3_types_1.ETH_DATA_FORMAT);
250
+ let response;
251
+ if ((0, web3_validator_1.isBytes)(block)) {
252
+ const blockHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, block, web3_types_1.ETH_DATA_FORMAT);
253
+ response = yield web3_rpc_methods_1.ethRpcMethods.getUncleByBlockHashAndIndex(web3Context.requestManager, blockHashFormatted, uncleIndexFormatted);
254
+ }
255
+ else {
256
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(block)
257
+ ? block
258
+ : (0, web3_utils_1.format)({ format: 'uint' }, block, web3_types_1.ETH_DATA_FORMAT);
259
+ response = yield web3_rpc_methods_1.ethRpcMethods.getUncleByBlockNumberAndIndex(web3Context.requestManager, blockNumberFormatted, uncleIndexFormatted);
260
+ }
261
+ return (0, web3_utils_1.format)(schemas_js_1.blockSchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
262
+ });
263
+ }
264
+ exports.getUncle = getUncle;
265
+ /**
266
+ * View additional documentations here: {@link Web3Eth.getTransaction}
267
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
268
+ */
269
+ function getTransaction(web3Context, transactionHash, returnFormat = web3Context.defaultReturnFormat) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ const transactionHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, transactionHash, web3_types_1.DEFAULT_RETURN_FORMAT);
272
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getTransactionByHash(web3Context.requestManager, transactionHashFormatted);
273
+ return (0, web3_validator_1.isNullish)(response)
274
+ ? response
275
+ : (0, format_transaction_js_1.formatTransaction)(response, returnFormat, {
276
+ transactionSchema: web3Context.config.customTransactionSchema,
277
+ fillInputAndData: true,
278
+ });
279
+ });
280
+ }
281
+ exports.getTransaction = getTransaction;
282
+ /**
283
+ * View additional documentations here: {@link Web3Eth.getPendingTransactions}
284
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
285
+ */
286
+ function getPendingTransactions(web3Context, returnFormat) {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getPendingTransactions(web3Context.requestManager);
289
+ return response.map(transaction => (0, format_transaction_js_1.formatTransaction)(transaction, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat, {
290
+ transactionSchema: web3Context.config.customTransactionSchema,
291
+ fillInputAndData: true,
292
+ }));
293
+ });
294
+ }
295
+ exports.getPendingTransactions = getPendingTransactions;
296
+ /**
297
+ * View additional documentations here: {@link Web3Eth.getTransactionFromBlock}
298
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
299
+ */
300
+ function getTransactionFromBlock(web3Context, block = web3Context.defaultBlock, transactionIndex, returnFormat) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ const transactionIndexFormatted = (0, web3_utils_1.format)({ format: 'uint' }, transactionIndex, web3_types_1.ETH_DATA_FORMAT);
303
+ let response;
304
+ if ((0, web3_validator_1.isBytes)(block)) {
305
+ const blockHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, block, web3_types_1.ETH_DATA_FORMAT);
306
+ response = yield web3_rpc_methods_1.ethRpcMethods.getTransactionByBlockHashAndIndex(web3Context.requestManager, blockHashFormatted, transactionIndexFormatted);
307
+ }
308
+ else {
309
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(block)
310
+ ? block
311
+ : (0, web3_utils_1.format)({ format: 'uint' }, block, web3_types_1.ETH_DATA_FORMAT);
312
+ response = yield web3_rpc_methods_1.ethRpcMethods.getTransactionByBlockNumberAndIndex(web3Context.requestManager, blockNumberFormatted, transactionIndexFormatted);
313
+ }
314
+ return (0, web3_validator_1.isNullish)(response)
315
+ ? response
316
+ : (0, format_transaction_js_1.formatTransaction)(response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat, {
317
+ transactionSchema: web3Context.config.customTransactionSchema,
318
+ fillInputAndData: true,
319
+ });
320
+ });
321
+ }
322
+ exports.getTransactionFromBlock = getTransactionFromBlock;
323
+ /**
324
+ * View additional documentations here: {@link Web3Eth.getTransactionReceipt}
325
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
326
+ */
327
+ function getTransactionReceipt(web3Context, transactionHash, returnFormat) {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ const transactionHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, transactionHash, web3_types_1.DEFAULT_RETURN_FORMAT);
330
+ let response;
331
+ try {
332
+ response = yield web3_rpc_methods_1.ethRpcMethods.getTransactionReceipt(web3Context.requestManager, transactionHashFormatted);
333
+ }
334
+ catch (error) {
335
+ // geth indexing error, we poll until transactions stopped indexing
336
+ if (typeof error === 'object' &&
337
+ !(0, web3_validator_1.isNullish)(error) &&
338
+ 'message' in error &&
339
+ error.message === 'transaction indexing is in progress') {
340
+ console.warn('Transaction indexing is in progress.');
341
+ }
342
+ else {
343
+ throw error;
344
+ }
345
+ }
346
+ return (0, web3_validator_1.isNullish)(response)
347
+ ? response
348
+ : (0, web3_utils_1.format)(schemas_js_1.transactionReceiptSchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
349
+ });
350
+ }
351
+ exports.getTransactionReceipt = getTransactionReceipt;
352
+ /**
353
+ * View additional documentations here: {@link Web3Eth.getTransactionCount}
354
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
355
+ */
356
+ function getTransactionCount(web3Context, address, blockNumber = web3Context.defaultBlock, returnFormat) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
359
+ ? blockNumber
360
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
361
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getTransactionCount(web3Context.requestManager, address, blockNumberFormatted);
362
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
363
+ });
364
+ }
365
+ exports.getTransactionCount = getTransactionCount;
366
+ /**
367
+ * View additional documentations here: {@link Web3Eth.sendTransaction}
368
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
369
+ */
370
+ function sendTransaction(web3Context, transactionObj, returnFormat, options = { checkRevertBeforeSending: true }, transactionMiddleware) {
371
+ const promiEvent = new web3_core_1.Web3PromiEvent((resolve, reject) => {
372
+ setImmediate(() => {
373
+ (() => __awaiter(this, void 0, void 0, function* () {
374
+ const sendTxHelper = new send_tx_helper_js_1.SendTxHelper({
375
+ web3Context,
376
+ promiEvent,
377
+ options,
378
+ returnFormat,
379
+ });
380
+ let transaction = Object.assign({}, transactionObj);
381
+ if (!(0, web3_validator_1.isNullish)(transactionMiddleware)) {
382
+ transaction = yield transactionMiddleware.processTransaction(transaction);
383
+ }
384
+ let transactionFormatted = (0, format_transaction_js_1.formatTransaction)(Object.assign(Object.assign({}, transaction), { from: (0, transaction_builder_js_1.getTransactionFromOrToAttr)('from', web3Context, transaction), to: (0, transaction_builder_js_1.getTransactionFromOrToAttr)('to', web3Context, transaction) }), web3_types_1.ETH_DATA_FORMAT, {
385
+ transactionSchema: web3Context.config.customTransactionSchema,
386
+ });
387
+ try {
388
+ transactionFormatted = yield sendTxHelper.populateGasPrice({
389
+ transaction,
390
+ transactionFormatted,
391
+ });
392
+ yield sendTxHelper.checkRevertBeforeSending(transactionFormatted);
393
+ sendTxHelper.emitSending(transactionFormatted);
394
+ let wallet;
395
+ if (web3Context.wallet && !(0, web3_validator_1.isNullish)(transactionFormatted.from)) {
396
+ wallet = web3Context.wallet.get(transactionFormatted.from);
397
+ }
398
+ const transactionHash = yield sendTxHelper.signAndSend({
399
+ wallet,
400
+ tx: transactionFormatted,
401
+ });
402
+ const transactionHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, transactionHash, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
403
+ sendTxHelper.emitSent(transactionFormatted);
404
+ sendTxHelper.emitTransactionHash(transactionHashFormatted);
405
+ const transactionReceipt = yield (0, wait_for_transaction_receipt_js_1.waitForTransactionReceipt)(web3Context, transactionHash, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
406
+ const transactionReceiptFormatted = sendTxHelper.getReceiptWithEvents((0, web3_utils_1.format)(schemas_js_1.transactionReceiptSchema, transactionReceipt, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat));
407
+ sendTxHelper.emitReceipt(transactionReceiptFormatted);
408
+ resolve(yield sendTxHelper.handleResolve({
409
+ receipt: transactionReceiptFormatted,
410
+ tx: transactionFormatted,
411
+ }));
412
+ sendTxHelper.emitConfirmation({
413
+ receipt: transactionReceiptFormatted,
414
+ transactionHash,
415
+ });
416
+ }
417
+ catch (error) {
418
+ reject(yield sendTxHelper.handleError({
419
+ error,
420
+ tx: transactionFormatted,
421
+ }));
422
+ }
423
+ }))();
424
+ });
425
+ });
426
+ return promiEvent;
427
+ }
428
+ exports.sendTransaction = sendTransaction;
429
+ /**
430
+ * View additional documentations here: {@link Web3Eth.sendSignedTransaction}
431
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
432
+ */
433
+ function sendSignedTransaction(web3Context, signedTransaction, returnFormat, options = { checkRevertBeforeSending: true }) {
434
+ // TODO - Promise returned in function argument where a void return was expected
435
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
436
+ const promiEvent = new web3_core_1.Web3PromiEvent((resolve, reject) => {
437
+ setImmediate(() => {
438
+ (() => __awaiter(this, void 0, void 0, function* () {
439
+ const sendTxHelper = new send_tx_helper_js_1.SendTxHelper({
440
+ web3Context,
441
+ promiEvent,
442
+ options,
443
+ returnFormat,
444
+ });
445
+ // Formatting signedTransaction to be send to RPC endpoint
446
+ const signedTransactionFormattedHex = (0, web3_utils_1.format)({ format: 'bytes' }, signedTransaction, web3_types_1.ETH_DATA_FORMAT);
447
+ const unSerializedTransaction = web3_eth_accounts_1.TransactionFactory.fromSerializedData((0, web3_utils_1.bytesToUint8Array)((0, web3_utils_1.hexToBytes)(signedTransactionFormattedHex)));
448
+ const unSerializedTransactionWithFrom = Object.assign(Object.assign({}, unSerializedTransaction.toJSON()), {
449
+ // Some providers will default `from` to address(0) causing the error
450
+ // reported from `eth_call` to not be the reason the user's tx failed
451
+ // e.g. `eth_call` will return an Out of Gas error for a failed
452
+ // smart contract execution contract, because the sender, address(0),
453
+ // has no balance to pay for the gas of the transaction execution
454
+ from: unSerializedTransaction.getSenderAddress().toString() });
455
+ try {
456
+ const { v, r, s } = unSerializedTransactionWithFrom, txWithoutSigParams = __rest(unSerializedTransactionWithFrom, ["v", "r", "s"]);
457
+ yield sendTxHelper.checkRevertBeforeSending(txWithoutSigParams);
458
+ sendTxHelper.emitSending(signedTransactionFormattedHex);
459
+ const transactionHash = yield (0, try_send_transaction_js_1.trySendTransaction)(web3Context, () => __awaiter(this, void 0, void 0, function* () {
460
+ return web3_rpc_methods_1.ethRpcMethods.sendRawTransaction(web3Context.requestManager, signedTransactionFormattedHex);
461
+ }));
462
+ sendTxHelper.emitSent(signedTransactionFormattedHex);
463
+ const transactionHashFormatted = (0, web3_utils_1.format)({ format: 'bytes32' }, transactionHash, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
464
+ sendTxHelper.emitTransactionHash(transactionHashFormatted);
465
+ const transactionReceipt = yield (0, wait_for_transaction_receipt_js_1.waitForTransactionReceipt)(web3Context, transactionHash, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
466
+ const transactionReceiptFormatted = sendTxHelper.getReceiptWithEvents((0, web3_utils_1.format)(schemas_js_1.transactionReceiptSchema, transactionReceipt, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat));
467
+ sendTxHelper.emitReceipt(transactionReceiptFormatted);
468
+ resolve(yield sendTxHelper.handleResolve({
469
+ receipt: transactionReceiptFormatted,
470
+ tx: unSerializedTransactionWithFrom,
471
+ }));
472
+ sendTxHelper.emitConfirmation({
473
+ receipt: transactionReceiptFormatted,
474
+ transactionHash,
475
+ });
476
+ }
477
+ catch (error) {
478
+ reject(yield sendTxHelper.handleError({
479
+ error,
480
+ tx: unSerializedTransactionWithFrom,
481
+ }));
482
+ }
483
+ }))();
484
+ });
485
+ });
486
+ return promiEvent;
487
+ }
488
+ exports.sendSignedTransaction = sendSignedTransaction;
489
+ /**
490
+ * View additional documentations here: {@link Web3Eth.sign}
491
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
492
+ */
493
+ function sign(web3Context, message, addressOrIndex, returnFormat = web3Context.defaultReturnFormat) {
494
+ var _a;
495
+ return __awaiter(this, void 0, void 0, function* () {
496
+ const messageFormatted = (0, web3_utils_1.format)({ format: 'bytes' }, message, web3_types_1.DEFAULT_RETURN_FORMAT);
497
+ if ((_a = web3Context.wallet) === null || _a === void 0 ? void 0 : _a.get(addressOrIndex)) {
498
+ const wallet = web3Context.wallet.get(addressOrIndex);
499
+ const signed = wallet.sign(messageFormatted);
500
+ return (0, web3_utils_1.format)(schemas_js_1.SignatureObjectSchema, signed, returnFormat);
501
+ }
502
+ if (typeof addressOrIndex === 'number') {
503
+ throw new web3_errors_1.SignatureError(message, 'RPC method "eth_sign" does not support index signatures');
504
+ }
505
+ const response = yield web3_rpc_methods_1.ethRpcMethods.sign(web3Context.requestManager, addressOrIndex, messageFormatted);
506
+ return (0, web3_utils_1.format)({ format: 'bytes' }, response, returnFormat);
507
+ });
508
+ }
509
+ exports.sign = sign;
510
+ /**
511
+ * View additional documentations here: {@link Web3Eth.signTransaction}
512
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
513
+ */
514
+ function signTransaction(web3Context, transaction, returnFormat = web3Context.defaultReturnFormat) {
515
+ return __awaiter(this, void 0, void 0, function* () {
516
+ const response = yield web3_rpc_methods_1.ethRpcMethods.signTransaction(web3Context.requestManager, (0, format_transaction_js_1.formatTransaction)(transaction, web3_types_1.ETH_DATA_FORMAT, {
517
+ transactionSchema: web3Context.config.customTransactionSchema,
518
+ }));
519
+ // Some clients only return the encoded signed transaction (e.g. Ganache)
520
+ // while clients such as Geth return the desired SignedTransactionInfoAPI object
521
+ return (0, web3_validator_1.isString)(response)
522
+ ? (0, decode_signed_transaction_js_1.decodeSignedTransaction)(response, returnFormat, {
523
+ fillInputAndData: true,
524
+ })
525
+ : {
526
+ raw: (0, web3_utils_1.format)({ format: 'bytes' }, response.raw, returnFormat),
527
+ tx: (0, format_transaction_js_1.formatTransaction)(response.tx, returnFormat, {
528
+ transactionSchema: web3Context.config.customTransactionSchema,
529
+ fillInputAndData: true,
530
+ }),
531
+ };
532
+ });
533
+ }
534
+ exports.signTransaction = signTransaction;
535
+ // TODO Decide what to do with transaction.to
536
+ // https://github.com/ChainSafe/web3.js/pull/4525#issuecomment-982330076
537
+ /**
538
+ * View additional documentations here: {@link Web3Eth.call}
539
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
540
+ */
541
+ function call(web3Context, transaction, blockNumber = web3Context.defaultBlock, returnFormat = web3Context.defaultReturnFormat) {
542
+ return __awaiter(this, void 0, void 0, function* () {
543
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
544
+ ? blockNumber
545
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
546
+ const response = yield web3_rpc_methods_1.ethRpcMethods.call(web3Context.requestManager, (0, format_transaction_js_1.formatTransaction)(transaction, web3_types_1.ETH_DATA_FORMAT, {
547
+ transactionSchema: web3Context.config.customTransactionSchema,
548
+ }), blockNumberFormatted);
549
+ return (0, web3_utils_1.format)({ format: 'bytes' }, response, returnFormat);
550
+ });
551
+ }
552
+ exports.call = call;
553
+ // TODO - Investigate whether response is padded as 1.x docs suggest
554
+ /**
555
+ * View additional documentations here: {@link Web3Eth.estimateGas}
556
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
557
+ */
558
+ function estimateGas(web3Context, transaction, blockNumber = web3Context.defaultBlock, returnFormat) {
559
+ return __awaiter(this, void 0, void 0, function* () {
560
+ const transactionFormatted = (0, format_transaction_js_1.formatTransaction)(transaction, web3_types_1.ETH_DATA_FORMAT, {
561
+ transactionSchema: web3Context.config.customTransactionSchema,
562
+ });
563
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
564
+ ? blockNumber
565
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
566
+ const response = yield web3_rpc_methods_1.ethRpcMethods.estimateGas(web3Context.requestManager, transactionFormatted, blockNumberFormatted);
567
+ return (0, web3_utils_1.format)({ format: 'uint' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
568
+ });
569
+ }
570
+ exports.estimateGas = estimateGas;
571
+ // TODO - Add input formatting to filter
572
+ /**
573
+ * View additional documentations here: {@link Web3Eth.getPastLogs}
574
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
575
+ */
576
+ function getLogs(web3Context, filter, returnFormat) {
577
+ return __awaiter(this, void 0, void 0, function* () {
578
+ // format type bigint or number toBlock and fromBlock to hexstring.
579
+ let { toBlock, fromBlock } = filter;
580
+ if (!(0, web3_validator_1.isNullish)(toBlock)) {
581
+ if (typeof toBlock === 'number' || typeof toBlock === 'bigint') {
582
+ toBlock = (0, web3_utils_1.numberToHex)(toBlock);
583
+ }
584
+ }
585
+ if (!(0, web3_validator_1.isNullish)(fromBlock)) {
586
+ if (typeof fromBlock === 'number' || typeof fromBlock === 'bigint') {
587
+ fromBlock = (0, web3_utils_1.numberToHex)(fromBlock);
588
+ }
589
+ }
590
+ const formattedFilter = Object.assign(Object.assign({}, filter), { fromBlock, toBlock });
591
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getLogs(web3Context.requestManager, formattedFilter);
592
+ const result = response.map(res => {
593
+ if (typeof res === 'string') {
594
+ return res;
595
+ }
596
+ return (0, web3_utils_1.format)(schemas_js_1.logSchema, res, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
597
+ });
598
+ return result;
599
+ });
600
+ }
601
+ exports.getLogs = getLogs;
602
+ /**
603
+ * View additional documentations here: {@link Web3Eth.getChainId}
604
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
605
+ */
606
+ function getChainId(web3Context, returnFormat) {
607
+ return __awaiter(this, void 0, void 0, function* () {
608
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getChainId(web3Context.requestManager);
609
+ return (0, web3_utils_1.format)({ format: 'uint' },
610
+ // Response is number in hex formatted string
611
+ response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
612
+ });
613
+ }
614
+ exports.getChainId = getChainId;
615
+ /**
616
+ * View additional documentations here: {@link Web3Eth.getProof}
617
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
618
+ */
619
+ function getProof(web3Context, address, storageKeys, blockNumber = web3Context.defaultBlock, returnFormat) {
620
+ return __awaiter(this, void 0, void 0, function* () {
621
+ const storageKeysFormatted = storageKeys.map(storageKey => (0, web3_utils_1.format)({ format: 'bytes' }, storageKey, web3_types_1.ETH_DATA_FORMAT));
622
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
623
+ ? blockNumber
624
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
625
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getProof(web3Context.requestManager, address, storageKeysFormatted, blockNumberFormatted);
626
+ return (0, web3_utils_1.format)(schemas_js_1.accountSchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
627
+ });
628
+ }
629
+ exports.getProof = getProof;
630
+ // TODO Throwing an error with Geth, but not Infura
631
+ // TODO gasUsedRatio and reward not formatting
632
+ /**
633
+ * View additional documentations here: {@link Web3Eth.getFeeHistory}
634
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
635
+ */
636
+ function getFeeHistory(web3Context, blockCount, newestBlock = web3Context.defaultBlock, rewardPercentiles, returnFormat) {
637
+ return __awaiter(this, void 0, void 0, function* () {
638
+ const blockCountFormatted = (0, web3_utils_1.format)({ format: 'uint' }, blockCount, web3_types_1.ETH_DATA_FORMAT);
639
+ const newestBlockFormatted = (0, web3_validator_1.isBlockTag)(newestBlock)
640
+ ? newestBlock
641
+ : (0, web3_utils_1.format)({ format: 'uint' }, newestBlock, web3_types_1.ETH_DATA_FORMAT);
642
+ const rewardPercentilesFormatted = (0, web3_utils_1.format)({
643
+ type: 'array',
644
+ items: {
645
+ format: 'uint',
646
+ },
647
+ }, rewardPercentiles, constants_js_1.NUMBER_DATA_FORMAT);
648
+ const response = yield web3_rpc_methods_1.ethRpcMethods.getFeeHistory(web3Context.requestManager, blockCountFormatted, newestBlockFormatted, rewardPercentilesFormatted);
649
+ return (0, web3_utils_1.format)(schemas_js_1.feeHistorySchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
650
+ });
651
+ }
652
+ exports.getFeeHistory = getFeeHistory;
653
+ /**
654
+ * View additional documentations here: {@link Web3Eth.createAccessList}
655
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
656
+ */
657
+ function createAccessList(web3Context, transaction, blockNumber = web3Context.defaultBlock, returnFormat) {
658
+ return __awaiter(this, void 0, void 0, function* () {
659
+ const blockNumberFormatted = (0, web3_validator_1.isBlockTag)(blockNumber)
660
+ ? blockNumber
661
+ : (0, web3_utils_1.format)({ format: 'uint' }, blockNumber, web3_types_1.ETH_DATA_FORMAT);
662
+ const response = (yield web3_rpc_methods_1.ethRpcMethods.createAccessList(web3Context.requestManager, (0, format_transaction_js_1.formatTransaction)(transaction, web3_types_1.ETH_DATA_FORMAT, {
663
+ transactionSchema: web3Context.config.customTransactionSchema,
664
+ }), blockNumberFormatted));
665
+ return (0, web3_utils_1.format)(schemas_js_1.accessListResultSchema, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
666
+ });
667
+ }
668
+ exports.createAccessList = createAccessList;
669
+ /**
670
+ * View additional documentations here: {@link Web3Eth.signTypedData}
671
+ * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.
672
+ */
673
+ function signTypedData(web3Context, address, typedData, useLegacy, returnFormat) {
674
+ return __awaiter(this, void 0, void 0, function* () {
675
+ const response = yield web3_rpc_methods_1.ethRpcMethods.signTypedData(web3Context.requestManager, address, typedData, useLegacy);
676
+ return (0, web3_utils_1.format)({ format: 'bytes' }, response, returnFormat !== null && returnFormat !== void 0 ? returnFormat : web3Context.defaultReturnFormat);
677
+ });
678
+ }
679
+ exports.signTypedData = signTypedData;
680
+ //# sourceMappingURL=rpc_method_wrappers.js.map