essential-eth 0.4.10 → 0.5.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 (52) hide show
  1. package/lib/cjs/classes/utils/clean-block.d.ts +3 -3
  2. package/lib/cjs/classes/utils/clean-block.js +3 -2
  3. package/lib/cjs/classes/utils/clean-transaction.d.ts +3 -3
  4. package/lib/cjs/classes/utils/clean-transaction.js +10 -6
  5. package/lib/cjs/classes/utils/fetchers.d.ts +3 -3
  6. package/lib/cjs/index.d.ts +5 -3
  7. package/lib/cjs/index.js +16 -0
  8. package/lib/cjs/logger/logger.d.ts +11 -0
  9. package/lib/cjs/logger/logger.js +36 -0
  10. package/lib/cjs/logger/package-version.d.ts +1 -0
  11. package/lib/cjs/logger/package-version.js +5 -0
  12. package/lib/cjs/providers/JsonRpcProvider.d.ts +190 -3
  13. package/lib/cjs/providers/JsonRpcProvider.js +214 -19
  14. package/lib/cjs/providers/test/rpc-urls.d.ts +2 -0
  15. package/lib/cjs/providers/test/rpc-urls.js +2 -0
  16. package/lib/cjs/providers/utils/chains-info.d.ts +11 -0
  17. package/lib/cjs/providers/utils/chains-info.js +34 -1
  18. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +7 -0
  19. package/lib/cjs/shared/tiny-big/tiny-big.js +24 -0
  20. package/lib/cjs/types/Block.types.d.ts +9 -19
  21. package/lib/cjs/types/Transaction.types.d.ts +23 -14
  22. package/lib/cjs/utils/bytes.d.ts +90 -0
  23. package/lib/cjs/utils/bytes.js +484 -0
  24. package/lib/cjs/utils/solidity-keccak256.d.ts +30 -0
  25. package/lib/cjs/utils/solidity-keccak256.js +125 -0
  26. package/lib/esm/classes/utils/clean-block.d.ts +2 -2
  27. package/lib/esm/classes/utils/clean-block.js +2 -1
  28. package/lib/esm/classes/utils/clean-transaction.d.ts +2 -2
  29. package/lib/esm/classes/utils/clean-transaction.js +10 -6
  30. package/lib/esm/classes/utils/fetchers.d.ts +3 -3
  31. package/lib/esm/index.d.ts +5 -3
  32. package/lib/esm/index.js +2 -0
  33. package/lib/esm/logger/logger.d.ts +11 -0
  34. package/lib/esm/logger/logger.js +33 -0
  35. package/lib/esm/logger/package-version.d.ts +1 -0
  36. package/lib/esm/logger/package-version.js +1 -0
  37. package/lib/esm/providers/JsonRpcProvider.d.ts +6 -2
  38. package/lib/esm/providers/JsonRpcProvider.js +30 -19
  39. package/lib/esm/providers/test/rpc-urls.d.ts +2 -0
  40. package/lib/esm/providers/test/rpc-urls.js +2 -0
  41. package/lib/esm/providers/utils/chains-info.d.ts +11 -0
  42. package/lib/esm/providers/utils/chains-info.js +34 -1
  43. package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -0
  44. package/lib/esm/shared/tiny-big/tiny-big.js +19 -0
  45. package/lib/esm/types/Block.types.d.ts +8 -19
  46. package/lib/esm/types/Transaction.types.d.ts +22 -14
  47. package/lib/esm/utils/bytes.d.ts +39 -0
  48. package/lib/esm/utils/bytes.js +245 -0
  49. package/lib/esm/utils/solidity-keccak256.d.ts +3 -0
  50. package/lib/esm/utils/solidity-keccak256.js +91 -0
  51. package/package.json +15 -17
  52. package/readme.md +252 -62
@@ -14,19 +14,66 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.jsonRpcProvider = exports.JsonRpcProvider = void 0;
16
16
  const clean_block_1 = require("../classes/utils/clean-block");
