essential-eth 0.5.1 → 0.5.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/cjs/classes/Contract.d.ts +3 -2
  2. package/lib/cjs/classes/Contract.js +3 -2
  3. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +1 -0
  4. package/lib/cjs/classes/utils/encode-decode-transaction.js +4 -4
  5. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  6. package/lib/cjs/index.d.ts +2 -1
  7. package/lib/cjs/index.js +3 -1
  8. package/lib/cjs/logger/package-version.d.ts +1 -1
  9. package/lib/cjs/logger/package-version.js +1 -1
  10. package/lib/cjs/providers/BaseProvider.d.ts +261 -0
  11. package/lib/cjs/providers/BaseProvider.js +340 -0
  12. package/lib/cjs/providers/FallthroughProvider.d.ts +25 -0
  13. package/lib/cjs/providers/FallthroughProvider.js +65 -0
  14. package/lib/cjs/providers/JsonRpcProvider.d.ts +4 -200
  15. package/lib/cjs/providers/JsonRpcProvider.js +11 -263
  16. package/lib/cjs/providers/test/rpc-urls.d.ts +1 -0
  17. package/lib/cjs/providers/test/rpc-urls.js +1 -0
  18. package/lib/cjs/providers/utils/chains-info.d.ts +4 -0
  19. package/lib/cjs/providers/utils/chains-info.js +12 -0
  20. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +2 -2
  21. package/lib/cjs/shared/tiny-big/tiny-big.js +2 -2
  22. package/lib/cjs/utils/bytes.d.ts +82 -1
  23. package/lib/cjs/utils/bytes.js +83 -3
  24. package/lib/cjs/utils/solidity-keccak256.js +2 -2
  25. package/lib/esm/classes/Contract.js +1 -1
  26. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +1 -0
  27. package/lib/esm/classes/utils/encode-decode-transaction.js +2 -2
  28. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  29. package/lib/esm/index.d.ts +2 -1
  30. package/lib/esm/index.js +2 -1
  31. package/lib/esm/logger/package-version.d.ts +1 -1
  32. package/lib/esm/logger/package-version.js +1 -1
  33. package/lib/esm/providers/BaseProvider.d.ts +17 -0
  34. package/lib/esm/providers/BaseProvider.js +88 -0
  35. package/lib/esm/providers/FallthroughProvider.d.ts +12 -0
  36. package/lib/esm/providers/FallthroughProvider.js +41 -0
  37. package/lib/esm/providers/JsonRpcProvider.d.ts +4 -12
  38. package/lib/esm/providers/JsonRpcProvider.js +8 -69
  39. package/lib/esm/providers/test/rpc-urls.d.ts +1 -0
  40. package/lib/esm/providers/test/rpc-urls.js +1 -0
  41. package/lib/esm/providers/utils/chains-info.d.ts +4 -0
  42. package/lib/esm/providers/utils/chains-info.js +12 -0
  43. package/lib/esm/utils/bytes.d.ts +1 -1
  44. package/lib/esm/utils/bytes.js +2 -2
  45. package/lib/esm/utils/solidity-keccak256.js +2 -2
  46. package/package.json +11 -9
  47. package/readme.md +32 -5
