essential-eth 0.5.1 โ†’ 0.5.5

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 (79) 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/clean-transaction-receipt.d.ts +5 -0
  4. package/lib/cjs/classes/utils/clean-transaction-receipt.js +55 -0
  5. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +1 -0
  6. package/lib/cjs/classes/utils/encode-decode-transaction.js +4 -4
  7. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  8. package/lib/cjs/index.d.ts +12 -4
  9. package/lib/cjs/index.js +16 -1
  10. package/lib/cjs/logger/package-version.d.ts +1 -1
  11. package/lib/cjs/logger/package-version.js +1 -1
  12. package/lib/cjs/providers/BaseProvider.d.ts +284 -0
  13. package/lib/cjs/providers/BaseProvider.js +380 -0
  14. package/lib/cjs/providers/FallthroughProvider.d.ts +24 -0
  15. package/lib/cjs/providers/FallthroughProvider.js +65 -0
  16. package/lib/cjs/providers/JsonRpcProvider.d.ts +4 -200
  17. package/lib/cjs/providers/JsonRpcProvider.js +11 -263
  18. package/lib/cjs/providers/test/rpc-urls.d.ts +1 -0
  19. package/lib/cjs/providers/test/rpc-urls.js +1 -0
  20. package/lib/cjs/providers/utils/chains-info.d.ts +20 -0
  21. package/lib/cjs/providers/utils/chains-info.js +62 -2
  22. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +2 -2
  23. package/lib/cjs/shared/tiny-big/tiny-big.js +2 -2
  24. package/lib/cjs/types/Transaction.types.d.ts +53 -0
  25. package/lib/cjs/utils/bytes.d.ts +86 -4
  26. package/lib/cjs/utils/bytes.js +83 -3
  27. package/lib/cjs/utils/compute-address.d.ts +8 -0
  28. package/lib/cjs/utils/compute-address.js +24 -0
  29. package/lib/cjs/utils/compute-public-key.d.ts +9 -0
  30. package/lib/cjs/utils/compute-public-key.js +17 -0
  31. package/lib/cjs/utils/hash-message.d.ts +12 -0
  32. package/lib/cjs/utils/hash-message.js +26 -0
  33. package/lib/cjs/utils/keccak256.d.ts +2 -0
  34. package/lib/cjs/utils/keccak256.js +17 -0
  35. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -1
  36. package/lib/cjs/utils/solidity-keccak256.js +5 -12
  37. package/lib/cjs/utils/split-signature.d.ts +26 -0
  38. package/lib/cjs/utils/split-signature.js +165 -0
  39. package/lib/cjs/utils/to-utf8-bytes.d.ts +1 -0
  40. package/lib/cjs/utils/to-utf8-bytes.js +7 -0
  41. package/lib/esm/classes/Contract.js +1 -1
  42. package/lib/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  43. package/lib/esm/classes/utils/clean-transaction-receipt.js +48 -0
  44. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +1 -0
  45. package/lib/esm/classes/utils/encode-decode-transaction.js +2 -2
  46. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  47. package/lib/esm/index.d.ts +12 -4
  48. package/lib/esm/index.js +10 -2
  49. package/lib/esm/logger/package-version.d.ts +1 -1
  50. package/lib/esm/logger/package-version.js +1 -1
  51. package/lib/esm/providers/BaseProvider.d.ts +19 -0
  52. package/lib/esm/providers/BaseProvider.js +107 -0
  53. package/lib/esm/providers/FallthroughProvider.d.ts +11 -0
  54. package/lib/esm/providers/FallthroughProvider.js +41 -0
  55. package/lib/esm/providers/JsonRpcProvider.d.ts +4 -12
  56. package/lib/esm/providers/JsonRpcProvider.js +8 -69
  57. package/lib/esm/providers/test/rpc-urls.d.ts +1 -0
  58. package/lib/esm/providers/test/rpc-urls.js +1 -0
  59. package/lib/esm/providers/utils/chains-info.d.ts +20 -0
  60. package/lib/esm/providers/utils/chains-info.js +62 -2
  61. package/lib/esm/types/Transaction.types.d.ts +45 -0
  62. package/lib/esm/utils/bytes.d.ts +5 -4
  63. package/lib/esm/utils/bytes.js +2 -2
  64. package/lib/esm/utils/compute-address.d.ts +1 -0
  65. package/lib/esm/utils/compute-address.js +11 -0
  66. package/lib/esm/utils/compute-public-key.d.ts +2 -0
  67. package/lib/esm/utils/compute-public-key.js +6 -0
  68. package/lib/esm/utils/hash-message.d.ts +2 -0
  69. package/lib/esm/utils/hash-message.js +12 -0
  70. package/lib/esm/utils/keccak256.d.ts +2 -0
  71. package/lib/esm/utils/keccak256.js +13 -0
  72. package/lib/esm/utils/solidity-keccak256.d.ts +0 -1
  73. package/lib/esm/utils/solidity-keccak256.js +4 -10
  74. package/lib/esm/utils/split-signature.d.ts +2 -0
  75. package/lib/esm/utils/split-signature.js +126 -0
  76. package/lib/esm/utils/to-utf8-bytes.d.ts +1 -0
  77. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  78. package/package.json +19 -14
  79. package/readme.md +648 -95