17
+ const clean_transaction_1 = require("../classes/utils/clean-transaction");
17
18
  const fetchers_1 = require("../classes/utils/fetchers");
18
19
  const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
19
20
  const tiny_big_1 = require("../shared/tiny-big/tiny-big");
20
21
  const chains_info_1 = __importDefault(require("./utils/chains-info"));
21
22
  class JsonRpcProvider {
23
+ /**
24
+ * @param rpcUrl The URL to your Eth node. Consider POKT or Infura
25
+ */
22
26
  constructor(rpcUrl) {
27
+ /**
28
+ * @ignore
29
+ */
30
+ this.post = (body) => (0, fetchers_1.post)(this._rpcUrl, body);
23
31
  this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
24
32
  }
25
33
  /**
26
34
  * Returns the block requested
27
35
  * Same as `web3.eth.getBlock`
36
+ * @example
37
+ * ```js
38
+ * await provider.getBlock('latest');
39
+ * {
40
+ * number: 4232826,
41
+ * hash: '0x93211a1cd17e154b183565ec685254a03f844a8e34824a46ce1bdd6753dcb669',
42
+ * parentHash: '0x1b32bfcba1bb2a57f56e166a3bb06875a1978992999dfc8828397b4c1526f472',
43
+ * sha3Uncles: '0x0fb399c67bb5a071ec8a22549223215ab76b7d4009941c9c37aa3c3936010463',
44
+ * logsBloom: '0x00000000000000000000101000000000020000000000000000000000000000000000400000010000000000000000000000000000010000000008800000000800000000200000000000000000000000000000000000000000000002000000000000000000000000000040000000000040000000000000000000000000000000000000000000000001000000000004000000000010000000000000000020000000000000000200100020000000000000000080000000000080001000000000000000000001040000000000000000008000000020010100000000200000100000000000000000000000002000000080000000020400000000002000200000000000',
45
+ * transactionsRoot: '0xc43b3f13e1fe810e34d3a26ffe465b72c7063a5c70a02de2c78e91e4d10bd9fb',
46
+ * stateRoot: '0x04d7bc816537ea7ef3a16e76c9879d29f34f99d4154273c2e98e012a31bad745',
47
+ * receiptsRoot: '0x89c6f781ceac0bd49c4d9aa9115df4a5d4dd0e0220ff7668012f15bc04222c6b',
48
+ * miner: '0x31fe561eb2c628cD32Ec52573D7c4b7E4C278Bfa',
49
+ * difficulty: '1300907486001755331049',
50
+ * totalDifficulty: '5989929395521171616186006183',
51
+ * extraData: '0xce018c495249532d62613031656132',
52
+ * size: 5416,
53
+ * gasLimit: 6800000,
54
+ * gasUsed: 202955,
55
+ * timestamp: 1649884910,
56
+ * transactions: [
57
+ * '0x6b34a59c7b9aead24fa6dad782f8a3ad84ed4a23ee09bcbf0bcf880840fbbe20',
58
+ * '0x9a3851ca24d5336c6a0d48aba2c4b4769d7a672c9b01729c5eb9924efd1b19a7',
59
+ * '0xc3ed3d198b62f2f3427ebfa3bbd0fcada4e3c0c189e4464e7eeceb403c75981e'
60
+ * ],
61
+ * uncles: [
62
+ * '0x0c567c054e98153f10d651fbbc018891c1dd9d62a9ffd998e87678803e95b6ed',
63
+ * '0xb7d69389dbfb057c6fcb4bc0582d46a2ba01170703f0dadf8cd1462b83e88753',
64
+ * '0xd5f74ccd0ad4c58b3161e8c2c507c264231e5f28925061b809c02e5e4bb6db28'
65
+ * ],
66
+ * minimumGasPrice: '0x387ee40',
67
+ * bitcoinMergedMiningHeader: '0x04000020e8567ed3d2480e15a1dd1b4335e4732ae343c037e4fd03000000000000000000ed10a8340d163d3e813bdd430f902f4e5a56828dc62313b2e23797c0be6b8516eb3e576297d8091735884f42',
68
+ * bitcoinMergedMiningCoinbaseTransaction: '0x0000000000000140e910128fda7bac502dc5e0573bbaf12de8e2524f70c22f7bd160dedcb19a2521002b6a2952534b424c4f434b3ae493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967aace6a7d9',
69
+ * bitcoinMergedMiningMerkleProof: '0xdf63a3d7eb6fbcfb301311faa46e9a15b0408bb1a04e284daee86c273c1dfd65ede23f3170f806e9e0f4cef7ba6b56aa37470d9c23f96ec8e43d08b58645919c5e10bcb892897a731f8f9ce79c72dc0e390896bcd6c67bb38c0bdb72982b6cf05519968d76673572c3f3ef3a08b0ddb464863f1788f7cdbaad3fe44a8a8af576d430ac282fe28852c16df198ca96cc5f71a50695912efe1a836e8442be69e31b6d6f973da2818bce9a3a1c2d9be0671aee9a7776e398d6a03d1e178e20d84646004a3d03c0501334e629d9146aa6a01316dcbaa289df6e6c5e3090cadaddff22699cfc7ff09512fc0d65c5062f17c98561ce3c9510de210d9d654cf99f8d756ff37c9fa21e7122ee8cadb923341690845d572921425f2bd7e044558b7e07983ac4df28928028b0c13c3624dc7a965af8091b0cecc845bf7da5308c03b2c97d607f6706a599f802025894435f1d76ea4e67cc2fc4e1559f1206f559a24633de0f',
70
+ * hashForMergedMining: '0xe493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967a',
71
+ * paidFees: '0xc0744dcb7a0',
72
+ * cumulativeDifficulty: '0x1190930db285269e582'
73
+ * }
74
+ *```
28
75
  */
29
- getBlock(timeFrame /* block number as integer */, returnTransactionObjects = false) {
76
+ getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
30
77
  return __awaiter(this, void 0, void 0, function* () {
31
78
  let rpcTimeFrame;
32
79
  if (typeof timeFrame === 'number') {
@@ -37,14 +84,11 @@ class JsonRpcProvider {
37
84
  // "latest", "earliest", and "pending" require no manipulation
38
85
  rpcTimeFrame = timeFrame;
39
86
  }
40
- const req = () => __awaiter(this, void 0, void 0, function* () {
41
- return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_getBlockByNumber', [
42
- rpcTimeFrame,
43
- returnTransactionObjects,
44
- ]));
45
- });
46
- const nodeResponse = (yield req());
47
- return (0, clean_block_1.cleanBlock)(nodeResponse, returnTransactionObjects);
87
+ const rpcBlock = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBlockByNumber', [
88
+ rpcTimeFrame,
89
+ returnTransactionObjects,
90
+ ])));
91
+ return (0, clean_block_1.cleanBlock)(rpcBlock, returnTransactionObjects);
48
92
  });