@@ -1,277 +1,25 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.jsonRpcProvider = exports.JsonRpcProvider = void 0;
16
- const clean_block_1 = require("../classes/utils/clean-block");
17
- const clean_transaction_1 = require("../classes/utils/clean-transaction");
18
- const fetchers_1 = require("../classes/utils/fetchers");
19
- const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
20
- const tiny_big_1 = require("../shared/tiny-big/tiny-big");
21
- const chains_info_1 = __importDefault(require("./utils/chains-info"));
22
- class JsonRpcProvider {
4
+ const BaseProvider_1 = require("./BaseProvider");
5
+ class JsonRpcProvider extends BaseProvider_1.BaseProvider {
23
6
  /**
24
- * @param rpcUrl The URL to your Eth node. Consider POKT or Infura
25
- */
26
- constructor(rpcUrl) {
27
- /**
28
- * @ignore
29
- */
30
- this.post = (body) => (0, fetchers_1.post)(this._rpcUrl, body);
31
- this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
32
- }
33
- /**
34
- * Returns the block requested
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
- *```
7
+ * @ignore
75
8
  */
76
- getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- let rpcTimeFrame;
79
- if (typeof timeFrame === 'number') {
80
- // exact block numbers require hex string format
81
- rpcTimeFrame = `0x${timeFrame.toString(16)}`;
82
- }
83
- else {
84
- // "latest", "earliest", and "pending" require no manipulation
85
- rpcTimeFrame = timeFrame;
86
- }
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);
92
- });
9
+ selectRpcUrl() {
10
+ return this._rpcUrls[0];
93
11
  }
94
12
  /**
95
- * Returns the network this provider is connected to
13
+ * @ignore
96
14
  */
97
- getNetwork() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const hexChainId = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_chainId', [])));
100
- const chainId = (0, hex_to_decimal_1.hexToDecimal)(hexChainId);
101
- const info = chains_info_1.default[chainId];
102
- return {
103
- chainId: Number(chainId),
104
- name: info[0] || 'unknown',
105
- ensAddress: info[1] || null, // only send ensAddress if it exists
106
- };
107
- });
15
+ post(body) {
16
+ return this._post(body);
108
17
  }
