essential-eth 0.5.10 → 0.5.12

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 (190) hide show
  1. package/lib/cjs/classes/Contract.d.ts +78 -0
  2. package/lib/cjs/classes/Contract.js +140 -0
  3. package/{dist → lib/cjs}/classes/test/Contract/crv-abi.d.ts +2 -2
  4. package/lib/cjs/classes/test/Contract/crv-abi.js +488 -0
  5. package/{dist → lib/cjs}/classes/test/Contract/ens-abi.d.ts +2 -2
  6. package/lib/cjs/classes/test/Contract/ens-abi.js +453 -0
  7. package/{dist → lib/cjs}/classes/test/Contract/fei-abi.d.ts +2 -2
  8. package/lib/cjs/classes/test/Contract/fei-abi.js +526 -0
  9. package/{dist → lib/cjs}/classes/test/Contract/foo-abi.d.ts +2 -2
  10. package/lib/cjs/classes/test/Contract/foo-abi.js +42 -0
  11. package/{dist → lib/cjs}/classes/test/Contract/uniswap-abi.d.ts +2 -2
  12. package/lib/cjs/classes/test/Contract/uniswap-abi.js +121 -0
  13. package/lib/cjs/classes/utils/clean-block.d.ts +121 -0
  14. package/lib/cjs/classes/utils/clean-block.js +160 -0
  15. package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
  16. package/lib/cjs/classes/utils/clean-log.js +37 -0
  17. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +14 -0
  18. package/lib/cjs/classes/utils/clean-transaction-receipt.js +50 -0
  19. package/lib/cjs/classes/utils/clean-transaction.d.ts +14 -0
  20. package/lib/cjs/classes/utils/clean-transaction.js +51 -0
  21. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +16 -0
  22. package/lib/cjs/classes/utils/encode-decode-transaction.js +137 -0
  23. package/lib/cjs/classes/utils/fetchers.d.ts +39 -0
  24. package/lib/cjs/classes/utils/fetchers.js +81 -0
  25. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +18 -0
  26. package/lib/cjs/classes/utils/hex-to-decimal.js +24 -0
  27. package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
  28. package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
  29. package/{dist → lib/cjs}/index.d.ts +25 -25
  30. package/lib/cjs/index.js +54 -0
  31. package/{dist → lib/cjs}/logger/logger.d.ts +11 -11
  32. package/lib/cjs/logger/logger.js +36 -0
  33. package/lib/cjs/logger/package-version.d.ts +1 -0
  34. package/lib/cjs/logger/package-version.js +5 -0
  35. package/lib/cjs/providers/BaseProvider.d.ts +353 -0
  36. package/lib/cjs/providers/BaseProvider.js +512 -0
  37. package/lib/cjs/providers/FallthroughProvider.d.ts +24 -0
  38. package/lib/cjs/providers/FallthroughProvider.js +65 -0
  39. package/lib/cjs/providers/JsonRpcProvider.d.ts +33 -0
  40. package/lib/cjs/providers/JsonRpcProvider.js +46 -0
  41. package/{dist → lib/cjs}/providers/test/rpc-urls.d.ts +11 -11
  42. package/lib/cjs/providers/test/rpc-urls.js +14 -0
  43. package/{dist → lib/cjs}/providers/utils/chains-info.d.ts +467 -467
  44. package/lib/cjs/providers/utils/chains-info.js +1402 -0
  45. package/lib/cjs/shared/tiny-big/helpers.d.ts +17 -0
  46. package/lib/cjs/shared/tiny-big/helpers.js +97 -0
  47. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +58 -0
  48. package/lib/cjs/shared/tiny-big/tiny-big.js +101 -0
  49. package/{dist → lib/cjs}/shared/validate-type.d.ts +3 -3
  50. package/lib/cjs/shared/validate-type.js +9 -0
  51. package/{dist → lib/cjs}/types/Block.types.d.ts +41 -40
  52. package/lib/cjs/types/Block.types.js +2 -0
  53. package/{dist → lib/cjs}/types/Contract.types.d.ts +24 -24
  54. package/lib/cjs/types/Contract.types.js +2 -0
  55. package/lib/cjs/types/Filter.types.d.ts +16 -0
  56. package/lib/cjs/types/Filter.types.js +2 -0
  57. package/lib/cjs/types/Network.types.d.ts +8 -0
  58. package/lib/cjs/types/Network.types.js +2 -0
  59. package/lib/cjs/types/Transaction.types.d.ts +123 -0
  60. package/lib/cjs/types/Transaction.types.js +2 -0
  61. package/lib/cjs/utils/bytes.d.ts +289 -0
  62. package/lib/cjs/utils/bytes.js +711 -0
  63. package/lib/cjs/utils/compute-address.d.ts +17 -0
  64. package/lib/cjs/utils/compute-address.js +33 -0
  65. package/lib/cjs/utils/compute-public-key.d.ts +18 -0
  66. package/lib/cjs/utils/compute-public-key.js +26 -0
  67. package/lib/cjs/utils/ether-to-gwei.d.ts +27 -0
  68. package/lib/cjs/utils/ether-to-gwei.js +35 -0
  69. package/lib/cjs/utils/ether-to-wei.d.ts +27 -0
  70. package/lib/cjs/utils/ether-to-wei.js +35 -0
  71. package/lib/cjs/utils/gwei-to-ether.d.ts +27 -0
  72. package/lib/cjs/utils/gwei-to-ether.js +35 -0
  73. package/lib/cjs/utils/hash-message.d.ts +14 -0
  74. package/lib/cjs/utils/hash-message.js +28 -0
  75. package/lib/cjs/utils/is-address.d.ts +24 -0
  76. package/lib/cjs/utils/is-address.js +39 -0
  77. package/lib/cjs/utils/keccak256.d.ts +16 -0
  78. package/lib/cjs/utils/keccak256.js +31 -0
  79. package/lib/cjs/utils/solidity-keccak256.d.ts +39 -0
  80. package/lib/cjs/utils/solidity-keccak256.js +138 -0
  81. package/lib/cjs/utils/split-signature.d.ts +24 -0
  82. package/lib/cjs/utils/split-signature.js +163 -0
  83. package/lib/cjs/utils/to-checksum-address.d.ts +17 -0
  84. package/lib/cjs/utils/to-checksum-address.js +46 -0
  85. package/lib/cjs/utils/to-utf8-bytes.d.ts +15 -0
  86. package/lib/cjs/utils/to-utf8-bytes.js +21 -0
  87. package/lib/cjs/utils/wei-to-ether.d.ts +27 -0
  88. package/lib/cjs/utils/wei-to-ether.js +45 -0
  89. package/{dist → lib/esm}/classes/Contract.d.ts +11 -11
  90. package/lib/esm/classes/Contract.js +65 -0
  91. package/lib/esm/classes/test/Contract/crv-abi.d.ts +2 -0
  92. package/lib/esm/classes/test/Contract/crv-abi.js +470 -0
  93. package/lib/esm/classes/test/Contract/ens-abi.d.ts +2 -0
  94. package/lib/esm/classes/test/Contract/ens-abi.js +435 -0
  95. package/lib/esm/classes/test/Contract/fei-abi.d.ts +2 -0
  96. package/lib/esm/classes/test/Contract/fei-abi.js +521 -0
  97. package/lib/esm/classes/test/Contract/foo-abi.d.ts +2 -0
  98. package/lib/esm/classes/test/Contract/foo-abi.js +33 -0
  99. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
  100. package/lib/esm/classes/test/Contract/uniswap-abi.js +116 -0
  101. package/{dist → lib/esm}/classes/utils/clean-block.d.ts +3 -3
  102. package/lib/esm/classes/utils/clean-block.js +35 -0
  103. package/{dist → lib/esm}/classes/utils/clean-log.d.ts +2 -2
  104. package/lib/esm/classes/utils/clean-log.js +26 -0
  105. package/{dist → lib/esm}/classes/utils/clean-transaction-receipt.d.ts +2 -2
  106. package/lib/esm/classes/utils/clean-transaction-receipt.js +34 -0
  107. package/{dist → lib/esm}/classes/utils/clean-transaction.d.ts +2 -2
  108. package/lib/esm/classes/utils/clean-transaction.js +33 -0
  109. package/{dist → lib/esm}/classes/utils/encode-decode-transaction.d.ts +4 -4
  110. package/lib/esm/classes/utils/encode-decode-transaction.js +98 -0
  111. package/{dist → lib/esm}/classes/utils/fetchers.d.ts +9 -9
  112. package/lib/esm/classes/utils/fetchers.js +43 -0
  113. package/{dist → lib/esm}/classes/utils/hex-to-decimal.d.ts +1 -1
  114. package/lib/esm/classes/utils/hex-to-decimal.js +3 -0
  115. package/{dist → lib/esm}/classes/utils/prepare-transaction.d.ts +2 -2
  116. package/lib/esm/classes/utils/prepare-transaction.js +34 -0
  117. package/lib/esm/index.d.ts +25 -0
  118. package/lib/esm/index.js +20 -0
  119. package/lib/esm/logger/logger.d.ts +11 -0
  120. package/lib/esm/logger/logger.js +33 -0
  121. package/lib/esm/logger/package-version.d.ts +1 -0
  122. package/lib/esm/logger/package-version.js +1 -0
  123. package/{dist → lib/esm}/providers/BaseProvider.d.ts +24 -24
  124. package/lib/esm/providers/BaseProvider.js +157 -0
  125. package/{dist → lib/esm}/providers/FallthroughProvider.d.ts +11 -11
  126. package/lib/esm/providers/FallthroughProvider.js +41 -0
  127. package/{dist → lib/esm}/providers/JsonRpcProvider.d.ts +7 -7
  128. package/lib/esm/providers/JsonRpcProvider.js +15 -0
  129. package/lib/esm/providers/test/rpc-urls.d.ts +11 -0
  130. package/lib/esm/providers/test/rpc-urls.js +11 -0
  131. package/lib/esm/providers/utils/chains-info.d.ts +467 -0
  132. package/lib/esm/providers/utils/chains-info.js +1398 -0
  133. package/{dist → lib/esm}/shared/tiny-big/helpers.d.ts +1 -1
  134. package/lib/esm/shared/tiny-big/helpers.js +58 -0
  135. package/{dist → lib/esm}/shared/tiny-big/tiny-big.d.ts +10 -10
  136. package/lib/esm/shared/tiny-big/tiny-big.js +45 -0
  137. package/lib/esm/shared/validate-type.d.ts +3 -0
  138. package/lib/esm/shared/validate-type.js +5 -0
  139. package/lib/esm/types/Block.types.d.ts +40 -0
  140. package/lib/esm/types/Block.types.js +1 -0
  141. package/lib/esm/types/Contract.types.d.ts +24 -0
  142. package/lib/esm/types/Contract.types.js +1 -0
  143. package/{dist → lib/esm}/types/Filter.types.d.ts +12 -12
  144. package/lib/esm/types/Filter.types.js +1 -0
  145. package/{dist → lib/esm}/types/Network.types.d.ts +5 -5
  146. package/lib/esm/types/Network.types.js +1 -0
  147. package/{dist → lib/esm}/types/Transaction.types.d.ts +113 -113
  148. package/lib/esm/types/Transaction.types.js +1 -0
  149. package/{dist → lib/esm}/utils/bytes.d.ts +40 -40
  150. package/lib/esm/utils/bytes.js +245 -0
  151. package/{dist → lib/esm}/utils/compute-address.d.ts +1 -1
  152. package/lib/esm/utils/compute-address.js +11 -0
  153. package/{dist → lib/esm}/utils/compute-public-key.d.ts +2 -2
  154. package/lib/esm/utils/compute-public-key.js +6 -0
  155. package/{dist → lib/esm}/utils/ether-to-gwei.d.ts +3 -3
  156. package/lib/esm/utils/ether-to-gwei.js +7 -0
  157. package/{dist → lib/esm}/utils/ether-to-wei.d.ts +3 -3
  158. package/lib/esm/utils/ether-to-wei.js +7 -0
  159. package/{dist → lib/esm}/utils/gwei-to-ether.d.ts +3 -3
  160. package/lib/esm/utils/gwei-to-ether.js +7 -0
  161. package/{dist → lib/esm}/utils/hash-message.d.ts +2 -2
  162. package/lib/esm/utils/hash-message.js +12 -0
  163. package/{dist → lib/esm}/utils/is-address.d.ts +1 -1
  164. package/lib/esm/utils/is-address.js +12 -0
  165. package/{dist → lib/esm}/utils/keccak256.d.ts +2 -2
  166. package/lib/esm/utils/keccak256.js +13 -0
  167. package/{dist → lib/esm}/utils/solidity-keccak256.d.ts +2 -2
  168. package/lib/esm/utils/solidity-keccak256.js +85 -0
  169. package/{dist → lib/esm}/utils/split-signature.d.ts +2 -2
  170. package/lib/esm/utils/split-signature.js +126 -0
  171. package/{dist → lib/esm}/utils/to-checksum-address.d.ts +1 -1
  172. package/lib/esm/utils/to-checksum-address.js +25 -0
  173. package/{dist → lib/esm}/utils/to-utf8-bytes.d.ts +1 -1
  174. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  175. package/{dist → lib/esm}/utils/wei-to-ether.d.ts +3 -3
  176. package/lib/esm/utils/wei-to-ether.js +16 -0
  177. package/package.json +14 -37
  178. package/dist/index.cjs +0 -2
  179. package/dist/index.cjs.map +0 -1
  180. package/dist/index.js +0 -2
  181. package/dist/index.js.map +0 -1
  182. package/dist/index.modern.js +0 -2
  183. package/dist/index.modern.js.map +0 -1
  184. package/dist/index.modern.mjs +0 -2
  185. package/dist/index.modern.mjs.map +0 -1
  186. package/dist/index.module.js +0 -2
  187. package/dist/index.module.js.map +0 -1
  188. package/dist/index.umd.js +0 -2
  189. package/dist/index.umd.js.map +0 -1
  190. package/dist/logger/package-version.d.ts +0 -1