49
93
  }
50
94
  /**
@@ -52,11 +96,8 @@ class JsonRpcProvider {
52
96
  */
53
97
  getNetwork() {
54
98
  return __awaiter(this, void 0, void 0, function* () {
55
- const req = () => __awaiter(this, void 0, void 0, function* () {
56
- return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_chainId', []));
57
- });
58
- const nodeResponse = (yield req());
59
- const chainId = (0, hex_to_decimal_1.hexToDecimal)(nodeResponse);
99
+ const hexChainId = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_chainId', [])));
100
+ const chainId = (0, hex_to_decimal_1.hexToDecimal)(hexChainId);
60
101
  const info = chains_info_1.default[chainId];
61
102
  return {
62
103
  chainId: Number(chainId),
@@ -71,11 +112,165 @@ class JsonRpcProvider {
71
112
  */
72
113
  getGasPrice() {
73
114
  return __awaiter(this, void 0, void 0, function* () {
74
- const req = () => __awaiter(this, void 0, void 0, function* () {
75
- return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_gasPrice', []));
76
- });
77
- const nodeResponse = (yield req()); /* '0x153cfb1ad0' */
78
- return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(nodeResponse));
115
+ const hexGasPrice = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_gasPrice', [])));
116
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexGasPrice));
117
+ });
118
+ }
119
+ /**
120
+ * Returns the balance of the account in wei as TinyBig
121
+ * Same as `ethers.provider.getBalance`
122
+ * Same as `web3.eth.getBalance`
123
+ *
124
+ * @example
125
+ * ```js
126
+ * await provider
127
+ * .getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8')
128
+ * .then((balance) => console.log(balance.toString()));
129
+ * // "28798127851528138"
130
+ * ```
131
+ */
132
+ getBalance(address, blockTag = 'latest') {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const hexBalance = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag])));
135
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
136
+ });
137
+ }
138
+ /**
139
+ * Similar to `ethers.provider.getTransaction`, some information not included
140
+ *
141
+ * @params hash A transaction hash
142
+ * @returns information about one transaction
143
+ * @example
144
+ * ```js
145
+ * await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
146
+ * {
147
+ * accessList: [],
148
+ * blockHash: '0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d',
149
+ * blockNumber: 14578286,
150
+ * chainId: 1,
151
+ * from: '0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4',
152
+ * gas: Big {
153
+ * s: 1,
154
+ * e: 5,
155
+ * c: [ 1, 1, 2, 1, 6, 3 ],
156
+ * constructor: <ref *1> [Function: Big] {
157
+ * DP: 20,
158
+ * RM: 1,
159
+ * NE: -7,
160
+ * PE: 21,
161
+ * strict: false,
162
+ * roundDown: 0,
163
+ * roundHalfUp: 1,
164
+ * roundHalfEven: 2,
165
+ * roundUp: 3,
166
+ * Big: [Circular *1],
167
+ * default: [Circular *1]
168
+ * }
169
+ * },
170
+ * gasPrice: Big {
171
+ * s: 1,
172
+ * e: 10,
173
+ * c: [
174
+ * 4, 8, 5, 9, 2,
175
+ * 4, 2, 6, 8, 5,
176
+ * 8
177
+ * ],
178
+ * constructor: <ref *1> [Function: Big] {
179
+ * DP: 20,
180
+ * RM: 1,
181
+ * NE: -7,
182
+ * PE: 21,
183
+ * strict: false,
184
+ * roundDown: 0,
185
+ * roundHalfUp: 1,
186
+ * roundHalfEven: 2,
187
+ * roundUp: 3,
188
+ * Big: [Circular *1],
189
+ * default: [Circular *1]
190
+ * }
191
+ * },
192
+ * hash: '0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789',
193
+ * input: '0x83259f170000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009e99ad11a214fd016b19dc3648678c5944859ae292b21c24ca94f857836c4596f1950c82dd0c23dd621af4763edc2f66466e63c5df9de0c1107b1cd16bf460fe93e43fd308e3444bc79c3d88a4cb961dc8367ab6ad048867afc76d193bca99cf3a068864ed4a7df1dbf1d4c52238eced3e5e05644b4040fc2b3ccb8557b0e99fff6131305a0ea2b8061b90bd418db5bbdd2e92129f52d93f90531465e309c4caec5b85285822b6196398d36f16f511811b61bbda6461e80e29210cd303118bdcee8df6fa0505ffbe8642094fd2ba4dd458496fe3b459ac880bbf71877c713e969ccf5ed7efab8a84ebc07e3939901371ca427e1192e455a8f35a6a1d7ad09e1475dd1758b36fa631dab5d70e99316b23c4c43094188d360cd9c3457355904e07c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000162074a7047f',
194
+ * maxFeePerGas: Big {
195
+ * s: 1,
196
+ * e: 10,
197
+ * c: [
198
+ * 6, 7, 6, 8, 1,
199
+ * 2, 6, 1, 6, 1,
200
+ * 8
201
+ * ],
202
+ * constructor: <ref *1> [Function: Big] {
203
+ * DP: 20,
204
+ * RM: 1,
205
+ * NE: -7,
206
+ * PE: 21,
207
+ * strict: false,
208
+ * roundDown: 0,
209
+ * roundHalfUp: 1,
210
+ * roundHalfEven: 2,
211
+ * roundUp: 3,
212
+ * Big: [Circular *1],
213
+ * default: [Circular *1]
214
+ * }
215
+ * },
216
+ * maxPriorityFeePerGas: Big {
217
+ * s: 1,
218
+ * e: 9,
219
+ * c: [ 1, 5 ],
220
+ * constructor: <ref *1> [Function: Big] {
221
+ * DP: 20,
222
+ * RM: 1,
223
+ * NE: -7,
224
+ * PE: 21,
225
+ * strict: false,
226
+ * roundDown: 0,
227
+ * roundHalfUp: 1,
228
+ * roundHalfEven: 2,
229
+ * roundUp: 3,
230
+ * Big: [Circular *1],
231
+ * default: [Circular *1]
232
+ * }
233
+ * },
234
+ * nonce: 129,
235
+ * r: '0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc',
236
+ * s: '0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c',
237
+ * to: '0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B',
238
+ * transactionIndex: 29,
239
+ * type: 2,
240
+ * v: 0,
241
+ * value: Big {
242
+ * s: 1,
243
+ * e: 0,
244
+ * c: [ 0 ],
245
+ * constructor: <ref *1> [Function: Big] {
246
+ * DP: 20,
247
+ * RM: 1,
248
+ * NE: -7,
249
+ * PE: 21,
250
+ * strict: false,
251
+ * roundDown: 0,
252
+ * roundHalfUp: 1,
253
+ * roundHalfEven: 2,
254
+ * roundUp: 3,
255
+ * Big: [Circular *1],
256
+ * default: [Circular *1]
257
+ * }
258
+ * },
259
+ * confirmations: 1210
260
+ * }
261
+ * ```
262
+ */
263
+ getTransaction(hash) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ const [rpcTransaction, blockNumber] = yield Promise.all([
266
+ this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionByHash', [hash])),
267
+ this.getBlock('latest'),
268
+ ]);
269
+ const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(rpcTransaction);
270
+ // https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
271
+ cleanedTransaction.confirmations =
272
+ blockNumber.number - cleanedTransaction.blockNumber + 1;
273
+ return cleanedTransaction;
79
274
  });
