essential-eth 0.9.1-next.0 → 0.9.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,215 +1,28 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _async_to_generator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _class_call_check(instance, Constructor) {
39
- if (!(instance instanceof Constructor)) {
40
- throw new TypeError("Cannot call a class as a function");
41
- }
42
- }
43
- function _defineProperties(target, props) {
44
- for(var i = 0; i < props.length; i++){
45
- var descriptor = props[i];
46
- descriptor.enumerable = descriptor.enumerable || false;
47
- descriptor.configurable = true;
48
- if ("value" in descriptor) descriptor.writable = true;
49
- Object.defineProperty(target, descriptor.key, descriptor);
50
- }
51
- }
52
- function _create_class(Constructor, protoProps, staticProps) {
53
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
54
- if (staticProps) _defineProperties(Constructor, staticProps);
55
- return Constructor;
56
- }
57
- function _define_property(obj, key, value) {
58
- if (key in obj) {
59
- Object.defineProperty(obj, key, {
60
- value: value,
61
- enumerable: true,
62
- configurable: true,
63
- writable: true
64
- });
65
- } else {
66
- obj[key] = value;
67
- }
68
- return obj;
69
- }
70
- function _iterable_to_array_limit(arr, i) {
71
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
72
- if (_i == null) return;
73
- var _arr = [];
74
- var _n = true;
75
- var _d = false;
76
- var _s, _e;
77
- try {
78
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
79
- _arr.push(_s.value);
80
- if (i && _arr.length === i) break;
81
- }
82
- } catch (err) {
83
- _d = true;
84
- _e = err;
85
- } finally{
86
- try {
87
- if (!_n && _i["return"] != null) _i["return"]();
88
- } finally{
89
- if (_d) throw _e;
90
- }
91
- }
92
- return _arr;
93
- }
94
- function _non_iterable_rest() {
95
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
96
- }
97
- function _sliced_to_array(arr, i) {
98
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
- }
100
- function _unsupported_iterable_to_array(o, minLen) {
101
- if (!o) return;
102
- if (typeof o === "string") return _array_like_to_array(o, minLen);
103
- var n = Object.prototype.toString.call(o).slice(8, -1);
104
- if (n === "Object" && o.constructor) n = o.constructor.name;
105
- if (n === "Map" || n === "Set") return Array.from(n);
106
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
107
- }
108
- function _ts_generator(thisArg, body) {
109
- var f, y, t, g, _ = {
110
- label: 0,
111
- sent: function() {
112
- if (t[0] & 1) throw t[1];
113
- return t[1];
114
- },
115
- trys: [],
116
- ops: []
117
- };
118
- return g = {
119
- next: verb(0),
120
- "throw": verb(1),
121
- "return": verb(2)
122
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
123
- return this;
124
- }), g;
125
- function verb(n) {
126
- return function(v) {
127
- return step([
128
- n,
129
- v
130
- ]);
131
- };
132
- }
133
- function step(op) {
134
- if (f) throw new TypeError("Generator is already executing.");
135
- while(_)try {
136
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
137
- if (y = 0, t) op = [
138
- op[0] & 2,
139
- t.value
140
- ];
141
- switch(op[0]){
142
- case 0:
143
- case 1:
144
- t = op;
145
- break;
146
- case 4:
147
- _.label++;
148
- return {
149
- value: op[1],
150
- done: false
151
- };
152
- case 5:
153
- _.label++;
154
- y = op[1];
155
- op = [
156
- 0
157
- ];
158
- continue;
159
- case 7:
160
- op = _.ops.pop();
161
- _.trys.pop();
162
- continue;
163
- default:
164
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
165
- _ = 0;
166
- continue;
167
- }
168
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
169
- _.label = op[1];
170
- break;
171
- }
172
- if (op[0] === 6 && _.label < t[1]) {
173
- _.label = t[1];
174
- t = op;
175
- break;
176
- }
177
- if (t && _.label < t[2]) {
178
- _.label = t[2];
179
- _.ops.push(op);
180
- break;
181
- }
182
- if (t[2]) _.ops.pop();
183
- _.trys.pop();
184
- continue;
185
- }
186
- op = body.call(thisArg, _);
187
- } catch (e) {
188
- op = [
189
- 6,
190
- e
191
- ];
192
- y = 0;
193
- } finally{
194
- f = t = 0;
195
- }
196
- if (op[0] & 5) throw op[1];
197
- return {
198
- value: op[0] ? op[1] : void 0,
199
- done: true
200
- };
201
- }
202
- }
203
- import { cleanBlock } from "../classes/utils/clean-block";
204
- import { cleanLog } from "../classes/utils/clean-log";
205
- import { cleanTransaction } from "../classes/utils/clean-transaction";
206
- import { cleanTransactionReceipt } from "../classes/utils/clean-transaction-receipt";
207
- import { buildRPCPostBody, post } from "../classes/utils/fetchers";
208
- import { hexToDecimal } from "../classes/utils/hex-to-decimal";
209
- import { prepareTransaction } from "../classes/utils/prepare-transaction";
210
- import { logger } from "../logger/logger";
211
- import { tinyBig } from "../shared/tiny-big/tiny-big";
212
- import chainsInfo from "./utils/chains-info";
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BaseProvider = void 0;
16
+ const clean_block_1 = require("../classes/utils/clean-block");
17
+ const clean_log_1 = require("../classes/utils/clean-log");
18
+ const clean_transaction_1 = require("../classes/utils/clean-transaction");
19
+ const clean_transaction_receipt_1 = require("../classes/utils/clean-transaction-receipt");
20
+ const fetchers_1 = require("../classes/utils/fetchers");
21
+ const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
22
+ const prepare_transaction_1 = require("../classes/utils/prepare-transaction");
23
+ const logger_1 = require("../logger/logger");
24
+ const tiny_big_1 = require("../shared/tiny-big/tiny-big");
25
+ const chains_info_1 = __importDefault(require("./utils/chains-info"));
213
26
  /**
214
27
  * Converts a block tag into the right format when needed.
215
28
  *
@@ -229,759 +42,508 @@ import chainsInfo from "./utils/chains-info";
229
42
  * prepBlockTag('0xe290b7');
230
43
  * // '0xe290b7'
231
44
  * ```
232
- */ function prepBlockTag(blockTag) {
233
- return typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag;
45
+ */
46
+ function prepBlockTag(blockTag) {
47
+ return typeof blockTag === 'number'
48
+ ? (0, tiny_big_1.tinyBig)(blockTag).toHexString()
49
+ : blockTag;
234
50
  }
235
- export var BaseProvider = /*#__PURE__*/ function() {
236
- "use strict";
237
- function BaseProvider(rpcUrls) {
238
- var _this = this;
239
- _class_call_check(this, BaseProvider);
51
+ class BaseProvider {
52
+ /**
53
+ * @param rpcUrls The URL(s) to your Eth node(s). Consider POKT or Infura
54
+ * @example
55
+ * `https://free-eth-node.com/api/eth`
56
+ * @example
57
+ * `https://mainnet.infura.io/v3/YOUR-PROJECT-ID`
58
+ */
59
+ constructor(rpcUrls) {
240
60
  /**
241
- * @ignore
242
- */ _define_property(this, "_rpcUrls", []);
61
+ * @ignore
62
+ */
63
+ this._rpcUrls = [];
243
64
  /**
244
- * @ignore
245
- */ _define_property(this, "_post", function(body) {
246
- return post(_this.selectRpcUrl(), body);
247
- });
65
+ * @ignore
66
+ */
67
+ this._post = (body) => (0, fetchers_1.post)(this.selectRpcUrl(), body);
248
68
  this._rpcUrls = rpcUrls;
249
69
  }
250
- _create_class(BaseProvider, [
251
- {
252
- key: "getNetwork",
253
- value: /**
254
- * Gets information (name, chainId, and ensAddress when applicable) about the network the provider is connected to.
255
- *
256
- * * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
257
- * * [Similar](/docs/api#isd) to [`web3.eth.getChainId`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getchainid) in web3.js, returns more than just the `chainId`
258
- *
259
- * @returns information about the network this provider is currently connected to
260
- * @example
261
- * ```javascript
262
- * jsonRpcProvider('https://free-eth-node.com/api/eth').getNetwork();
263
- * // { chainId: 1, name: 'eth', ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' }
264
- * ```
265
- * @example
266
- * ```javascript
267
- * jsonRpcProvider('https://free-eth-node.com/api/MATIC').getNetwork();
268
- * // { chainId: 137, name: 'MATIC', ensAddress: null }
269
- * ```
270
- */ function getNetwork() {
271
- var _this = this;
272
- return _async_to_generator(function() {
273
- var hexChainId, chainId, info;
274
- return _ts_generator(this, function(_state) {
275
- switch(_state.label){
276
- case 0:
277
- return [
278
- 4,
279
- _this.post(buildRPCPostBody("eth_chainId", []))
280
- ];
281
- case 1:
282
- hexChainId = _state.sent();
283
- chainId = hexToDecimal(hexChainId);
284
- info = chainsInfo[chainId];
285
- return [
286
- 2,
287
- {
288
- chainId: Number(chainId),
289
- name: info[0] || "unknown",
290
- ensAddress: info[1] || null
291
- }
292
- ];
293
- }
294
- });
295
- })();
296
- }
297
- },
298
- {
299
- key: "getBlockNumber",
300
- value: /**
301
- * Gets the number of the most recently mined block on the network the provider is connected to.
302
- *
303
- * * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
304
- * * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
305
- *
306
- * @returns the number of the most recently mined block
307
- * @example
308
- * ```javascript
309
- * await provider.getBlockNumber();
310
- * // 1053312
311
- * ```
312
- */ function getBlockNumber() {
313
- var _this = this;
314
- return _async_to_generator(function() {
315
- var currentBlockNumber;
316
- return _ts_generator(this, function(_state) {
317
- switch(_state.label){
318
- case 0:
319
- return [
320
- 4,
321
- _this.post(buildRPCPostBody("eth_blockNumber", []))
322
- ];
323
- case 1:
324
- currentBlockNumber = _state.sent();
325
- return [
326
- 2,
327
- Number(hexToDecimal(currentBlockNumber))
328
- ];
329
- }
330
- });
331
- })();
332
- }
333
- },
334
- {
335
- key: "getTransaction",
336
- value: /**
337
- * Gets information about a specified transaction, even if it hasn't been mined yet.
338
- *
339
- * * [Similar](/docs/api#isd) to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction) in ethers.js, does not have `wait` method that waits until the transaction has been mined
340
- * * [Similar](/docs/api#isd) to [`web3.eth.getTransaction`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransaction) in web3.js, some information returned using different types
341
- *
342
- * @param transactionHash the hash of the transaction to get information about
343
- * @returns information about the specified transaction
344
- * @example
345
- * ```javascript
346
- * await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
347
- * // {
348
- * // accessList: [],
349
- * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
350
- * // blockNumber: 14578286,
351
- * // chainId: 1,
352
- * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
353
- * // gas: { TinyBig: 112163 },
354
- * // gasPrice: { TinyBig: 48592426858 },
355
- * // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
356
- * // input: "0x83259f17000000000000000000000000000000000000000000...",
357
- * // maxFeePerGas: { TinyBig: 67681261618 },
358
- * // maxPriorityFeePerGas: { TinyBig: 1500000000 },
359
- * // nonce: { TinyBig: 129 },
360
- * // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
361
- * // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
362
- * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
363
- * // transactionIndex: 29,
364
- * // type: 2,
365
- * // v: 0,
366
- * // value: { TinyBig: 0 },
367
- * // confirmations: 298140,
368
- * // }
369
- * ```
370
- */ function getTransaction(transactionHash) {
371
- var _this = this;
372
- return _async_to_generator(function() {
373
- var _ref, rpcTransaction, blockNumber, cleanedTransaction;
374
- return _ts_generator(this, function(_state) {
375
- switch(_state.label){
376
- case 0:
377
- return [
378
- 4,
379
- Promise.all([
380
- _this.post(buildRPCPostBody("eth_getTransactionByHash", [
381
- transactionHash
382
- ])),
383
- _this.getBlock("latest")
384
- ])
385
- ];
386
- case 1:
387
- _ref = _sliced_to_array.apply(void 0, [
388
- _state.sent(),
389
- 2
390
- ]), rpcTransaction = _ref[0], blockNumber = _ref[1];
391
- cleanedTransaction = cleanTransaction(rpcTransaction);
392
- // https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
393
- cleanedTransaction.confirmations = blockNumber.number - cleanedTransaction.blockNumber + 1;
394
- return [
395
- 2,
396
- cleanedTransaction
397
- ];
398
- }
399
- });
400
- })();
401
- }
402
- },
403
- {
404
- key: "getTransactionReceipt",
405
- value: /**
406
- * Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by [`getTransaction`](/docs/api/modules#gettransaction).
407
- *
408
- * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
409
- * * [Similar](/docs/api#isd) to [`web3.eth.getTransactionReceipt`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactionreceipt) in web3.js, some information returned using different types
410
- *
411
- * @param transactionHash the hash of the transaction to get information about
412
- * @returns information about the specified transaction that has already been mined
413
- * @example
414
- * ```javascript
415
- * await provider.getTransactionReceipt('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
416
- * // {
417
- * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
418
- * // blockNumber: 14578286,
419
- * // contractAddress: null,
420
- * // cumulativeGasUsed: { TinyBig: 3067973 },
421
- * // effectiveGasPrice: { TinyBig: 48592426858 },
422
- * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
423
- * // gasUsed: { TinyBig: 112163 },
424
- * // logs: [
425
- * // {
426
- * // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
427
- * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
428
- * // blockNumber: 14578286,
429
- * // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
430
- * // logIndex: 42,
431
- * // topics: [
432
- * // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
433
- * // "0x00000000000000000000000039b72d136ba3e4cef35f48cd09587ffab754dd8b",
434
- * // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
435
- * // ],
436
- * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
437
- * // transactionIndex: 29,
438
- * // },
439
- * // {
440
- * // address: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
441
- * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
442
- * // blockNumber: 14578286,
443
- * // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
444
- * // logIndex: 43,
445
- * // topics: [
446
- * // "0x34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7",
447
- * // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
448
- * // "0x0000000000000000000000000000000000000000000000000000000000000003",
449
- * // ],
450
- * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
451
- * // transactionIndex: 29,
452
- * // },
453
- * // ],
454
- * // logsBloom: "0x00000000000000000000000000000...",
455
- * // status: 1,
456
- * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
457
- * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
458
- * // transactionIndex: 29,
459
- * // type: 2,
460
- * // byzantium: true,
461
- * // confirmations: 298171,
462
- * // }
463
- * ```
464
- */ function getTransactionReceipt(transactionHash) {
465
- var _this = this;
466
- return _async_to_generator(function() {
467
- var _ref, rpcTransaction, blockNumber, cleanedTransactionReceipt;
468
- return _ts_generator(this, function(_state) {
469
- switch(_state.label){
470
- case 0:
471
- return [
472
- 4,
473
- Promise.all([
474
- _this.post(buildRPCPostBody("eth_getTransactionReceipt", [
475
- transactionHash
476
- ])),
477
- _this.getBlock("latest")
478
- ])
479
- ];
480
- case 1:
481
- _ref = _sliced_to_array.apply(void 0, [
482
- _state.sent(),
483
- 2
484
- ]), rpcTransaction = _ref[0], blockNumber = _ref[1];
485
- cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
486
- cleanedTransactionReceipt.confirmations = blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
487
- return [
488
- 2,
489
- cleanedTransactionReceipt
490
- ];
491
- }
492
- });
493
- })();
494
- }
495
- },
496
- {
497
- key: "getTransactionCount",
498
- value: /**
499
- * Returns the number of sent transactions by an address, from genesis (or as far back as a provider looks) up to specified block.
500
- *
501
- * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
502
- * * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
503
- *
504
- * @param address the address to count number of sent transactions
505
- * @param blockTag the block to count transactions up to, inclusive
506
- * @returns the number of transactions sent by the specified address
507
- * @example
508
- * ```javascript
509
- * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3');
510
- * // 1060000
511
- * ```
512
- * @example
513
- * ```javascript
514
- * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 'latest');
515
- * // 1060000
516
- * ```
517
- * @example
518
- * ```javascript
519
- * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 14649390);
520
- * // 1053312
521
- * ```
522
- */ function getTransactionCount(address) {
523
- var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
524
- var _this = this;
525
- return _async_to_generator(function() {
526
- var transactionCount;
527
- return _ts_generator(this, function(_state) {
528
- switch(_state.label){
529
- case 0:
530
- blockTag = prepBlockTag(blockTag);
531
- return [
532
- 4,
533
- _this.post(buildRPCPostBody("eth_getTransactionCount", [
534
- address,
535
- blockTag
536
- ]))
537
- ];
538
- case 1:
539
- transactionCount = _state.sent();
540
- return [
541
- 2,
542
- Number(hexToDecimal(transactionCount))
543
- ];
544
- }
545
- });
546
- })();
547
- }
548
- },
549
- {
550
- key: "getBlock",
551
- value: /**
552
- * Gets information about a certain block, optionally with full transaction objects.
553
- *
554
- * * [Similar](/docs/api#isd) to [`ethers.provider.getBlock`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js, includes some additional information. Can also return block with full transaction objects, similar to [`ethers.providers.getBlockWithTransactions`]
555
- * * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
556
- *
557
- * @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
558
- * @param returnTransactionObjects Whether to also return data about the transactions on the block.
559
- * @returns A BlockResponse object with information about the specified block
560
- * @example
561
- * ```javascript
562
- * await provider.getBlock(14879862);
563
- * // {
564
- * // baseFeePerGas: { TinyBig: 39095728776 },
565
- * // difficulty: { TinyBig: 14321294455359973 },
566
- * // extraData: "0x486976656f6e2073672d6865617679",
567
- * // gasLimit: { TinyBig: 29970620 },
568
- * // gasUsed: { TinyBig: 20951384 },
569
- * // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
570
- * // logsBloom:
571
- * // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
572
- * // miner: "0x1aD91ee08f21bE3dE0BA2ba6918E714dA6B45836",
573
- * // mixHash: "0x73cc9419bfb89c9d41c3a8c34ce56b5ebe468bdcf870258d2e77262275d580ec",
574
- * // nonce: "0x976f3f5d596ffb08",
575
- * // number: 14879862,
576
- * // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
577
- * // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
578
- * // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
579
- * // size: { TinyBig: 134483 },
580
- * // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
581
- * // timestamp: { TinyBig: 1654016186 },
582
- * // totalDifficulty: { TinyBig: 50478104614257705213748 },
583
- * // transactions: [
584
- * // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
585
- * // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
586
- * // "0x882f78fcb73f0f7ad0700bb0424a8b4beb366aaa93b88a3562c49a8d0ce4dcff",
587
- * // ...
588
- * // ],
589
- * // transactionsRoot: "0x5934902f3dcc263ec34f24318179bf6301f53f4834685792066026f3a4849d72",
590
- * // uncles: [],
591
- * // }
592
- * ```
593
- */ function getBlock() {
594
- var timeFrame = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "latest", returnTransactionObjects = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
595
- var _this = this;
596
- return _async_to_generator(function() {
597
- var type, rpcBlock;
598
- return _ts_generator(this, function(_state) {
599
- switch(_state.label){
600
- case 0:
601
- type = "Number";
602
- if (typeof timeFrame === "string" && timeFrame.length === 66) {
603
- // use endpoint that accepts string
604
- type = "Hash";
605
- } else {
606
- timeFrame = prepBlockTag(timeFrame);
607
- }
608
- return [
609
- 4,
610
- _this.post(buildRPCPostBody("eth_getBlockBy".concat(type), [
611
- timeFrame,
612
- returnTransactionObjects
613
- ]))
614
- ];
615
- case 1:
616
- rpcBlock = _state.sent();
617
- return [
618
- 2,
619
- cleanBlock(rpcBlock, returnTransactionObjects)
620
- ];
621
- }
622
- });
623
- })();
624
- }
625
- },
626
- {
627
- key: "getGasPrice",
628
- value: /**
629
- * Gives an estimate of the current gas price in wei.
630
- *
631
- * * [Similar](/docs/api#isd) to [`ethers.provider.getGasPrice`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getGasPrice) in ethers.js, does not have a parameter specifying what unit you'd like to return. See also [`weiToEther`](/docs/api/modules#weitoether) and [`etherToGwei`](/docs/api/modules#ethertogwei)
632
- * * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (TinyBig) instead of a string
633
- *
634
- * @returns an estimate of the current gas price in wei
635
- * @example
636
- * ```javascript
637
- * await provider.getGasPrice();
638
- * // 52493941856
639
- * ```
640
- */ function getGasPrice() {
641
- var _this = this;
642
- return _async_to_generator(function() {
643
- var hexGasPrice;
644
- return _ts_generator(this, function(_state) {
645
- switch(_state.label){
646
- case 0:
647
- return [
648
- 4,
649
- _this.post(buildRPCPostBody("eth_gasPrice", []))
650
- ];
651
- case 1:
652
- hexGasPrice = _state.sent();
653
- return [
654
- 2,
655
- tinyBig(hexToDecimal(hexGasPrice))
656
- ];
657
- }
658
- });
659
- })();
660
- }
661
- },
662
- {
663
- key: "getBalance",
664
- value: /**
665
- * Returns the balance of the account in wei.
666
- *
667
- * * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
668
- * * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (TinyBig) instead of a string
669
- *
670
- * @param address the address to check the balance of
671
- * @param blockTag the block to check the specified address' balance on
672
- * @returns the balance of the network's native token for the specified address on the specified block
673
- * @example
674
- * ```javascript
675
- * await provider.getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8');
676
- * // 28798127851528138
677
- * ```
678
- */ function getBalance(address) {
679
- var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
680
- var _this = this;
681
- return _async_to_generator(function() {
682
- var hexBalance;
683
- return _ts_generator(this, function(_state) {
684
- switch(_state.label){
685
- case 0:
686
- blockTag = prepBlockTag(blockTag);
687
- return [
688
- 4,
689
- _this.post(buildRPCPostBody("eth_getBalance", [
690
- address,
691
- blockTag
692
- ]))
693
- ];
694
- case 1:
695
- hexBalance = _state.sent();
696
- return [
697
- 2,
698
- tinyBig(hexToDecimal(hexBalance))
699
- ];
700
- }
701
- });
702
- })();
703
- }
704
- },
705
- {
706
- key: "getCode",
707
- value: /**
708
- * Gets the code of a contract on a specified block.
709
- *
710
- * * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
711
- * * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
712
- *
713
- * @param address the contract address to get the contract code from
714
- * @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
715
- * @returns the contract creation code for the specified address at the specified block height
716
- * @example
717
- * ```javascript
718
- * await jsonRpcProvider().getCode('0xaC6095720221C79C6E7C638d260A2eFBC5D8d880', 'latest');
719
- * // '0x608060405234801561001057600080fd5b506004361061...'
720
- * ```
721
- */ function getCode(address) {
722
- var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
723
- var _this = this;
724
- return _async_to_generator(function() {
725
- var contractCode;
726
- return _ts_generator(this, function(_state) {
727
- switch(_state.label){
728
- case 0:
729
- blockTag = prepBlockTag(blockTag);
730
- return [
731
- 4,
732
- _this.post(buildRPCPostBody("eth_getCode", [
733
- address,
734
- blockTag
735
- ]))
736
- ];
737
- case 1:
738
- contractCode = _state.sent();
739
- return [
740
- 2,
741
- contractCode
742
- ];
743
- }
744
- });
745
- })();
70
+ /**
71
+ * Gets information (name, chainId, and ensAddress when applicable) about the network the provider is connected to.
72
+ *
73
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
74
+ * * [Similar](/docs/api#isd) to [`web3.eth.getChainId`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getchainid) in web3.js, returns more than just the `chainId`
75
+ *
76
+ * @returns information about the network this provider is currently connected to
77
+ * @example
78
+ * ```javascript
79
+ * jsonRpcProvider('https://free-eth-node.com/api/eth').getNetwork();
80
+ * // { chainId: 1, name: 'eth', ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' }
81
+ * ```
82
+ * @example
83
+ * ```javascript
84
+ * jsonRpcProvider('https://free-eth-node.com/api/MATIC').getNetwork();
85
+ * // { chainId: 137, name: 'MATIC', ensAddress: null }
86
+ * ```
87
+ */
88
+ getNetwork() {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const hexChainId = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_chainId', [])));
91
+ const chainId = (0, hex_to_decimal_1.hexToDecimal)(hexChainId);
92
+ const info = chains_info_1.default[chainId];
93
+ return {
94
+ chainId: Number(chainId),
95
+ name: info[0] || 'unknown',
96
+ ensAddress: info[1] || null, // only send ensAddress if it exists
97
+ };
98
+ });
99
+ }
100
+ /**
101
+ * Gets the number of the most recently mined block on the network the provider is connected to.
102
+ *
103
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
104
+ * * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
105
+ *
106
+ * @returns the number of the most recently mined block
107
+ * @example
108
+ * ```javascript
109
+ * await provider.getBlockNumber();
110
+ * // 1053312
111
+ * ```
112
+ */
113
+ getBlockNumber() {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const currentBlockNumber = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_blockNumber', [])));
116
+ return Number((0, hex_to_decimal_1.hexToDecimal)(currentBlockNumber));
117
+ });
118
+ }
119
+ /**
120
+ * Gets information about a specified transaction, even if it hasn't been mined yet.
121
+ *
122
+ * * [Similar](/docs/api#isd) to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction) in ethers.js, does not have `wait` method that waits until the transaction has been mined
123
+ * * [Similar](/docs/api#isd) to [`web3.eth.getTransaction`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransaction) in web3.js, some information returned using different types
124
+ *
125
+ * @param transactionHash the hash of the transaction to get information about
126
+ * @returns information about the specified transaction
127
+ * @example
128
+ * ```javascript
129
+ * await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
130
+ * // {
131
+ * // accessList: [],
132
+ * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
133
+ * // blockNumber: 14578286,
134
+ * // chainId: 1,
135
+ * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
136
+ * // gas: { TinyBig: 112163 },
137
+ * // gasPrice: { TinyBig: 48592426858 },
138
+ * // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
139
+ * // input: "0x83259f17000000000000000000000000000000000000000000...",
140
+ * // maxFeePerGas: { TinyBig: 67681261618 },
141
+ * // maxPriorityFeePerGas: { TinyBig: 1500000000 },
142
+ * // nonce: { TinyBig: 129 },
143
+ * // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
144
+ * // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
145
+ * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
146
+ * // transactionIndex: 29,
147
+ * // type: 2,
148
+ * // v: 0,
149
+ * // value: { TinyBig: 0 },
150
+ * // confirmations: 298140,
151
+ * // }
152
+ * ```
153
+ */
154
+ getTransaction(transactionHash) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ const [rpcTransaction, blockNumber] = yield Promise.all([
157
+ this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionByHash', [transactionHash])),
158
+ this.getBlock('latest'),
159
+ ]);
160
+ const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(rpcTransaction);
161
+ // https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
162
+ cleanedTransaction.confirmations =
163
+ blockNumber.number - cleanedTransaction.blockNumber + 1;
164
+ return cleanedTransaction;
165
+ });
166
+ }
167
+ /**
168
+ * Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by [`getTransaction`](/docs/api/modules#gettransaction).
169
+ *
170
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
171
+ * * [Similar](/docs/api#isd) to [`web3.eth.getTransactionReceipt`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactionreceipt) in web3.js, some information returned using different types
172
+ *
173
+ * @param transactionHash the hash of the transaction to get information about
174
+ * @returns information about the specified transaction that has already been mined
175
+ * @example
176
+ * ```javascript
177
+ * await provider.getTransactionReceipt('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
178
+ * // {
179
+ * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
180
+ * // blockNumber: 14578286,
181
+ * // contractAddress: null,
182
+ * // cumulativeGasUsed: { TinyBig: 3067973 },
183
+ * // effectiveGasPrice: { TinyBig: 48592426858 },
184
+ * // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
185
+ * // gasUsed: { TinyBig: 112163 },
186
+ * // logs: [
187
+ * // {
188
+ * // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
189
+ * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
190
+ * // blockNumber: 14578286,
191
+ * // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
192
+ * // logIndex: 42,
193
+ * // topics: [
194
+ * // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
195
+ * // "0x00000000000000000000000039b72d136ba3e4cef35f48cd09587ffab754dd8b",
196
+ * // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
197
+ * // ],
198
+ * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
199
+ * // transactionIndex: 29,
200
+ * // },
201
+ * // {
202
+ * // address: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
203
+ * // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
204
+ * // blockNumber: 14578286,
205
+ * // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
206
+ * // logIndex: 43,
207
+ * // topics: [
208
+ * // "0x34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7",
209
+ * // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
210
+ * // "0x0000000000000000000000000000000000000000000000000000000000000003",
211
+ * // ],
212
+ * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
213
+ * // transactionIndex: 29,
214
+ * // },
215
+ * // ],
216
+ * // logsBloom: "0x00000000000000000000000000000...",
217
+ * // status: 1,
218
+ * // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
219
+ * // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
220
+ * // transactionIndex: 29,
221
+ * // type: 2,
222
+ * // byzantium: true,
223
+ * // confirmations: 298171,
224
+ * // }
225
+ * ```
226
+ */
227
+ getTransactionReceipt(transactionHash) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ const [rpcTransaction, blockNumber] = yield Promise.all([
230
+ this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionReceipt', [transactionHash])),
231
+ this.getBlock('latest'),
232
+ ]);
233
+ const cleanedTransactionReceipt = (0, clean_transaction_receipt_1.cleanTransactionReceipt)(rpcTransaction);
234
+ cleanedTransactionReceipt.confirmations =
235
+ blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
236
+ return cleanedTransactionReceipt;
237
+ });
238
+ }
239
+ /**
240
+ * Returns the number of sent transactions by an address, from genesis (or as far back as a provider looks) up to specified block.
241
+ *
242
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
243
+ * * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
244
+ *
245
+ * @param address the address to count number of sent transactions
246
+ * @param blockTag the block to count transactions up to, inclusive
247
+ * @returns the number of transactions sent by the specified address
248
+ * @example
249
+ * ```javascript
250
+ * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3');
251
+ * // 1060000
252
+ * ```
253
+ * @example
254
+ * ```javascript
255
+ * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 'latest');
256
+ * // 1060000
257
+ * ```
258
+ * @example
259
+ * ```javascript
260
+ * await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 14649390);
261
+ * // 1053312
262
+ * ```
263
+ */
264
+ getTransactionCount(address, blockTag = 'latest') {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ blockTag = prepBlockTag(blockTag);
267
+ const transactionCount = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionCount', [address, blockTag])));
268
+ return Number((0, hex_to_decimal_1.hexToDecimal)(transactionCount));
269
+ });
270
+ }
271
+ /**
272
+ * Gets information about a certain block, optionally with full transaction objects.
273
+ *
274
+ * * [Similar](/docs/api#isd) to [`ethers.provider.getBlock`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js, includes some additional information. Can also return block with full transaction objects, similar to [`ethers.providers.getBlockWithTransactions`]
275
+ * * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
276
+ *
277
+ * @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
278
+ * @param returnTransactionObjects Whether to also return data about the transactions on the block.
279
+ * @returns A BlockResponse object with information about the specified block
280
+ * @example
281
+ * ```javascript
282
+ * await provider.getBlock(14879862);
283
+ * // {
284
+ * // baseFeePerGas: { TinyBig: 39095728776 },
285
+ * // difficulty: { TinyBig: 14321294455359973 },
286
+ * // extraData: "0x486976656f6e2073672d6865617679",
287
+ * // gasLimit: { TinyBig: 29970620 },
288
+ * // gasUsed: { TinyBig: 20951384 },
289
+ * // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
290
+ * // logsBloom:
291
+ * // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
292
+ * // miner: "0x1aD91ee08f21bE3dE0BA2ba6918E714dA6B45836",
293
+ * // mixHash: "0x73cc9419bfb89c9d41c3a8c34ce56b5ebe468bdcf870258d2e77262275d580ec",
294
+ * // nonce: "0x976f3f5d596ffb08",
295
+ * // number: 14879862,
296
+ * // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
297
+ * // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
298
+ * // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
299
+ * // size: { TinyBig: 134483 },
300
+ * // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
301
+ * // timestamp: { TinyBig: 1654016186 },
302
+ * // totalDifficulty: { TinyBig: 50478104614257705213748 },
303
+ * // transactions: [
304
+ * // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
305
+ * // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
306
+ * // "0x882f78fcb73f0f7ad0700bb0424a8b4beb366aaa93b88a3562c49a8d0ce4dcff",
307
+ * // ...
308
+ * // ],
309
+ * // transactionsRoot: "0x5934902f3dcc263ec34f24318179bf6301f53f4834685792066026f3a4849d72",
310
+ * // uncles: [],
311
+ * // }
312
+ * ```
313
+ */
314
+ getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
315
+ return __awaiter(this, void 0, void 0, function* () {
316
+ let type = 'Number';
317
+ if (typeof timeFrame === 'string' && timeFrame.length === 66) {
318
+ // use endpoint that accepts string
319
+ type = 'Hash';
746
320
  }
747
- },
748
- {
749
- key: "estimateGas",
750
- value: /**
751
- * Returns an estimate of the amount of gas that would be required to submit transaction to the network.
752
- * An estimate may not be accurate since there could be another transaction on the network that was not accounted for.
753
- *
754
- * * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
755
- * * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
756
- *
757
- * @param transaction the transaction to check the estimated gas cost for
758
- * @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
759
- * @example
760
- * ```javascript
761
- * await provider.estimateGas({
762
- * // Wrapped ETH address
763
- * to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
764
- * data: "0xd0e30db0",
765
- * value: etherToWei('1.0').toHexString(),
766
- * });
767
- * // { TinyBig: "27938" }
768
- * ```
769
- */ function estimateGas(transaction) {
770
- var _this = this;
771
- return _async_to_generator(function() {
772
- var rpcTransaction, gasUsed;
773
- return _ts_generator(this, function(_state) {
774
- switch(_state.label){
775
- case 0:
776
- rpcTransaction = prepareTransaction(transaction);
777
- return [
778
- 4,
779
- _this.post(buildRPCPostBody("eth_estimateGas", [
780
- rpcTransaction
781
- ]))
782
- ];
783
- case 1:
784
- gasUsed = _state.sent();
785
- return [
786
- 2,
787
- tinyBig(hexToDecimal(gasUsed))
788
- ];
789
- }
790
- });
791
- })();
321
+ else {
322
+ timeFrame = prepBlockTag(timeFrame);
792
323
  }
793
- },
794
- {
795
- key: "getFeeData",
796
- value: /**
797
- * Returns the current recommended FeeData to use in a transaction.
798
- * For an EIP-1559 transaction, the maxFeePerGas and maxPriorityFeePerGas should be used.
799
- * For legacy transactions and networks which do not support EIP-1559, the gasPrice should be used.Returns an estimate of the amount of gas that would be required to submit transaction to the network.
800
- *
801
- * * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
802
- *
803
- * @returns an object with gas estimates for the network currently
804
- * @example
805
- * ```javascript
806
- * await provider.getFeeData();
807
- * // {
808
- * // gasPrice: { TinyBig: "14184772639" },
809
- * // lastBaseFeePerGas: { TinyBig: "14038523098" },
810
- * // maxFeePerGas: { TinyBig: "29577046196" },
811
- * // maxPriorityFeePerGas: { TinyBig: "1500000000" }
812
- * // }
813
- * ```
814
- */ function getFeeData() {
815
- var _this = this;
816
- return _async_to_generator(function() {
817
- var _ref, block, gasPrice, lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas;
818
- return _ts_generator(this, function(_state) {
819
- switch(_state.label){
820
- case 0:
821
- return [
822
- 4,
823
- Promise.all([
824
- _this.getBlock("latest"),
825
- _this.getGasPrice()
826
- ])
827
- ];
828
- case 1:
829
- _ref = _sliced_to_array.apply(void 0, [
830
- _state.sent(),
831
- 2
832
- ]), block = _ref[0], gasPrice = _ref[1];
833
- lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
834
- if (block && block.baseFeePerGas) {
835
- // We may want to compute this more accurately in the future,
836
- // using the formula "check if the base fee is correct".
837
- // See: https://eips.ethereum.org/EIPS/eip-1559
838
- lastBaseFeePerGas = block.baseFeePerGas;
839
- maxPriorityFeePerGas = tinyBig("1500000000");
840
- maxFeePerGas = tinyBig(block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas));
841
- }
842
- return [
843
- 2,
844
- {
845
- lastBaseFeePerGas: lastBaseFeePerGas,
846
- maxFeePerGas: maxFeePerGas,
847
- maxPriorityFeePerGas: maxPriorityFeePerGas,
848
- gasPrice: gasPrice
849
- }
850
- ];
851
- }
852
- });
853
- })();
324
+ const rpcBlock = (yield this.post((0, fetchers_1.buildRPCPostBody)(`eth_getBlockBy${type}`, [
325
+ timeFrame,
326
+ returnTransactionObjects,
327
+ ])));
328
+ return (0, clean_block_1.cleanBlock)(rpcBlock, returnTransactionObjects);
329
+ });
330
+ }
331
+ /**
332
+ * Gives an estimate of the current gas price in wei.
333
+ *
334
+ * * [Similar](/docs/api#isd) to [`ethers.provider.getGasPrice`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getGasPrice) in ethers.js, does not have a parameter specifying what unit you'd like to return. See also [`weiToEther`](/docs/api/modules#weitoether) and [`etherToGwei`](/docs/api/modules#ethertogwei)
335
+ * * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (TinyBig) instead of a string
336
+ *
337
+ * @returns an estimate of the current gas price in wei
338
+ * @example
339
+ * ```javascript
340
+ * await provider.getGasPrice();
341
+ * // 52493941856
342
+ * ```
343
+ */
344
+ getGasPrice() {
345
+ return __awaiter(this, void 0, void 0, function* () {
346
+ const hexGasPrice = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_gasPrice', [])));
347
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexGasPrice));
348
+ });
349
+ }
350
+ /**
351
+ * Returns the balance of the account in wei.
352
+ *
353
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
354
+ * * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (TinyBig) instead of a string
355
+ *
356
+ * @param address the address to check the balance of
357
+ * @param blockTag the block to check the specified address' balance on
358
+ * @returns the balance of the network's native token for the specified address on the specified block
359
+ * @example
360
+ * ```javascript
361
+ * await provider.getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8');
362
+ * // 28798127851528138
363
+ * ```
364
+ */
365
+ getBalance(address, blockTag = 'latest') {
366
+ return __awaiter(this, void 0, void 0, function* () {
367
+ blockTag = prepBlockTag(blockTag);
368
+ const hexBalance = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag])));
369
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
370
+ });
371
+ }
372
+ /**
373
+ * Gets the code of a contract on a specified block.
374
+ *
375
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
376
+ * * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
377
+ *
378
+ * @param address the contract address to get the contract code from
379
+ * @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
380
+ * @returns the contract creation code for the specified address at the specified block height
381
+ * @example
382
+ * ```javascript
383
+ * await jsonRpcProvider().getCode('0xaC6095720221C79C6E7C638d260A2eFBC5D8d880', 'latest');
384
+ * // '0x608060405234801561001057600080fd5b506004361061...'
385
+ * ```
386
+ */
387
+ getCode(address, blockTag = 'latest') {
388
+ return __awaiter(this, void 0, void 0, function* () {
389
+ blockTag = prepBlockTag(blockTag);
390
+ const contractCode = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getCode', [address, blockTag])));
391
+ return contractCode;
392
+ });
393
+ }
394
+ /**
395
+ * Returns an estimate of the amount of gas that would be required to submit transaction to the network.
396
+ * An estimate may not be accurate since there could be another transaction on the network that was not accounted for.
397
+ *
398
+ * * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
399
+ * * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
400
+ *
401
+ * @param transaction the transaction to check the estimated gas cost for
402
+ * @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
403
+ * @example
404
+ * ```javascript
405
+ * await provider.estimateGas({
406
+ * // Wrapped ETH address
407
+ * to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
408
+ * data: "0xd0e30db0",
409
+ * value: etherToWei('1.0').toHexString(),
410
+ * });
411
+ * // { TinyBig: "27938" }
412
+ * ```
413
+ */
414
+ estimateGas(transaction) {
415
+ return __awaiter(this, void 0, void 0, function* () {
416
+ const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
417
+ const gasUsed = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_estimateGas', [rpcTransaction])));
418
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(gasUsed));
419
+ });
420
+ }
421
+ /**
422
+ * Returns the current recommended FeeData to use in a transaction.
423
+ * For an EIP-1559 transaction, the maxFeePerGas and maxPriorityFeePerGas should be used.
424
+ * For legacy transactions and networks which do not support EIP-1559, the gasPrice should be used.Returns an estimate of the amount of gas that would be required to submit transaction to the network.
425
+ *
426
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
427
+ *
428
+ * @returns an object with gas estimates for the network currently
429
+ * @example
430
+ * ```javascript
431
+ * await provider.getFeeData();
432
+ * // {
433
+ * // gasPrice: { TinyBig: "14184772639" },
434
+ * // lastBaseFeePerGas: { TinyBig: "14038523098" },
435
+ * // maxFeePerGas: { TinyBig: "29577046196" },
436
+ * // maxPriorityFeePerGas: { TinyBig: "1500000000" }
437
+ * // }
438
+ * ```
439
+ */
440
+ getFeeData() {
441
+ return __awaiter(this, void 0, void 0, function* () {
442
+ const [block, gasPrice] = yield Promise.all([
443
+ this.getBlock('latest'),
444
+ this.getGasPrice(),
445
+ ]);
446
+ let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
447
+ if (block && block.baseFeePerGas) {
448
+ // We may want to compute this more accurately in the future,
449
+ // using the formula "check if the base fee is correct".
450
+ // See: https://eips.ethereum.org/EIPS/eip-1559
451
+ lastBaseFeePerGas = block.baseFeePerGas;
452
+ maxPriorityFeePerGas = (0, tiny_big_1.tinyBig)('1500000000');
453
+ maxFeePerGas = (0, tiny_big_1.tinyBig)(block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas));
854
454
  }
855
- },
856
- {
857
- key: "getLogs",
858
- value: /**
859
- * Returns transaction receipt event logs that match a specified filter.
860
- * May return `[]` if parameters are too broad, even if logs exist.
861
- *
862
- * * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
863
- * * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
864
- *
865
- * @param filter parameters to filter the logs by
866
- * @returns an array of logs matching the specified filter
867
- * @example
868
- * ```javascript
869
- * provider.getLogs({
870
- * address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
871
- * topics: [
872
- * "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
873
- * "0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e",
874
- * ],
875
- * fromBlock: 14825027,
876
- * toBlock: 14825039,
877
- * });
878
- *
879
- * [
880
- * {
881
- * address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
882
- * blockHash: '0x8e0dfac2f704851960f866c8708b3bef2f66c0fee0329cf25ff0261b264ca6bc',
883
- * blockNumber: 14825029,
884
- * data: '0x000000000000000000000000000000000000000000000000005f862ee352a38a',
885
- * logIndex: 384,
886
- * removed: false,
887
- * topics: [
888
- * '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
889
- * '0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e',
890
- * '0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
891
- * ],
892
- * transactionHash: '0xbd49031be16f8fd1775f4e0fe79b408ffd8ae9c65b2827ee47e3238e3f51f4c0',
893
- * transactionIndex: 226
894
- * }
895
- * ]
896
- * ```
897
- */ function getLogs(filter) {
898
- var _this = this;
899
- return _async_to_generator(function() {
900
- var filterByRange, rpcLogs, logs;
901
- return _ts_generator(this, function(_state) {
902
- switch(_state.label){
903
- case 0:
904
- filterByRange = filter;
905
- if (filterByRange.fromBlock) filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
906
- if (filterByRange.toBlock) filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
907
- return [
908
- 4,
909
- _this.post(buildRPCPostBody("eth_getLogs", [
910
- filter
911
- ]))
912
- ];
913
- case 1:
914
- rpcLogs = _state.sent();
915
- logs = rpcLogs.map(function(log) {
916
- return cleanLog(log, false);
917
- });
918
- return [
919
- 2,
920
- logs
921
- ];
922
- }
923
- });
924
- })();
455
+ return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
456
+ });
457
+ }
458
+ /**
459
+ * Returns transaction receipt event logs that match a specified filter.
460
+ * May return `[]` if parameters are too broad, even if logs exist.
461
+ *
462
+ * * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
463
+ * * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
464
+ *
465
+ * @param filter parameters to filter the logs by
466
+ * @returns an array of logs matching the specified filter
467
+ * @example
468
+ * ```javascript
469
+ * provider.getLogs({
470
+ * address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
471
+ * topics: [
472
+ * "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
473
+ * "0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e",
474
+ * ],
475
+ * fromBlock: 14825027,
476
+ * toBlock: 14825039,
477
+ * });
478
+ *
479
+ * [
480
+ * {
481
+ * address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
482
+ * blockHash: '0x8e0dfac2f704851960f866c8708b3bef2f66c0fee0329cf25ff0261b264ca6bc',
483
+ * blockNumber: 14825029,
484
+ * data: '0x000000000000000000000000000000000000000000000000005f862ee352a38a',
485
+ * logIndex: 384,
486
+ * removed: false,
487
+ * topics: [
488
+ * '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
489
+ * '0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e',
490
+ * '0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
491
+ * ],
492
+ * transactionHash: '0xbd49031be16f8fd1775f4e0fe79b408ffd8ae9c65b2827ee47e3238e3f51f4c0',
493
+ * transactionIndex: 226
494
+ * }
495
+ * ]
496
+ * ```
497
+ */
498
+ getLogs(filter) {
499
+ return __awaiter(this, void 0, void 0, function* () {
500
+ const filterByRange = filter;
501
+ if (filterByRange.fromBlock)
502
+ filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
503
+ if (filterByRange.toBlock)
504
+ filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
505
+ const rpcLogs = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getLogs', [filter])));
506
+ const logs = rpcLogs.map((log) => (0, clean_log_1.cleanLog)(log, false));
507
+ return logs;
508
+ });
509
+ }
510
+ /**
511
+ * Returns the result of adding a transaction to the blockchain without actually adding that transaction to the blockchain.
512
+ * Does not require any ether as gas.
513
+ *
514
+ * * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
515
+ * * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
516
+ *
517
+ * @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
518
+ * @param blockTag the block to execute this transaction on
519
+ * @returns the result of executing the transaction on the specified block
520
+ * @example
521
+ * ```javascript
522
+ * await provider.call({ to: "0x6b175474e89094c44da98b954eedeac495271d0f", data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE" });
523
+ * // '0x0000000000000000000000000000000000000000000000000858898f93629000'
524
+ * ```
525
+ */
526
+ call(transaction, blockTag = 'latest') {
527
+ return __awaiter(this, void 0, void 0, function* () {
528
+ if (transaction.gasPrice &&
529
+ (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
530
+ logger_1.logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
531
+ gasPrice: transaction.gasPrice,
532
+ maxFeePerGas: transaction.maxFeePerGas,
533
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
534
+ });
925
535
  }
926
- },
927
- {
928
- key: "call",
929
- value: /**
930
- * Returns the result of adding a transaction to the blockchain without actually adding that transaction to the blockchain.
931
- * Does not require any ether as gas.
932
- *
933
- * * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
934
- * * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
935
- *
936
- * @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
937
- * @param blockTag the block to execute this transaction on
938
- * @returns the result of executing the transaction on the specified block
939
- * @example
940
- * ```javascript
941
- * await provider.call({ to: "0x6b175474e89094c44da98b954eedeac495271d0f", data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE" });
942
- * // '0x0000000000000000000000000000000000000000000000000858898f93629000'
943
- * ```
944
- */ function call(transaction) {
945
- var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
946
- var _this = this;
947
- return _async_to_generator(function() {
948
- var rpcTransaction, transactionRes;
949
- return _ts_generator(this, function(_state) {
950
- switch(_state.label){
951
- case 0:
952
- if (transaction.gasPrice && (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
953
- logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
954
- gasPrice: transaction.gasPrice,
955
- maxFeePerGas: transaction.maxFeePerGas,
956
- maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
957
- });
958
- }
959
- if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
960
- logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
961
- maxFeePerGas: transaction.maxFeePerGas,
962
- maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
963
- });
964
- }
965
- blockTag = prepBlockTag(blockTag);
966
- rpcTransaction = prepareTransaction(transaction);
967
- return [
968
- 4,
969
- _this.post(buildRPCPostBody("eth_call", [
970
- rpcTransaction,
971
- blockTag
972
- ]))
973
- ];
974
- case 1:
975
- transactionRes = _state.sent();
976
- return [
977
- 2,
978
- transactionRes
979
- ];
980
- }
981
- });
982
- })();
536
+ if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
537
+ logger_1.logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
538
+ maxFeePerGas: transaction.maxFeePerGas,
539
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
540
+ });
983
541
  }
984
- }
985
- ]);
986
- return BaseProvider;
987
- }();
542
+ blockTag = prepBlockTag(blockTag);
543
+ const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
544
+ const transactionRes = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_call', [rpcTransaction, blockTag])));
545
+ return transactionRes;
546
+ });
547
+ }
548
+ }
549
+ exports.BaseProvider = BaseProvider;