package/readme.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://user-images.githubusercontent.com/3408480/163274699-ae4fb0f4-fca0-4745-bcd7-4868f80deaf6.png" title="Logo"/>
2
+ <img src="https://user-images.githubusercontent.com/3408480/163274699-ae4fb0f4-fca0-4745-bcd7-4868f80deaf6.png" height="220" title="Logo"/>
3
3
 
4
4
  </p>
5
5
  <p align="center">
@@ -8,12 +8,10 @@
8
8
  ๐Ÿชถ Essential Eth ๐Ÿชถ
9
9
  </b>
10
10
  <br/>
11
- <i>A replacement for ethers & web3 that's 50x smaller</i>
11
+ <i>An alternative for ethers & web3 that's 20x smaller</i>
12
12
  <br/>
13
13
  </p>
14
14
 
15
- ---
16
-
17
15
  <br/>
18
16
 
19
17
  ## Why you should replace Ethers.js and web3
@@ -24,6 +22,8 @@
24
22
 
25
23
  ---
26
24
 
25
+ [![๐Ÿงช tests](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml/badge.svg)](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/Earnifi/essential-eth/branch/master/graph/badge.svg?token=E44EK6RWTZ)](https://codecov.io/gh/Earnifi/essential-eth) ![](https://badgen.net/bundlephobia/minzip/essential-eth) ![](https://badgen.net/bundlephobia/tree-shaking/essential-eth) ![](https://img.shields.io/npm/v/essential-eth)
26
+
27
27
  <br/>
28
28
 
29
29
  - ๐Ÿ†๏ธ <sub><sup>[smallest code size possible](https://bundlephobia.com/package/essential-eth)</sup></sub>
@@ -32,23 +32,79 @@
32
32
  - - โšก๏ธ Near-identical API to `ethers`
33
33
  - ๐ŸŒฒ Tree-shaking and no side-effects
34
34
  - ๐Ÿ™Œ Supports multiple JS versions (CommonJS and ESM)
35
- - โœ… Node 17, 16, 14, & 12
35
+ - โœ… Node 18, 16, 14, & 12
36
36
  - โœ… Web
37
37
 
38
38
  <br/>
39
39
 
40
+ ## Table of Contents
41
+
42
+ <!-- โ›”๏ธ AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click to expand) -->
43
+ <details>
44
+ <summary>Click to expand</summary>
45
+
46
+ - [Why you should replace Ethers.js and web3](#why-you-should-replace-ethersjs-and-web3)
47
+ - [Install](#install)
48
+ - [๐Ÿ›  Utils](#-utils)
49
+ - [`arrayify`](#arrayify)
50
+ - [`computeAddress`](#computeaddress)
51
+ - [`computePublicKey`](#computepublickey)
52
+ - [`concat`](#concat)
53
+ - [`etherToGwei`](#ethertogwei)
54
+ - [`etherToWei`](#ethertowei)
55
+ - [`gweiToEther`](#gweitoether)
56
+ - [`hashMessage`](#hashmessage)
57
+ - [`hexConcat`](#hexconcat)
58
+ - [`hexDataLength`](#hexdatalength)
59
+ - [`hexDataSlice`](#hexdataslice)
60
+ - [`hexStripZeros`](#hexstripzeros)
61
+ - [`hexValue`](#hexvalue)
62
+ - [`hexZeroPad`](#hexzeropad)
63
+ - [`hexlify`](#hexlify)
64
+ - [`isAddress`](#isaddress)
65
+ - [`isBytes`](#isbytes)
66
+ - [`isBytesLike`](#isbyteslike)
67
+ - [`isHexString`](#ishexstring)
68
+ - [`jsonRpcProvider`](#jsonrpcprovider)
69
+ - [`keccak256`](#keccak256)
70
+ - [`pack`](#pack)
71
+ - [`solidityKeccak256`](#soliditykeccak256)
72
+ - [`splitSignature`](#splitsignature)
73
+ - [`stripZeros`](#stripzeros)
74
+ - [`tinyBig`](#tinybig)
75
+ - [`toChecksumAddress`](#tochecksumaddress)
76
+ - [`toUtf8Bytes`](#toutf8bytes)
77
+ - [`weiToEther`](#weitoether)
78
+ - [`zeroPad`](#zeropad)
79
+ - [RPC](#rpc)
80
+ - [`getTransactionCount(address, blockTag?): Promise<number>`](#gettransactioncountaddress-blocktag-promisenumber)
81
+ - [`getGasPrice`](#getgasprice)
82
+ - [`getBalance`](#getbalance)
83
+ - [`getNetwork`](#getnetwork)
84
+ - [`getBlock`](#getblock)
85
+ - [`getTransaction`](#gettransaction)
86
+ - [Contract](#contract)
87
+ - [`contractFunctionName(args)`](#contractfunctionnameargs)
88
+ - [More Info](#more-info)
89
+
90
+ </details>
91
+
92
+ <!-- โ›”๏ธ AUTO-GENERATED-CONTENT:END -->
93
+
94
+ <br/>
95
+
40
96
  ## Install
41
97
 
42
98
  ```sh
43
99
  npm install --save essential-eth # TypeScript types load automatically
44
100
 
45
- # or if you prefer yarn
101
+ # or yarn
46
102
  yarn add essential-eth # TypeScript types load automatically
47
103
  ```
48
104
 
49
105
  <br/>
50
106
 
51
- ## Utils (do not require connecting to an Eth node)
107
+ ## ๐Ÿ›  Utils
52
108
 
53
109
  ```typescript
54
110
  import { etherToWei } from 'essential-eth';
@@ -57,191 +113,661 @@ import { etherToWei } from 'essential-eth';
57
113
  const { etherToWei } = require('essential-eth');
58
114
  ```
59
115
 
60
- - The return-type `TinyBig` is just [`Big`](https://github.com/MikeMcl/big.js) but expands scientific notation on `toNumber()` and `toString()`
116
+ <!-- โ›”๏ธ AUTO-GENERATED-CONTENT:START (FUNCTIONS) -->
61
117
 
62
- <br/>
63
-
64
- #### `etherToWei`
118
+ #### [`arrayify`](https://essential-eth.vercel.app/docs/api/modules#arrayify)
65
119
 
66
120
  ```typescript
67
- // convert ether to wei
68
- etherToWei(etherQuantity: string | number | TinyBig | Big): TinyBig
121
+ arrayify(value: number | BytesLike | Hexable, options: DataOptions): Uint8Array
69
122
  ```
70
123
 
71
- <details>
124
+ <details>
72
125
  <summary>View Example</summary>
73
126
 
127
+ ```js
128
+ import { arrayify } from 'essential-eth';
129
+
130
+ // or in a require environment
131
+ const { arrayify } = require('essential-eth');
132
+ ```
133
+
134
+ ```js
135
+ arrayify(1);
136
+ // Uint8Array(1) [ 1 ]
137
+ ```
138
+
139
+ ```js
140
+ arrayify(0x1234);
141
+ // Uint8Array(2) [ 18, 52 ]
142
+ ```
143
+
144
+ ```js
145
+ arrayify('0x1', { hexPad: 'right' });
146
+ // Uint8Array(1) [ 16 ]
147
+ ```
148
+
149
+ </details>
150
+
151
+ <br/>
152
+
153
+ #### [`computeAddress`](https://essential-eth.vercel.app/docs/api/modules#computeaddress)
154
+
74
155
  ```typescript
75
- import { etherToWei } from 'essential-eth';
156
+ computeAddress(key: string): string
157
+ ```
76
158
 
77
- etherToWei(1).toString();
78
- // "1000000000000000000"
159
+ <br/>
79
160
 
80
- etherToWei(1).toNumber();
81
- // 1000000000000000000
161
+ #### [`computePublicKey`](https://essential-eth.vercel.app/docs/api/modules#computepublickey)
82
162
 
83
- etherToWei('1').toNumber();
84
- // 1000000000000000000
163
+ ```typescript
164
+ computePublicKey(privKey: BytesLike): string
85
165
  ```
86
166
 
87
- </details>
167
+ <br/>
88
168
 
89
- <br/>
169
+ #### [`concat`](https://essential-eth.vercel.app/docs/api/modules#concat)
170
+
171
+ ```typescript
172
+ concat(arrayOfBytesLike: Array<BytesLikeWithNumber>): Uint8Array
173
+ ```
90
174
 
91
- #### `weiToEther`
175
+ <details>
176
+ <summary>View Example</summary>
177
+
178
+ ```js
179
+ import { concat } from 'essential-eth';
180
+
181
+ // or in a require environment
182
+ const { concat } = require('essential-eth');
183
+ ```
184
+
185
+ ```js
186
+ concat([0, 1]);
187
+ // Uint8Array(2) [ 0, 1 ]
188
+ ```
189
+
190
+ </details>
191
+
192
+ <br/>
193
+
194
+ #### [`etherToGwei`](https://essential-eth.vercel.app/docs/api/modules#ethertogwei)
92
195
 
93
196
  ```typescript
94
- // convert wei to ether
95
- weiToEther(weiQuantity: string | number | TinyBig | Big): TinyBig
197
+ etherToGwei(etherQuantity: string | number | TinyBig | Big): TinyBig
96
198
  ```
97
199
 
98
- <details>
200
+ <details>
99
201
  <summary>View Example</summary>
100
202
 
203
+ ```js
204
+ import { etherToGwei } from 'essential-eth';
205
+
206
+ // or in a require environment
207
+ const { etherToGwei } = require('essential-eth');
208
+ ```
209
+
210
+ ```javascript
211
+ etherToGwei('1000').toString();
212
+ // '1000000000000'
213
+ etherToGwei(1000).toString();
214
+ // '1000000000000'
215
+ ```
216
+
217
+ ```javascript
218
+ etherToGwei('1000').toNumber();
219
+ // 1000000000000
220
+ etherToGwei(1000).toNumber();
221
+ // 1000000000000
222
+ ```
223
+
224
+ </details>
225
+
226
+ <br/>
227
+
228
+ #### [`etherToWei`](https://essential-eth.vercel.app/docs/api/modules#ethertowei)
229
+
101
230
  ```typescript
102
- import { weiToEther } from 'essential-eth';
231
+ etherToWei(etherQuantity: string | number | TinyBig | Big): TinyBig
232
+ ```
103
233
 
104
- weiToEther(1000000000000000000).toString();
105
- // "1"
234
+ <details>
235
+ <summary>View Example</summary>
236
+
237
+ ```js
238
+ import { etherToWei } from 'essential-eth';
106
239
 
107
- weiToEther(1000000000000000000).toNumber();
108
- // 1
109
- weiToEther('1000000000000000000').toNumber();
110
- // 1
240
+ // or in a require environment
241
+ const { etherToWei } = require('essential-eth');
111
242
  ```
112
243
 
113
- </details>
244
+ ```javascript
245
+ etherToWei('1000').toString();
246
+ // '1000000000000000000000'
247
+ etherToWei(1000).toString();
248
+ // '1000000000000000000000'
249
+ ```
114
250
 
115
- <br/>
251
+ ```javascript
252
+ etherToWei('1000').toNumber();
253
+ // 1000000000000000000000
254
+ etherToWei(1000).toNumber();
255
+ // 1000000000000000000000
256
+ ```
257
+
258
+ </details>
259
+
260
+ <br/>
116
261
 
117
- #### `gweiToEther`
262
+ #### [`gweiToEther`](https://essential-eth.vercel.app/docs/api/modules#gweitoether)
118
263
 
119
264
  ```typescript
120
265
  gweiToEther(gweiQuantity: string | number | TinyBig | Big): TinyBig
121
266
  ```
122
267
 
123
- <details>
268
+ <details>
124
269
  <summary>View Example</summary>
125
270
 
126
- ```typescript
271
+ ```js
127
272
  import { gweiToEther } from 'essential-eth';
128
273
 
129
- gweiToEther(1000000000).toString();
130
- // "1"
274
+ // or in a require environment
275
+ const { gweiToEther } = require('essential-eth');
276
+ ```
131
277
 
132
- gweiToEther(1000000000).toNumber();
133
- // 1
134
- gweiToEther('1000000000').toNumber();
135
- // 1
278
+ ```javascript
279
+ gweiToEther('1000000000000').toString();
280
+ // '1000'
281
+ gweiToEther(1000000000000).toString();
282
+ // '1000'
136
283
  ```
137
284
 
138
- </details>
285
+ ```javascript
286
+ gweiToEther('1000000000000').toNumber();
287
+ // 1000
288
+ gweiToEther(1000000000000).toNumber();
289
+ // 1000
290
+ ```
139
291
 
140
- <br/>
292
+ </details>
293
+
294
+ <br/>
141
295
 
142
- #### `etherToGwei`
296
+ #### [`hashMessage`](https://essential-eth.vercel.app/docs/api/modules#hashmessage)
143
297
 
144
298
  ```typescript
145
- etherToGwei(etherQuantity: string | number | TinyBig | Big): TinyBig
299
+ hashMessage(message: string | Bytes): string
146
300
  ```
147
301
 
148
- <details>
302
+ <details>
149
303
  <summary>View Example</summary>
150
304
 
305
+ ```js
306
+ import { hashMessage } from 'essential-eth';
307
+
308
+ // or in a require environment
309
+ const { hashMessage } = require('essential-eth');
310
+ ```
311
+
312
+ ```js
313
+ hashMessage('Hello World');
314
+ // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
315
+ ```
316
+
317
+ </details>
318
+
319
+ <br/>
320
+
321
+ #### [`hexConcat`](https://essential-eth.vercel.app/docs/api/modules#hexconcat)
322
+
151
323
  ```typescript
152
- import { etherToGwei } from 'essential-eth';
324
+ hexConcat(items: Array<BytesLike>): string
325
+ ```
153
326
 
154
- etherToGwei(0.000000001).toString();
155
- // "1"
327
+ <br/>
328
+
329
+ #### [`hexDataLength`](https://essential-eth.vercel.app/docs/api/modules#hexdatalength)
156
330
 
157
- etherToGwei(0.000000001).toNumber();
158
- // 1
159
- etherToGwei('0.000000001').toNumber();
160
- // 1
331
+ ```typescript
332
+ hexDataLength(data: BytesLike): null | number
161
333
  ```
162
334
 
163
- </details>
335
+ <br/>
164
336
 
165
- <br/>
337
+ #### [`hexDataSlice`](https://essential-eth.vercel.app/docs/api/modules#hexdataslice)
338
+
339
+ ```typescript
340
+ hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset: number): string
341
+ ```
342
+
343
+ <br/>
166
344
 
167
- #### `toChecksumAddress`
345
+ #### [`hexStripZeros`](https://essential-eth.vercel.app/docs/api/modules#hexstripzeros)
168
346
 
169
347
  ```typescript
170
- // return proper mixed-case address
171
- // does not support ICAP addresses
172
- toChecksumAddress(address: string): string
348
+ hexStripZeros(value: BytesLike): string
173
349
  ```
174
350
 
175
- <details>
351
+ <br/>
352
+
353
+ #### [`hexValue`](https://essential-eth.vercel.app/docs/api/modules#hexvalue)
354
+
355
+ ```typescript
356
+ hexValue(value: number | bigint | BytesLike | Hexable): string
357
+ ```
358
+
359
+ <br/>
360
+
361
+ #### [`hexZeroPad`](https://essential-eth.vercel.app/docs/api/modules#hexzeropad)
362
+
363
+ ```typescript
364
+ hexZeroPad(value: BytesLikeWithNumber, length: number): string
365
+ ```
366
+
367
+ <details>
176
368
  <summary>View Example</summary>
177
369
 
370
+ ```js
371
+ import { hexZeroPad } from 'essential-eth';
372
+
373
+ // or in a require environment
374
+ const { hexZeroPad } = require('essential-eth');
375
+ ```
376
+
377
+ ```javascript
378
+ hexZeroPad('0x60', 2);
379
+ // '0x0060'
380
+ ```
381
+
382
+ ```javascript
383
+ hexZeroPad(0x60, 3);
384
+ // '0x000060'
385
+ ```
386
+
387
+ ```javascript
388
+ hexZeroPad('12345', 1);
389
+ // Throws
390
+ ```
391
+
392
+ </details>
393
+
394
+ <br/>
395
+
396
+ #### [`hexlify`](https://essential-eth.vercel.app/docs/api/modules#hexlify)
397
+
178
398
  ```typescript
179
- import { toChecksumAddress } from 'essential-eth';
399
+ hexlify(value: number | bigint | BytesLike | Hexable, options: DataOptions): string
400
+ ```
401
+
402
+ <details>
403
+ <summary>View Example</summary>
180
404
 
181
- toChecksumAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
182
- // "0xc0DEAF6bD3F0c6574a6a625EF2F22f62A5150EAB"
405
+ ```js
406
+ import { hexlify } from 'essential-eth';
407
+
408
+ // or in a require environment
409
+ const { hexlify } = require('essential-eth');
183
410
  ```
184
411
 
185
- </details>
412
+ ```js
413
+ hexlify(4);
414
+ // '0x04'
186
415
 
187
- <br/>
416
+ hexlify(14);
417
+ // '0x0e'
418
+ ```
419
+
420
+ </details>
188
421
 
189
- #### `isAddress`
422
+ <br/>
423
+
424
+ #### [`isAddress`](https://essential-eth.vercel.app/docs/api/modules#isaddress)
190
425
 
191
426
  ```typescript
192
- // returns boolean as to whether input is a valid address
193
- // does not support ENS nor ICAP
194
427
  isAddress(address: string): boolean
195
428
  ```
196
429
 
197
- <details>
430
+ <details>
198
431
  <summary>View Example</summary>
199
432
 
200
- ```typescript
433
+ ```js
201
434
  import { isAddress } from 'essential-eth';
202
435
 
436
+ // or in a require environment
437
+ const { isAddress } = require('essential-eth');
438
+ ```
439
+
440
+ ```javascript
203
441
  isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
204
442
  // true
443
+ ```
205
444
 
445
+ ```javascript
206
446
  isAddress('bad');
207
447
  // false
448
+ ```
208
449
 
450
+ ```javascript
209
451
  // Does NOT support ENS.
210
452
  isAddress('vitalik.eth');
211
453
  // false
212
454
  ```
213
455
 
214
- </details>
456
+ </details>
215
457
 
216
- <br/>
458
+ <br/>
217
459
 
218
- #### `hexZeroPad`
460
+ #### [`isBytes`](https://essential-eth.vercel.app/docs/api/modules#isbytes)
219
461
 
220
462
  ```typescript
221
- // returns a hex string padded to a specified length of bytes
222
- // if the hex value provided is already longer than the padding value, the value itself is returned without alteration
223
- hexZeroPad(hexValue: string | number, length: number): string
463
+ isBytes(value: any): value
224
464
  ```
225
465
 
226
- <details>
466
+ <details>
467
+ <summary>View Example</summary>
468
+
469
+ ```js
470
+ import { isBytes } from 'essential-eth';
471
+
472
+ // or in a require environment
473
+ const { isBytes } = require('essential-eth');
474
+ ```
475
+
476
+ ```js
477
+ isBytes([1, 2, 3]);
478
+ // true
479
+ ```
480
+
481
+ ```js
482
+ isBytes(false);
483
+ // false
484
+ ```
485
+
486
+ ```js
487
+ isBytes(new Uint8Array(1));
488
+ // true
489
+ ```
490
+
491
+ </details>
492
+
493
+ <br/>
494
+
495
+ #### [`isBytesLike`](https://essential-eth.vercel.app/docs/api/modules#isbyteslike)
496
+
497
+ ```typescript
498
+ isBytesLike(value: any): value
499
+ ```
500
+
501
+ <details>
227
502
  <summary>View Example</summary>
228
503
 
504
+ ```js
505
+ import { isBytesLike } from 'essential-eth';
506
+
507
+ // or in a require environment
508
+ const { isBytesLike } = require('essential-eth');
509
+ ```
510
+
511
+ ```js
512
+ isBytesLike([1, 2, 3]);
513
+ // true
514
+ ```
515
+
516
+ ```js
517
+ isBytesLike(false);
518
+ // false
519
+ ```
520
+
521
+ ```js
522
+ isBytesLike(new Uint8Array(1));
523
+ // true
524
+ ```
525
+
526
+ </details>
527
+
528
+ <br/>
529
+
530
+ #### [`isHexString`](https://essential-eth.vercel.app/docs/api/modules#ishexstring)
531
+
229
532
  ```typescript
230
- import { hexZeroPad } from 'essential-eth';
533
+ isHexString(value: any, length: number): boolean
534
+ ```
231
535
 
232
- hexZeroPad('0x60', 2);
233
- // '0x0060'
536
+ <br/>
234
537
 
235
- hexZeroPad(0x60, 3);
236
- // '0x000060'
538
+ #### [`jsonRpcProvider`](https://essential-eth.vercel.app/docs/api/modules#jsonrpcprovider)
539
+
540
+ ```typescript
541
+ jsonRpcProvider(rpcUrl: string): JsonRpcProvider
542
+ ```
543
+
544
+ <details>
545
+ <summary>View Example</summary>
546
+
547
+ ```js
548
+ import { jsonRpcProvider } from 'essential-eth';
237
549
 
238
- // Length of string is already longer than padding value
239
- hexZeroPad('0x31323334', 3);
240
- // Throws error
550
+ // or in a require environment
551
+ const { jsonRpcProvider } = require('essential-eth');
241
552
  ```
242
553
 
243
- </details>
554
+ ```javascript
555
+ jsonRpcProvider()
556
+ .getBlock('latest')
557
+ .then((block) => {
558
+ console.log(block.number);
559
+ });
560
+ // 14530496
561
+ ```
562
+
563
+ </details>
564
+
565
+ <br/>
566
+
567
+ #### [`keccak256`](https://essential-eth.vercel.app/docs/api/modules#keccak256)
568
+
569
+ ```typescript
570
+ keccak256(data: BytesLike): string
571
+ ```
572
+
573
+ <br/>
574
+
575
+ #### [`pack`](https://essential-eth.vercel.app/docs/api/modules#pack)
576
+
577
+ ```typescript
578
+ pack(types: Array<string>, values: Array<any>): string
579
+ ```
580
+
581
+ <br/>
582
+
583
+ #### [`solidityKeccak256`](https://essential-eth.vercel.app/docs/api/modules#soliditykeccak256)
584
+
585
+ ```typescript
586
+ solidityKeccak256(types: Array<string>, values: Array<any>): string
587
+ ```
588
+
589
+ <details>
590
+ <summary>View Example</summary>
591
+
592
+ ```js
593
+ import { solidityKeccak256 } from 'essential-eth';
594
+
595
+ // or in a require environment
596
+ const { solidityKeccak256 } = require('essential-eth');
597
+ ```
598
+
599
+ ```javascript
600
+ const types = ['string', 'bool', 'uint32'];
601
+ const values = ['essential-eth is great', true, 14];
602
+ solidityKeccak256(types, values);
603
+ // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
604
+ ```
605
+
606
+ ```javascript
607
+ const types = ['bytes4', 'uint32[5]'];
608
+ const values = [
609
+ [116, 101, 115, 116],
610
+ [5, 3, 4, 9, 18],
611
+ ];
612
+ solidityKeccak256(types, values);
613
+ // '0x038707a887f09355dc545412b058e7ba8f3c74047050c7c5e5e52eec608053d9'
614
+ ```
615
+
616
+ </details>
617
+
618
+ <br/>
619
+
620
+ #### [`splitSignature`](https://essential-eth.vercel.app/docs/api/modules#splitsignature)
621
+
622
+ ```typescript
623
+ splitSignature(signature: SignatureLike): Signature
624
+ ```
625
+
626
+ <details>
627
+ <summary>View Example</summary>
628
+
629
+ ```js
630
+ import { splitSignature } from 'essential-eth';
631
+
632
+ // or in a require environment
633
+ const { splitSignature } = require('essential-eth');
634
+ ```
635
+
636
+ ```javascript
637
+ const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
638
+ splitSignature(signature);
639
+ {
640
+ r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
641
+ s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
642
+ _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
643
+ recoveryParam: 0,
644
+ v: 27,
645
+ yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
646
+ compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
647
+ }
648
+ ```
649
+
650
+ </details>
651
+
652
+ <br/>
653
+
654
+ #### [`stripZeros`](https://essential-eth.vercel.app/docs/api/modules#stripzeros)
655
+
656
+ ```typescript
657
+ stripZeros(value: BytesLike): Uint8Array
658
+ ```
659
+
660
+ <br/>
661
+
662
+ #### [`tinyBig`](https://essential-eth.vercel.app/docs/api/modules#tinybig)
663
+
664
+ ```typescript
665
+ tinyBig(value: string | number | TinyBig | Big): TinyBig
666
+ ```
667
+
668
+ <details>
669
+ <summary>View Example</summary>
670
+
671
+ ```js
672
+ import { tinyBig } from 'essential-eth';
673
+
674
+ // or in a require environment
675
+ const { tinyBig } = require('essential-eth');
676
+ ```
677
+
678
+ ```javascript
679
+ tinyBig(10).times(3).toNumber();
680
+ // 30
681
+ ```
682
+
683
+ </details>
684
+
685
+ <br/>
686
+
687
+ #### [`toChecksumAddress`](https://essential-eth.vercel.app/docs/api/modules#tochecksumaddress)
688
+
689
+ ```typescript
690
+ toChecksumAddress(address: string): string
691
+ ```
692
+
693
+ <details>
694
+ <summary>View Example</summary>
695
+
696
+ ```js
697
+ import { toChecksumAddress } from 'essential-eth';
698
+
699
+ // or in a require environment
700
+ const { toChecksumAddress } = require('essential-eth');
701
+ ```
702
+
703
+ ```javascript
704
+ toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
705
+ // '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
706
+ ```
707
+
708
+ Similar to ["getAddress" in ethers.js](https://docs.ethers.io/v5/api/utils/address/#utils-getAddress)
709
+
710
+ Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#tochecksumaddress)
711
+
712
+ </details>
713
+
714
+ <br/>
715
+
716
+ #### [`toUtf8Bytes`](https://essential-eth.vercel.app/docs/api/modules#toutf8bytes)
717
+
718
+ ```typescript
719
+ toUtf8Bytes(data: string): Uint8Array
720
+ ```
721
+
722
+ <br/>
723
+
724
+ #### [`weiToEther`](https://essential-eth.vercel.app/docs/api/modules#weitoether)
725
+
726
+ ```typescript
727
+ weiToEther(weiQuantity: string | number | TinyBig | Big): TinyBig
728
+ ```
729
+
730
+ <details>
731
+ <summary>View Example</summary>
732
+
733
+ ```js
734
+ import { weiToEther } from 'essential-eth';
735
+
736
+ // or in a require environment
737
+ const { weiToEther } = require('essential-eth');
738
+ ```
739
+
740
+ ```javascript
741
+ weiToEther('1000000000000000000000').toString();
742
+ // '1000'
743
+ weiToEther(1000000000000000000000).toString();
744
+ // '1000'
745
+ ```
746
+
747
+ ```javascript
748
+ weiToEther('1000000000000000000000').toNumber();
749
+ // 1000
750
+ weiToEther(1000000000000000000000).toNumber();
751
+ // 1000
752
+ ```
753
+
754
+ </details>
755
+
756
+ <br/>
757
+
758
+ #### [`zeroPad`](https://essential-eth.vercel.app/docs/api/modules#zeropad)
759
+
760
+ ```typescript
761
+ zeroPad(value: BytesLike, length: number): Uint8Array
762
+ ```
763
+
764
+ <br/>
765
+
766
+ <!-- โ›”๏ธ AUTO-GENERATED-CONTENT:END -->
767
+
768
+ - _The return-type `TinyBig` is just [`Big`](https://github.com/MikeMcl/big.js) but expands scientific notation on `toNumber()` and `toString()`_
244
769
 
770
+ <br/>
245
771
  <br/>
246
772
 
247
773
  ## RPC
@@ -251,10 +777,35 @@ import { JsonRpcProvider } from 'essential-eth';
251
777
  const essentialEth = new JsonRpcProvider(
252
778
  'RPC URL HERE' /* Try POKT or Infura */,
253
779
  );
254
- // OR for very quick testing (limited to 500 requests)
780
+ // OR for very quick testing (limited to 10,000 requests)
255
781
  const essentialEth = new JsonRpcProvider();
256
782
  ```
257
783
 
784
+ <details>
785
+ <summary>Want a redundant provider that handles outages?</summary>
786
+
787
+ ```typescript
788
+ import { FallthroughProvider } from 'essential-eth';
789
+
790
+ // The FallthroughProvider handles falling through to the next valid URL.
791
+ // It's dynamic to never trust one URL again when it fails * until it has tried all other provided URLs
792
+ // The default timeout for a request is 8 seconds after which it moves to the next URL
793
+ const provider = new FallthroughProvider([
794
+ 'https://bad.com',
795
+ 'https://free-eth-node.com/api/eth',
796
+ ]);
797
+ provider.getGasPrice().toNumber();
798
+ /*
799
+ 39695942769
800
+ */
801
+ ```
802
+
803
+ </details>
804
+
805
+ <br/>
806
+
807
+ #### [`getTransactionCount(address, blockTag?): Promise<number>`](https://essential-eth.vercel.app/docs/api/classes/JsonRpcProvider#gettransactioncount)
808
+
258
809
  #### `getGasPrice`
259
810
 
260
811
  Returns the current gas price in gwei
@@ -548,7 +1099,7 @@ await provider.getTransaction(
548
1099
 
549
1100
  โš ๏ธ Only read functions are currently supported. โš ๏ธ
550
1101
 
551
- - ๐Ÿงช This is **highly experimental**, do not use this in production yet. (even though [earni.fi](https://earni.fi) does)
1102
+ - ๐Ÿงช `Contract` support is **experimental**, do not use this in production yet. (even though [earni.fi](https://earni.fi) does)
552
1103
 
553
1104
  Encoding support:
554
1105
 
@@ -564,7 +1115,7 @@ Decoding support:
564
1115
  - `bytes32`
565
1116
  - `uint8`
566
1117
 
567
- _Assume any smart-contract method outside the above types will break_
1118
+ _Assume all types outside the above types will break for now_
568
1119
 
569
1120
  ```typescript
570
1121
  import { Contract, jsonRpcProvider, JSONABI } from 'essential-eth';
@@ -617,11 +1168,13 @@ Any function on a contract. Returns are the same as `ethers.js`, except that ins
617
1168
 
618
1169
  ๐Ÿงช This repo is under active development. The API is less-fully featured than `web3` and `ethers`. More functions added often!
619
1170
 
620
- ![](https://badgen.net/bundlephobia/minzip/essential-eth) ![](https://badgen.net/bundlephobia/tree-shaking/essential-eth) ![](https://img.shields.io/npm/v/essential-eth) ![](https://badgen.net/bundlephobia/dependency-count/essential-eth)
621
-
622
1171
  ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Breaking changes will exist between minor versions until `1.0.0` (Versions go `major.minor.patch`)
623
1172
 
624
1173
  <br/>
625
1174
 
1175
+ ![Alt](https://repobeats.axiom.co/api/embed/e479d8f777288a94cdde2fe3cdedf38d5243793d.svg 'Repobeats analytics image')
1176
+
1177
+ <br/>
1178
+
626
1179
  - [๐Ÿ““ View full docs](https://essential-eth.vercel.app)
627
1180
  - [๐Ÿ““ View changelog (by looking at releases diff)](https://github.com/dawsbot/essential-eth/releases)