80
275
  }
81
276
  }
@@ -5,4 +5,6 @@ export declare const rpcUrls: {
5
5
  mainnet: string;
6
6
  gno: string;
7
7
  bnb: string;
8
+ arb1: string;
9
+ gor: string;
8
10
  };
@@ -8,4 +8,6 @@ exports.rpcUrls = {
8
8
  mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
9
9
  gno: `${process.env.RPC_ORIGIN}/api/gno`,
10
10
  bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
11
+ arb1: `${process.env.RPC_ORIGIN}/api/arb1`,
12
+ gor: `${process.env.RPC_ORIGIN}/api/gor`,
11
13
  };
@@ -66,7 +66,9 @@ declare const _default: {
66
66
  "76": string[];
67
67
  "77": string[];
68
68
  "78": string[];
69
+ "79": string[];
69
70
  "80": string[];
71
+ "81": string[];
70
72
  "82": string[];
71
73
  "83": string[];
72
74
  "85": string[];
@@ -147,6 +149,7 @@ declare const _default: {
147
149
  "600": string[];
148
150
  "666": string[];
149
151
  "686": string[];
152
+ "700": string[];
150
153
  "707": string[];
151
154
  "708": string[];
152
155
  "721": string[];
@@ -208,8 +211,11 @@ declare const _default: {
208
211
  "2025": string[];
209
212
  "2100": string[];
210
213
  "2101": string[];
214
+ "2152": string[];
215
+ "2153": string[];
211
216
  "2213": string[];
212
217
  "2221": string[];
218
+ "2223": string[];
213
219
  "2559": string[];
214
220
  "3000": string[];
215
221
  "3001": string[];
@@ -228,6 +234,8 @@ declare const _default: {
228
234
  "4918": string[];
229
235
  "5197": string[];
230
236
  "5315": string[];
237
+ "5551": string[];
238
+ "5553": string[];
231
239
  "5700": string[];
232
240
  "5777": string[];
233
241
  "5851": string[];
@@ -262,6 +270,7 @@ declare const _default: {
262
270
  "16000": string[];
263
271
  "16001": string[];
264
272
  "19845": string[];
273
+ "21337": string[];
265
274
  "21816": string[];
266
275
  "24484": string[];
267
276
  "24734": string[];
@@ -291,6 +300,7 @@ declare const _default: {
291
300
  "62320": string[];
292
301
  "63000": string[];
293
302
  "63001": string[];
303
+ "69420": string[];
294
304
  "70000": string[];
295
305
  "70001": string[];
296
306
  "70002": string[];
@@ -344,6 +354,7 @@ declare const _default: {
344
354
  "11155111": string[];
345
355
  "13371337": string[];
346
356
  "18289463": string[];
357
+ "20180430": string[];
347
358
  "20181205": string[];
348
359
  "28945486": string[];
349
360
  "35855456": string[];
@@ -208,9 +208,15 @@ exports.default = {
208
208
  "78": [
209
209
  "primuschain"
210
210
  ],
211
+ "79": [
212
+ "zenith"
213
+ ],
211
214
  "80": [
212
215
  "GeneChain"
213
216
  ],
217
+ "81": [
218
+ "VIL"
219
+ ],
214
220
  "82": [
215
221
  "Meter"
216
222
  ],
@@ -451,6 +457,9 @@ exports.default = {
451
457
  "686": [
452
458
  "kar"
453
459
  ],
460
+ "700": [
461
+ "SNS"
462
+ ],
454
463
  "707": [
455
464
  "bcs"
456
465
  ],
@@ -587,7 +596,7 @@ exports.default = {
587
596
  "mrock"
588
597
  ],
589
598
  "1337": [
590
- "cennz-a"
599
+ "cennz-old"
591
600
  ],
592
601
  "1618": [
593
602
  "cate"
@@ -634,12 +643,21 @@ exports.default = {
634
643
  "2101": [
635
644
  "esp"
636
645
  ],
646
+ "2152": [
647
+ "fra"
648
+ ],
649
+ "2153": [
650
+ "findora-testnet"
651
+ ],
637
652
  "2213": [
638
653
  "evanesco"
639
654
  ],
640
655
  "2221": [
641
656
  "kava"
642
657
  ],
658
+ "2223": [
659
+ "VChain"
660
+ ],
643
661
  "2559": [
644
662
  "ktoc"
645
663
  ],
@@ -694,6 +712,12 @@ exports.default = {
694
712
  "5315": [
695
713
  "UZMI"
696
714
  ],
715
+ "5551": [
716
+ "Nahmii"
717
+ ],
718
+ "5553": [
719
+ "Nahmii testnet"
720
+ ],
697
721
  "5700": [
698
722
  "tsys"
699
723
  ],
@@ -796,6 +820,9 @@ exports.default = {
796
820
  "19845": [
797
821
  "btcix"
798
822
  ],
823
+ "21337": [
824
+ "cennz-a"
825
+ ],
799
826
  "21816": [
800
827
  "oml"
801
828
  ],
@@ -883,6 +910,9 @@ exports.default = {
883
910
  "63001": [
884
911
  "ecs-testnet"
885
912
  ],
913
+ "69420": [
914
+ "cndr"
915
+ ],
886
916
  "70000": [
887
917
  "TKM0"
888
918
  ],
@@ -1042,6 +1072,9 @@ exports.default = {
1042
1072
  "18289463": [
1043
1073
  "ilt"
1044
1074
  ],
1075
+ "20180430": [
1076
+ "spectrum"
1077
+ ],
1045
1078
  "20181205": [
1046
1079
  "qki"
1047
1080
  ],
@@ -12,6 +12,13 @@ export declare class TinyBig extends Big {
12
12
  toHexString(): string;
13
13
  toNumber(): number;
14
14
  toString(): string;
15
+ /**
16
+ * @param {String} str
17
+ * @param {String} padChar
18
+ * @param {Number} length
19
+ */
20
+ private padAndChop;
21
+ toTwos(bitCount: number): Big;
15
22
  }
16
23
  /**
17
24
  * Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
@@ -13,6 +13,14 @@ const helpers_1 = require("./helpers");
13
13
  class TinyBig extends big_js_1.default {
14
14
  constructor(value) {
15
15
  super(value);
16
+ /**
17
+ * @param {String} str
18
+ * @param {String} padChar
19
+ * @param {Number} length
20
+ */
21
+ this.padAndChop = (str, padChar, length) => {
22
+ return (Array(length).fill(padChar).join('') + str).slice(length * -1);
23
+ };
16
24
  }
17
25
  /**
18
26
  * Used anytime you're passing in "value" to ethers or web3
@@ -30,6 +38,22 @@ class TinyBig extends big_js_1.default {
30
38
  }
31
39
  return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
32
40
  }
41
+ toTwos(bitCount) {
42
+ let binaryStr;
43
+ if (this.gte(0)) {
44
+ const twosComp = this.toNumber().toString(2);
45
+ binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
46
+ }
47
+ else {
48
+ binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
49
+ if (Number(binaryStr) < 0) {
50
+ throw new Error('Cannot calculate twos complement');
51
+ }
52
+ }
53
+ const binary = `0b${binaryStr}`;
54
+ const decimal = Number(binary);
55
+ return tinyBig(decimal);
56
+ }
33
57
  }
34
58
  exports.TinyBig = TinyBig;
35
59
  /**
@@ -1,27 +1,15 @@
1
- import { RPCTransaction, Transaction } from './Transaction.types';
2
- export interface Block {
3
- baseFeePerGas: string;
4
- difficulty: number;
5
- extraData: string;
1
+ import { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
2
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
3
+ export declare type BlockResponse = Modify<RPCBlock, {
6
4
  gasLimit: number;
7
5
  gasUsed: number;
8
- hash: string;
9
- logsBloom: string;
10
- miner: string;
11
- mixHash: string;
12
- nonce: string;
13
6
  number: number;
14
- parentHash: string;
15
- receiptsRoot: string;
16
- sha3Uncles: string;
17
7
  size: number;
18
- stateRoot: string;
19
8
  timestamp: number;
20
- totalDifficulty: number;
21
- transactions: string[] | Transaction[];
22
- transactionsRoot: string;
23
- uncles: unknown[];
24
- }
9
+ baseFeePerGas: number;
10
+ transactions: Array<string | BlockTransactionResponse>;
11
+ }>;
12
+ /** Exact response from backend */
25
13
  export interface RPCBlock {
26
14
  baseFeePerGas: string;
27
15
  difficulty: string;
@@ -45,3 +33,5 @@ export interface RPCBlock {
45
33
  transactionsRoot: string;
46
34
  uncles: unknown[];
47
35
  }
36
+ export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
37
+ export {};
@@ -1,23 +1,31 @@
1
- export interface Transaction {
2
- blockHash: string;
1
+ import { TinyBig } from '../shared/tiny-big/tiny-big';
2
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
3
+ export interface RPCTransaction extends RPCBlockTransaction {
4
+ maxFeePerGas: string;
5
+ maxPriorityFeePerGas: string;
6
+ }
7
+ export declare type TransactionResponse = Modify<RPCTransaction, {
3
8
  blockNumber: number;
4
- from: string;
5
- gas: number;
6
- gasPrice: string;
7
- hash: string;
8
- input: string;
9
+ chainId: number;
9
10
  nonce: number;
10
- r: string;
11
- s: string;
12
- to: string;
13
11
  transactionIndex: number;
14
12
  type: number;
15
- v: string;
16
- value: string;
17
- }
18
- export interface RPCTransaction {
13
+ v: number;
14
+ value: TinyBig;
15
+ gasPrice: TinyBig;
16
+ gas: TinyBig;
17
+ gasLimit: TinyBig;
18
+ } & {
19
+ maxFeePerGas: TinyBig;
20
+ maxPriorityFeePerGas: TinyBig;
21
+ confirmations: number;
22
+ }>;
23
+ export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
24
+ /** What JSONRPC responds with in getBlock transaction array */
25
+ export interface RPCBlockTransaction {
19
26
  blockHash: string;
20
27
  blockNumber: string;
28
+ chainId: string;
21
29
  from: string;
22
30
  gas: string;
23
31
  gasPrice: string;
@@ -32,3 +40,4 @@ export interface RPCTransaction {
32
40
  v: string;
33
41
  value: string;
34
42
  }
43
+ export {};
@@ -0,0 +1,90 @@
1
+ export declare type Bytes = ArrayLike<number>;
2
+ /**
3
+ * @example
4
+ * [1,2,3]
5
+ *
6
+ * @example
7
+ * 0x123
8
+ *
9
+ * @example
10
+ * '0x123'
11
+ */
12
+ export declare type BytesLike = Bytes | string | number;
13
+ export interface DataOptions {
14
+ allowMissingPrefix?: boolean;
15
+ hexPad?: 'left' | 'right' | null;
16
+ }
17
+ export interface Hexable {
18
+ toHexString(): string;
19
+ }
20
+ export declare type SignatureLike = {
21
+ r: string;
22
+ s?: string;
23
+ _vs?: string;
24
+ recoveryParam?: number;
25
+ v?: number;
26
+ } | BytesLike;
27
+ export interface Signature {
28
+ r: string;
29
+ s: string;
30
+ _vs: string;
31
+ recoveryParam: number;
32
+ v: number;
33
+ yParityAndS: string;
34
+ compact: string;
35
+ }
36
+ export declare function isBytesLike(value: any): value is BytesLike;
37
+ export declare function isBytes(value: any): value is Bytes;
38
+ export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
39
+ export declare function concat(items: ReadonlyArray<BytesLike>): Uint8Array;
40
+ export declare function stripZeros(value: BytesLike): Uint8Array;
41
+ export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
42
+ export declare function isHexString(value: any, length?: number): boolean;
43
+ /**
44
+ * @example
45
+ * ```js
46
+ * hexlify(4);
47
+ * // '0x04'
48
+ *
49
+ * hexlify(14);
50
+ * // '0x0e'
51
+ * ```
52
+ */
53
+ export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
54
+ export declare function hexDataLength(data: BytesLike): number | null;
55
+ export declare function hexDataSlice(data: BytesLike, offset: number, endOffset?: number): string;
56
+ export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
57
+ export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
58
+ export declare function hexStripZeros(value: BytesLike): string;
59
+ /**
60
+ * Returns a hex string padded to a specified length of bytes.
61
+ *
62
+ * Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
63
+ *
64
+ * Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
65
+ *
66
+ * @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
67
+ * @param length - The final length in bytes
68
+ *
69
+ * @throws - If the value is not a hex string or number
70
+ * @throws - If the value is longer than the length
71
+ *
72
+ * @example
73
+ * ```javascript
74
+ * hexZeroPad('0x60', 2);
75
+ * // '0x0060'
76
+ * ```
77
+ *
78
+ * @example
79
+ * ```javascript
80
+ * hexZeroPad(0x60, 3);
81
+ * // '0x000060'
82
+ * ```
83
+ *
84
+ * @example
85
+ * ```javascript
86
+ * hexZeroPad('12345', 1);
87
+ * // Throws
88
+ * ```
89
+ */
90
+ export declare function hexZeroPad(value: BytesLike, length: number): string;