109
18
  /**
110
- * Returns the current gas price in wei as TinyBig
111
- * Same as `ethers.provider.getGasPrice`
112
- */
113
- getGasPrice() {
114
- return __awaiter(this, void 0, void 0, function* () {
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
- * ```
19
+ * @param rpcUrl The URL to your Eth node. Consider POKT or Infura
262
20
  */
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;
274
- });
21
+ constructor(rpcUrl = 'https://free-eth-node.com/api/eth') {
22
+ super([rpcUrl]);
275
23
  }
276
24
  }
277
25
  exports.JsonRpcProvider = JsonRpcProvider;
@@ -3,6 +3,7 @@ export declare const fakeUrls: {
3
3
  };
4
4
  export declare const rpcUrls: {
5
5
  mainnet: string;
6
+ matic: string;
6
7
  gno: string;
7
8
  bnb: string;
8
9
  arb1: string;
@@ -6,6 +6,7 @@ exports.fakeUrls = {
6
6
  };
7
7
  exports.rpcUrls = {
8
8
  mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
9
+ matic: `${process.env.RPC_ORIGIN}/api/MATIC`,
9
10
  gno: `${process.env.RPC_ORIGIN}/api/gno`,
10
11
  bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
11
12
  arb1: `${process.env.RPC_ORIGIN}/api/arb1`,
@@ -61,6 +61,7 @@ declare const _default: {
61
61
  "67": string[];
62
62
  "68": string[];
63
63
  "69": string[];
64
+ "70": string[];
64
65
  "71": string[];
65
66
  "74": string[];
66
67
  "76": string[];
@@ -217,6 +218,7 @@ declare const _default: {
217
218
  "2221": string[];
218
219
  "2223": string[];
219
220
  "2559": string[];
221
+ "2569": string[];
220
222
  "3000": string[];
221
223
  "3001": string[];
222
224
  "3331": string[];
@@ -298,6 +300,7 @@ declare const _default: {
298
300
  "60002": string[];
299
301
  "60103": string[];
300
302
  "62320": string[];
303
+ "62621": string[];
301
304
  "63000": string[];
302
305
  "63001": string[];
303
306
  "69420": string[];
@@ -343,6 +346,7 @@ declare const _default: {
343
346
  "333999": string[];
344
347
  "421611": string[];
345
348
  "444900": string[];
349
+ "512512": string[];
346
350
  "666666": string[];
347
351
  "888888": string[];
348
352
  "955305": string[];
@@ -193,6 +193,9 @@ exports.default = {
193
193
  "69": [
194
194
  "okov"
195
195
  ],
196
+ "70": [
197
+ "hsc"
198
+ ],
196
199
  "71": [
197
200
  "cfxtest"
198
201
  ],
@@ -661,6 +664,9 @@ exports.default = {
661
664
  "2559": [
662
665
  "ktoc"
663
666
  ],
667
+ "2569": [
668
+ "tpc"
669
+ ],
664
670
  "3000": [
665
671
  "cennz-r"
666
672
  ],
@@ -904,6 +910,9 @@ exports.default = {
904
910
  "62320": [
905
911
  "BKLV"
906
912
  ],
913
+ "62621": [
914
+ "mtv"
915
+ ],
907
916
  "63000": [
908
917
  "ecs"
909
918
  ],
@@ -1039,6 +1048,9 @@ exports.default = {
1039
1048
  "444900": [
1040
1049
  "wlkt"
1041
1050
  ],
1051
+ "512512": [
1052
+ "cmp"
1053
+ ],
1042
1054
  "666666": [
1043
1055
  "vpioneer"
1044
1056
  ],
@@ -1,7 +1,7 @@
1
1
  import Big from 'big.js';
2
2
  /**
3
- * A wrapper around big.js which expands scientific notation and creates a "toHexString" function.
4
- * This is the return type of every operation on ether, wei, etc.
3
+ * A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
4
+ * * This is the return type of every operation on ether, wei, etc.
5
5
  */
6
6
  export declare class TinyBig extends Big {
7
7
  constructor(value: string | number | TinyBig | Big);
@@ -7,8 +7,8 @@ exports.tinyBig = exports.TinyBig = void 0;
7
7
  const big_js_1 = __importDefault(require("big.js"));
8
8
  const helpers_1 = require("./helpers");
9
9
  /**
10
- * A wrapper around big.js which expands scientific notation and creates a "toHexString" function.
11
- * This is the return type of every operation on ether, wei, etc.
10
+ * A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
11
+ * * This is the return type of every operation on ether, wei, etc.
12
12
  */
13
13
  class TinyBig extends big_js_1.default {
14
14
  constructor(value) {
@@ -33,12 +33,93 @@ export interface Signature {
33
33
  yParityAndS: string;
34
34
  compact: string;
35
35
  }
36
+ /**
37
+ * Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
38
+ * * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
39
+ *
40
+ * @example
41
+ * ```js
42
+ * isBytesLike([1,2,3]);
43
+ * // true
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```js
48
+ * isBytesLike(false);
49
+ * // false
50
+ * ```
51
+ *
52
+ * @example
53
+ * ```js
54
+ * isBytesLike(new Uint8Array(1));
55
+ * // true
56
+ * ```
57
+ */
36
58
  export declare function isBytesLike(value: any): value is BytesLike;
59
+ /**
60
+ * Returns true if and only if value is a valid [Bytes](#bytes)
61
+ * * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
62
+ *
63
+ * @example
64
+ * ```js
65
+ * isBytes([1,2,3]);
66
+ * // true
67
+ * ```
68
+ *
69
+ * @example
70
+ * ```js
71
+ * isBytes(false);
72
+ * // false
73
+ * ```
74
+ *
75
+ * @example
76
+ * ```js
77
+ * isBytes(new Uint8Array(1));
78
+ * // true
79
+ * ```
80
+ */
37
81
  export declare function isBytes(value: any): value is Bytes;
82
+ /**
83
+ * Converts DataHexStringOrArrayish to a Uint8Array
84
+ * * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
85
+ *
86
+ * @example
87
+ * ```js
88
+ * arrayify(1);
89
+ * // Uint8Array(1) [ 1 ]
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```js
94
+ * arrayify(0x1234);
95
+ * // Uint8Array(2) [ 18, 52 ]
96
+ * ```
97
+ *
98
+ * @example
99
+ * ```js
100
+ * arrayify('0x1', { hexPad: 'right' });
101
+ * // Uint8Array(1) [ 16 ]
102
+ * ```
103
+ */
38
104
  export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
39
- export declare function concat(items: ReadonlyArray<BytesLike>): Uint8Array;
105
+ /**
106
+ * Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
107
+ * * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
108
+ *
109
+ * @example
110
+ * ```js
111
+ * concat([0, 1]);
112
+ * // Uint8Array(2) [ 0, 1 ]
113
+ * ```
114
+ */
115
+ export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLike>): Uint8Array;
40
116
  export declare function stripZeros(value: BytesLike): Uint8Array;
41
117
  export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
118
+ /**
119
+ * Returns true if and only if object is a valid hex string.
120
+ * If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
121
+ * * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
122
+ */
42
123
  export declare function isHexString(value: any, length?: number): boolean;
43
124
  /**
44
125
  * @example
@@ -3,10 +3,31 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.hexZeroPad = exports.hexStripZeros = exports.hexValue = exports.hexConcat = exports.hexDataSlice = exports.hexDataLength = exports.hexlify = exports.isHexString = exports.zeroPad = exports.stripZeros = exports.concat = exports.arrayify = exports.isBytes = exports.isBytesLike = void 0;
5
5
  const logger_1 = require("../logger/logger");
6
- ///////////////////////////////
7
6
  function isHexable(value) {
8
7
  return !!value.toHexString;
9
8
  }
9
+ /**
10
+ * Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
11
+ * * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
12
+ *
13
+ * @example
14
+ * ```js
15
+ * isBytesLike([1,2,3]);
16
+ * // true
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```js
21
+ * isBytesLike(false);
22
+ * // false
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```js
27
+ * isBytesLike(new Uint8Array(1));
28
+ * // true
29
+ * ```
30
+ */
10
31
  function isBytesLike(value) {
11
32
  return (isHexString(value) && !(value.length % 2)) || isBytes(value);
12
33
  }
@@ -14,6 +35,28 @@ exports.isBytesLike = isBytesLike;
14
35
  function isInteger(value) {
15
36
  return typeof value === 'number' && value == value && value % 1 === 0;
16
37
  }
38
+ /**
39
+ * Returns true if and only if value is a valid [Bytes](#bytes)
40
+ * * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
41
+ *
42
+ * @example
43
+ * ```js
44
+ * isBytes([1,2,3]);
45
+ * // true
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```js
50
+ * isBytes(false);
51
+ * // false
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```js
56
+ * isBytes(new Uint8Array(1));
57
+ * // true
58
+ * ```
59
+ */
17
60
  function isBytes(value) {
18
61
  if (value == null) {
19
62
  return false;
@@ -36,6 +79,28 @@ function isBytes(value) {
36
79
  return true;
37
80
  }
38
81
  exports.isBytes = isBytes;
82
+ /**
83
+ * Converts DataHexStringOrArrayish to a Uint8Array
84
+ * * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
85
+ *
86
+ * @example
87
+ * ```js
88
+ * arrayify(1);
89
+ * // Uint8Array(1) [ 1 ]
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```js
94
+ * arrayify(0x1234);
95
+ * // Uint8Array(2) [ 18, 52 ]
96
+ * ```
97
+ *
98
+ * @example
99
+ * ```js
100
+ * arrayify('0x1', { hexPad: 'right' });
101
+ * // Uint8Array(1) [ 16 ]
102
+ * ```
103
+ */
39
104
  function arrayify(value, options) {
40
105
  if (!options) {
41
106
  options = {};
@@ -85,8 +150,18 @@ function arrayify(value, options) {
85
150
  return logger_1.logger.throwArgumentError('invalid arrayify value', 'value', value);
86
151
  }
87
152
  exports.arrayify = arrayify;
88
- function concat(items) {
89
- const objects = items.map((item) => arrayify(item));
153
+ /**
154
+ * Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
155
+ * * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
156
+ *
157
+ * @example
158
+ * ```js
159
+ * concat([0, 1]);
160
+ * // Uint8Array(2) [ 0, 1 ]
161
+ * ```
162
+ */
163
+ function concat(arrayOfBytesLike) {
164
+ const objects = arrayOfBytesLike.map((item) => arrayify(item));
90
165
  const length = objects.reduce((accum, item) => accum + item.length, 0);
91
166
  const result = new Uint8Array(length);
92
167
  objects.reduce((offset, object) => {
@@ -123,6 +198,11 @@ function zeroPad(value, length) {
123
198
  return result;
124
199
  }
125
200
  exports.zeroPad = zeroPad;
201
+ /**
202
+ * Returns true if and only if object is a valid hex string.
203
+ * If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
204
+ * * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
205
+ */
126
206
  function isHexString(value, length) {
127
207
  if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
128
208
  return false;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.solidityKeccak256 = exports.hashKeccak256 = exports.pack = void 0;
4
4
  const buffer_1 = require("buffer");
5
5
  const sha3_1 = require("sha3");
6
+ const encode_decode_transaction_1 = require("../classes/utils/encode-decode-transaction");
6
7
  const logger_1 = require("../logger/logger");
7
8
  const tiny_big_1 = require("../shared/tiny-big/tiny-big");
8
9
  const bytes_1 = require("./bytes");
9
10
  const regexBytes = new RegExp('^bytes([0-9]+)$');
10
11
  const regexNumber = new RegExp('^(u?int)([0-9]*)$');
11
12
  const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
12
- const Zeros = '0000000000000000000000000000000000000000000000000000000000000000';
13
13
  function _pack(type, value, isArray) {
14
14
  switch (type) {
15
15
  case 'address':
@@ -55,7 +55,7 @@ function _pack(type, value, isArray) {
55
55
  logger_1.logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
56
56
  }
57
57
  if (isArray) {
58
- return (0, bytes_1.arrayify)((value + Zeros).substring(0, 66));
58
+ return (0, bytes_1.arrayify)((value + encode_decode_transaction_1.hexFalse).substring(0, 66));
59
59
  }
60
60
  return value;
61
61
  }
@@ -40,7 +40,7 @@ export class BaseContract {
40
40
  ? estimateGas(data)
41
41
  : null;
42
42
  const req = () => __awaiter(this, void 0, void 0, function* () {
43
- return yield post(this._provider._rpcUrl, buildRPCPostBody('eth_call', [
43
+ return yield post(this._provider.selectRpcUrl(), buildRPCPostBody('eth_call', [
44
44
  Object.assign({ to: this._address.toLowerCase(), data }, (decimalGas
45
45
  ? { gas: `0x${decimalGas.toString(16)}` }
46
46
  : {})),
@@ -1,3 +1,4 @@
1
1
  import { JSONABIArgument } from '../../types/Contract.types';
2
+ export declare const hexFalse: string;
2
3
  export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
3
4
  export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../..").TinyBig | (string | number | boolean | import("../..").TinyBig)[];
@@ -1,8 +1,8 @@
1
1
  import { Keccak } from 'sha3';
2
2
  import { tinyBig, toChecksumAddress } from '../..';
3
3
  import { hexToDecimal } from './hex-to-decimal';
4
- const hexTrue = '0000000000000000000000000000000000000000000000000000000000000001';
5
- const hexFalse = '0000000000000000000000000000000000000000000000000000000000000000';
4
+ export const hexFalse = '0'.repeat(64);
5
+ const hexTrue = '0'.repeat(63) + '1';
6
6
  function expandType(type) {
7
7
  if (type === 'uint[]') {
8
8
  return 'uint256[]';
@@ -1,5 +1,5 @@
1
1
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash';
2
+ declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionCount';
3
3
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
4
  jsonrpc: string;
5
5
  id: number;