@@ -0,0 +1,157 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { cleanBlock } from '../classes/utils/clean-block';
11
+ import { cleanLog } from '../classes/utils/clean-log';
12
+ import { cleanTransaction } from '../classes/utils/clean-transaction';
13
+ import { cleanTransactionReceipt } from '../classes/utils/clean-transaction-receipt';
14
+ import { buildRPCPostBody, post } from '../classes/utils/fetchers';
15
+ import { hexToDecimal } from '../classes/utils/hex-to-decimal';
16
+ import { prepareTransaction } from '../classes/utils/prepare-transaction';
17
+ import { logger } from '../logger/logger';
18
+ import { tinyBig } from '../shared/tiny-big/tiny-big';
19
+ import chainsInfo from './utils/chains-info';
20
+ function prepBlockTag(blockTag) {
21
+ return typeof blockTag === 'number'
22
+ ? tinyBig(blockTag).toHexString()
23
+ : blockTag;
24
+ }
25
+ export class BaseProvider {
26
+ constructor(rpcUrls) {
27
+ this._rpcUrls = [];
28
+ this._post = (body) => post(this.selectRpcUrl(), body);
29
+ this._rpcUrls = rpcUrls;
30
+ }
31
+ getNetwork() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const hexChainId = (yield this.post(buildRPCPostBody('eth_chainId', [])));
34
+ const chainId = hexToDecimal(hexChainId);
35
+ const info = chainsInfo[chainId];
36
+ return {
37
+ chainId: Number(chainId),
38
+ name: info[0] || 'unknown',
39
+ ensAddress: info[1] || null,
40
+ };
41
+ });
42
+ }
43
+ getBlockNumber() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const currentBlockNumber = (yield this.post(buildRPCPostBody('eth_blockNumber', [])));
46
+ return Number(hexToDecimal(currentBlockNumber));
47
+ });
48
+ }
49
+ getTransaction(transactionHash) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const [rpcTransaction, blockNumber] = yield Promise.all([
52
+ this.post(buildRPCPostBody('eth_getTransactionByHash', [transactionHash])),
53
+ this.getBlock('latest'),
54
+ ]);
55
+ const cleanedTransaction = cleanTransaction(rpcTransaction);
56
+ cleanedTransaction.confirmations =
57
+ blockNumber.number - cleanedTransaction.blockNumber + 1;
58
+ return cleanedTransaction;
59
+ });
60
+ }
61
+ getTransactionReceipt(transactionHash) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const [rpcTransaction, blockNumber] = yield Promise.all([
64
+ this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])),
65
+ this.getBlock('latest'),
66
+ ]);
67
+ const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
68
+ cleanedTransactionReceipt.confirmations =
69
+ blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
70
+ return cleanedTransactionReceipt;
71
+ });
72
+ }
73
+ getTransactionCount(address, blockTag = 'latest') {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ blockTag = prepBlockTag(blockTag);
76
+ const transactionCount = (yield this.post(buildRPCPostBody('eth_getTransactionCount', [address, blockTag])));
77
+ return Number(hexToDecimal(transactionCount));
78
+ });
79
+ }
80
+ getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ let type = 'Number';
83
+ if (typeof timeFrame === 'string' && timeFrame.length === 66) {
84
+ type = 'Hash';
85
+ }
86
+ else {
87
+ timeFrame = prepBlockTag(timeFrame);
88
+ }
89
+ const rpcBlock = (yield this.post(buildRPCPostBody(`eth_getBlockBy${type}`, [
90
+ timeFrame,
91
+ returnTransactionObjects,
92
+ ])));
93
+ return cleanBlock(rpcBlock, returnTransactionObjects);
94
+ });
95
+ }
96
+ getGasPrice() {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
99
+ return tinyBig(hexToDecimal(hexGasPrice));
100
+ });
101
+ }
102
+ getBalance(address, blockTag = 'latest') {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ blockTag = prepBlockTag(blockTag);
105
+ const hexBalance = (yield this.post(buildRPCPostBody('eth_getBalance', [address, blockTag])));
106
+ return tinyBig(hexToDecimal(hexBalance));
107
+ });
108
+ }
109
+ getCode(address, blockTag = 'latest') {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ blockTag = prepBlockTag(blockTag);
112
+ const contractCode = (yield this.post(buildRPCPostBody('eth_getCode', [address, blockTag])));
113
+ return contractCode;
114
+ });
115
+ }
116
+ estimateGas(transaction) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const rpcTransaction = prepareTransaction(transaction);
119
+ const gasUsed = (yield this.post(buildRPCPostBody('eth_estimateGas', [rpcTransaction])));
120
+ return tinyBig(hexToDecimal(gasUsed));
121
+ });
122
+ }
123
+ getLogs(filter) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const filterByRange = filter;
126
+ if (filterByRange.fromBlock)
127
+ filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
128
+ if (filterByRange.toBlock)
129
+ filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
130
+ const rpcLogs = (yield this.post(buildRPCPostBody('eth_getLogs', [filter])));
131
+ const logs = rpcLogs.map((log) => cleanLog(log, false));
132
+ return logs;
133
+ });
134
+ }
135
+ call(transaction, blockTag = 'latest') {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ if (transaction.gasPrice &&
138
+ (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
139
+ logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
140
+ gasPrice: transaction.gasPrice,
141
+ maxFeePerGas: transaction.maxFeePerGas,
142
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
143
+ });
144
+ }
145
+ if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
146
+ logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
147
+ maxFeePerGas: transaction.maxFeePerGas,
148
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
149
+ });
150
+ }
151
+ blockTag = prepBlockTag(blockTag);
152
+ const rpcTransaction = prepareTransaction(transaction);
153
+ const transactionRes = (yield this.post(buildRPCPostBody('eth_call', [rpcTransaction, blockTag])));
154
+ return transactionRes;
155
+ });
156
+ }
157
+ }
@@ -1,11 +1,11 @@
1
- import { BaseProvider } from './BaseProvider';
2
- export interface ConstructorOptions {
3
- timeoutDuration?: number;
4
- }
5
- export declare class FallthroughProvider extends BaseProvider {
6
- private rpcUrlCounter;
7
- private readonly timeoutDuration;
8
- selectRpcUrl(): string;
9
- constructor(rpcUrls: string[], options?: ConstructorOptions);
10
- post: (body: Record<string, unknown>) => Promise<any>;
11
- }
1
+ import { BaseProvider } from './BaseProvider';
2
+ export interface ConstructorOptions {
3
+ timeoutDuration?: number;
4
+ }
5
+ export declare class FallthroughProvider extends BaseProvider {
6
+ private rpcUrlCounter;
7
+ private readonly timeoutDuration;
8
+ selectRpcUrl(): string;
9
+ constructor(rpcUrls: string[], options?: ConstructorOptions);
10
+ post: (body: Record<string, unknown>) => Promise<any>;
11
+ }
@@ -0,0 +1,41 @@
1
+ import { logger } from '../logger/logger';
2
+ import { BaseProvider } from './BaseProvider';
3
+ const promiseTimeout = (prom, time) => Promise.race([
4
+ prom,
5
+ new Promise((_r, reject) => setTimeout(() => reject('Promise timed out'), time)),
6
+ ]);
7
+ const DEFAULT_TIMEOUT_DURATION = 8000;
8
+ export class FallthroughProvider extends BaseProvider {
9
+ constructor(rpcUrls, options = {}) {
10
+ if (!Array.isArray(rpcUrls)) {
11
+ logger.throwError('Array required', { rpcUrls });
12
+ }
13
+ if (rpcUrls.length <= 1) {
14
+ logger.throwError('More than one rpcUrl is required', { rpcUrls });
15
+ }
16
+ super(rpcUrls);
17
+ this.rpcUrlCounter = 0;
18
+ this.post = (body) => {
19
+ const genesisCount = this.rpcUrlCounter;
20
+ const recursivePostRetry = () => {
21
+ const genesisRpcUrl = this.selectRpcUrl();
22
+ const res = promiseTimeout(this._post(body), this.timeoutDuration).catch((e) => {
23
+ if (genesisRpcUrl === this.selectRpcUrl()) {
24
+ this.rpcUrlCounter =
25
+ (this.rpcUrlCounter + 1) % this._rpcUrls.length;
26
+ }
27
+ if (this.rpcUrlCounter === genesisCount) {
28
+ throw e;
29
+ }
30
+ return recursivePostRetry();
31
+ });
32
+ return res;
33
+ };
34
+ return recursivePostRetry();
35
+ };
36
+ this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
37
+ }
38
+ selectRpcUrl() {
39
+ return this._rpcUrls[this.rpcUrlCounter];
40
+ }
41
+ }
@@ -1,7 +1,7 @@
1
- import { BaseProvider } from './BaseProvider';
2
- export declare class JsonRpcProvider extends BaseProvider {
3
- selectRpcUrl(): string;
4
- post(body: Record<string, unknown>): Promise<any>;
5
- constructor(rpcUrl?: string);
6
- }
7
- export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
1
+ import { BaseProvider } from './BaseProvider';
2
+ export declare class JsonRpcProvider extends BaseProvider {
3
+ selectRpcUrl(): string;
4
+ post(body: Record<string, unknown>): Promise<any>;
5
+ constructor(rpcUrl?: string);
6
+ }
7
+ export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
@@ -0,0 +1,15 @@
1
+ import { BaseProvider } from './BaseProvider';
2
+ export class JsonRpcProvider extends BaseProvider {
3
+ selectRpcUrl() {
4
+ return this._rpcUrls[0];
5
+ }
6
+ post(body) {
7
+ return this._post(body);
8
+ }
9
+ constructor(rpcUrl = 'https://free-eth-node.com/api/eth') {
10
+ super([rpcUrl]);
11
+ }
12
+ }
13
+ export function jsonRpcProvider(rpcUrl) {
14
+ return new JsonRpcProvider(rpcUrl);
15
+ }
@@ -0,0 +1,11 @@
1
+ export declare const fakeUrls: {
2
+ readonly notRPCButRealHttp: "https://httpstat.us/200";
3
+ };
4
+ export declare const rpcUrls: {
5
+ mainnet: string;
6
+ matic: string;
7
+ gno: string;
8
+ bnb: string;
9
+ arb1: string;
10
+ gor: string;
11
+ };
@@ -0,0 +1,11 @@
1
+ export const fakeUrls = {
2
+ notRPCButRealHttp: 'https://httpstat.us/200',
3
+ };
4
+ export const rpcUrls = {
5
+ mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
6
+ matic: `${process.env.RPC_ORIGIN}/api/MATIC`,
7
+ gno: `${process.env.RPC_ORIGIN}/api/gno`,
8
+ bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
9
+ arb1: `${process.env.RPC_ORIGIN}/api/arb1`,
10
+ gor: `${process.env.RPC_ORIGIN}/api/gor`,
11
+ };