essential-eth 0.5.4 โ 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.
- package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
- package/lib/cjs/index.d.ts +9 -5
- package/lib/cjs/index.js +10 -2
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +14 -0
- package/lib/cjs/providers/BaseProvider.js +19 -0
- package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
- package/lib/cjs/providers/utils/chains-info.d.ts +16 -0
- package/lib/cjs/providers/utils/chains-info.js +50 -2
- package/lib/cjs/utils/compute-address.d.ts +8 -0
- package/lib/cjs/utils/compute-address.js +24 -0
- package/lib/cjs/utils/compute-public-key.d.ts +9 -0
- package/lib/cjs/utils/compute-public-key.js +17 -0
- package/lib/cjs/utils/split-signature.d.ts +26 -0
- package/lib/cjs/utils/split-signature.js +165 -0
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/index.d.ts +9 -5
- package/lib/esm/index.js +7 -3
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +1 -0
- package/lib/esm/providers/BaseProvider.js +6 -0
- package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
- package/lib/esm/providers/utils/chains-info.d.ts +16 -0
- package/lib/esm/providers/utils/chains-info.js +50 -2
- package/lib/esm/utils/compute-address.d.ts +1 -0
- package/lib/esm/utils/compute-address.js +11 -0
- package/lib/esm/utils/compute-public-key.d.ts +2 -0
- package/lib/esm/utils/compute-public-key.js +6 -0
- package/lib/esm/utils/split-signature.d.ts +2 -0
- package/lib/esm/utils/split-signature.js +126 -0
- package/package.json +13 -10
- package/readme.md +615 -93
package/readme.md
CHANGED
|
@@ -8,12 +8,10 @@
|
|
|
8
8
|
๐ชถ Essential Eth ๐ชถ
|
|
9
9
|
</b>
|
|
10
10
|
<br/>
|
|
11
|
-
<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
|
+
[](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml) [](https://codecov.io/gh/Earnifi/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,27 +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
|
|
35
|
+
- โ
Node 18, 16, 14, & 12
|
|
36
36
|
- โ
Web
|
|
37
37
|
|
|
38
38
|
<br/>
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
## Table of Contents
|
|
41
41
|
|
|
42
|
-
|
|
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/>
|
|
43
95
|
|
|
44
96
|
## Install
|
|
45
97
|
|
|
46
98
|
```sh
|
|
47
99
|
npm install --save essential-eth # TypeScript types load automatically
|
|
48
100
|
|
|
49
|
-
# or
|
|
101
|
+
# or yarn
|
|
50
102
|
yarn add essential-eth # TypeScript types load automatically
|
|
51
103
|
```
|
|
52
104
|
|
|
53
105
|
<br/>
|
|
54
106
|
|
|
55
|
-
## Utils
|
|
107
|
+
## ๐ Utils
|
|
56
108
|
|
|
57
109
|
```typescript
|
|
58
110
|
import { etherToWei } from 'essential-eth';
|
|
@@ -61,191 +113,661 @@ import { etherToWei } from 'essential-eth';
|
|
|
61
113
|
const { etherToWei } = require('essential-eth');
|
|
62
114
|
```
|
|
63
115
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<br/>
|
|
116
|
+
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (FUNCTIONS) -->
|
|
67
117
|
|
|
68
|
-
#### `
|
|
118
|
+
#### [`arrayify`](https://essential-eth.vercel.app/docs/api/modules#arrayify)
|
|
69
119
|
|
|
70
120
|
```typescript
|
|
71
|
-
|
|
72
|
-
etherToWei(etherQuantity: string | number | TinyBig | Big): TinyBig
|
|
121
|
+
arrayify(value: number | BytesLike | Hexable, options: DataOptions): Uint8Array
|
|
73
122
|
```
|
|
74
123
|
|
|
75
|
-
<details>
|
|
124
|
+
<details>
|
|
76
125
|
<summary>View Example</summary>
|
|
77
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
|
+
|
|
78
155
|
```typescript
|
|
79
|
-
|
|
156
|
+
computeAddress(key: string): string
|
|
157
|
+
```
|
|
80
158
|
|
|
81
|
-
|
|
82
|
-
// "1000000000000000000"
|
|
159
|
+
<br/>
|
|
83
160
|
|
|
84
|
-
|
|
85
|
-
// 1000000000000000000
|
|
161
|
+
#### [`computePublicKey`](https://essential-eth.vercel.app/docs/api/modules#computepublickey)
|
|
86
162
|
|
|
87
|
-
|
|
88
|
-
|
|
163
|
+
```typescript
|
|
164
|
+
computePublicKey(privKey: BytesLike): string
|
|
89
165
|
```
|
|
90
166
|
|
|
91
|
-
|
|
167
|
+
<br/>
|
|
92
168
|
|
|
93
|
-
|
|
169
|
+
#### [`concat`](https://essential-eth.vercel.app/docs/api/modules#concat)
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
concat(arrayOfBytesLike: Array<BytesLikeWithNumber>): Uint8Array
|
|
173
|
+
```
|
|
94
174
|
|
|
95
|
-
|
|
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)
|
|
96
195
|
|
|
97
196
|
```typescript
|
|
98
|
-
|
|
99
|
-
weiToEther(weiQuantity: string | number | TinyBig | Big): TinyBig
|
|
197
|
+
etherToGwei(etherQuantity: string | number | TinyBig | Big): TinyBig
|
|
100
198
|
```
|
|
101
199
|
|
|
102
|
-
<details>
|
|
200
|
+
<details>
|
|
103
201
|
<summary>View Example</summary>
|
|
104
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
|
+
|
|
105
230
|
```typescript
|
|
106
|
-
|
|
231
|
+
etherToWei(etherQuantity: string | number | TinyBig | Big): TinyBig
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
<details>
|
|
235
|
+
<summary>View Example</summary>
|
|
107
236
|
|
|
108
|
-
|
|
109
|
-
|
|
237
|
+
```js
|
|
238
|
+
import { etherToWei } from 'essential-eth';
|
|
110
239
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
weiToEther('1000000000000000000').toNumber();
|
|
114
|
-
// 1
|
|
240
|
+
// or in a require environment
|
|
241
|
+
const { etherToWei } = require('essential-eth');
|
|
115
242
|
```
|
|
116
243
|
|
|
117
|
-
|
|
244
|
+
```javascript
|
|
245
|
+
etherToWei('1000').toString();
|
|
246
|
+
// '1000000000000000000000'
|
|
247
|
+
etherToWei(1000).toString();
|
|
248
|
+
// '1000000000000000000000'
|
|
249
|
+
```
|
|
118
250
|
|
|
119
|
-
|
|
251
|
+
```javascript
|
|
252
|
+
etherToWei('1000').toNumber();
|
|
253
|
+
// 1000000000000000000000
|
|
254
|
+
etherToWei(1000).toNumber();
|
|
255
|
+
// 1000000000000000000000
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
<br/>
|
|
120
261
|
|
|
121
|
-
#### `gweiToEther`
|
|
262
|
+
#### [`gweiToEther`](https://essential-eth.vercel.app/docs/api/modules#gweitoether)
|
|
122
263
|
|
|
123
264
|
```typescript
|
|
124
265
|
gweiToEther(gweiQuantity: string | number | TinyBig | Big): TinyBig
|
|
125
266
|
```
|
|
126
267
|
|
|
127
|
-
<details>
|
|
268
|
+
<details>
|
|
128
269
|
<summary>View Example</summary>
|
|
129
270
|
|
|
130
|
-
```
|
|
271
|
+
```js
|
|
131
272
|
import { gweiToEther } from 'essential-eth';
|
|
132
273
|
|
|
133
|
-
|
|
134
|
-
|
|
274
|
+
// or in a require environment
|
|
275
|
+
const { gweiToEther } = require('essential-eth');
|
|
276
|
+
```
|
|
135
277
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
278
|
+
```javascript
|
|
279
|
+
gweiToEther('1000000000000').toString();
|
|
280
|
+
// '1000'
|
|
281
|
+
gweiToEther(1000000000000).toString();
|
|
282
|
+
// '1000'
|
|
140
283
|
```
|
|
141
284
|
|
|
142
|
-
|
|
285
|
+
```javascript
|
|
286
|
+
gweiToEther('1000000000000').toNumber();
|
|
287
|
+
// 1000
|
|
288
|
+
gweiToEther(1000000000000).toNumber();
|
|
289
|
+
// 1000
|
|
290
|
+
```
|
|
143
291
|
|
|
144
|
-
|
|
292
|
+
</details>
|
|
293
|
+
|
|
294
|
+
<br/>
|
|
145
295
|
|
|
146
|
-
#### `
|
|
296
|
+
#### [`hashMessage`](https://essential-eth.vercel.app/docs/api/modules#hashmessage)
|
|
147
297
|
|
|
148
298
|
```typescript
|
|
149
|
-
|
|
299
|
+
hashMessage(message: string | Bytes): string
|
|
150
300
|
```
|
|
151
301
|
|
|
152
|
-
<details>
|
|
302
|
+
<details>
|
|
153
303
|
<summary>View Example</summary>
|
|
154
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
|
+
|
|
155
323
|
```typescript
|
|
156
|
-
|
|
324
|
+
hexConcat(items: Array<BytesLike>): string
|
|
325
|
+
```
|
|
157
326
|
|
|
158
|
-
|
|
159
|
-
|
|
327
|
+
<br/>
|
|
328
|
+
|
|
329
|
+
#### [`hexDataLength`](https://essential-eth.vercel.app/docs/api/modules#hexdatalength)
|
|
160
330
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
etherToGwei('0.000000001').toNumber();
|
|
164
|
-
// 1
|
|
331
|
+
```typescript
|
|
332
|
+
hexDataLength(data: BytesLike): null | number
|
|
165
333
|
```
|
|
166
334
|
|
|
167
|
-
|
|
335
|
+
<br/>
|
|
168
336
|
|
|
169
|
-
|
|
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/>
|
|
170
344
|
|
|
171
|
-
#### `
|
|
345
|
+
#### [`hexStripZeros`](https://essential-eth.vercel.app/docs/api/modules#hexstripzeros)
|
|
172
346
|
|
|
173
347
|
```typescript
|
|
174
|
-
|
|
175
|
-
// does not support ICAP addresses
|
|
176
|
-
toChecksumAddress(address: string): string
|
|
348
|
+
hexStripZeros(value: BytesLike): string
|
|
177
349
|
```
|
|
178
350
|
|
|
179
|
-
<
|
|
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>
|
|
180
368
|
<summary>View Example</summary>
|
|
181
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
|
+
|
|
182
398
|
```typescript
|
|
183
|
-
|
|
399
|
+
hexlify(value: number | bigint | BytesLike | Hexable, options: DataOptions): string
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
<details>
|
|
403
|
+
<summary>View Example</summary>
|
|
184
404
|
|
|
185
|
-
|
|
186
|
-
|
|
405
|
+
```js
|
|
406
|
+
import { hexlify } from 'essential-eth';
|
|
407
|
+
|
|
408
|
+
// or in a require environment
|
|
409
|
+
const { hexlify } = require('essential-eth');
|
|
187
410
|
```
|
|
188
411
|
|
|
189
|
-
|
|
412
|
+
```js
|
|
413
|
+
hexlify(4);
|
|
414
|
+
// '0x04'
|
|
190
415
|
|
|
191
|
-
|
|
416
|
+
hexlify(14);
|
|
417
|
+
// '0x0e'
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
</details>
|
|
192
421
|
|
|
193
|
-
|
|
422
|
+
<br/>
|
|
423
|
+
|
|
424
|
+
#### [`isAddress`](https://essential-eth.vercel.app/docs/api/modules#isaddress)
|
|
194
425
|
|
|
195
426
|
```typescript
|
|
196
|
-
// returns boolean as to whether input is a valid address
|
|
197
|
-
// does not support ENS nor ICAP
|
|
198
427
|
isAddress(address: string): boolean
|
|
199
428
|
```
|
|
200
429
|
|
|
201
|
-
<details>
|
|
430
|
+
<details>
|
|
202
431
|
<summary>View Example</summary>
|
|
203
432
|
|
|
204
|
-
```
|
|
433
|
+
```js
|
|
205
434
|
import { isAddress } from 'essential-eth';
|
|
206
435
|
|
|
436
|
+
// or in a require environment
|
|
437
|
+
const { isAddress } = require('essential-eth');
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
```javascript
|
|
207
441
|
isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
|
|
208
442
|
// true
|
|
443
|
+
```
|
|
209
444
|
|
|
445
|
+
```javascript
|
|
210
446
|
isAddress('bad');
|
|
211
447
|
// false
|
|
448
|
+
```
|
|
212
449
|
|
|
450
|
+
```javascript
|
|
213
451
|
// Does NOT support ENS.
|
|
214
452
|
isAddress('vitalik.eth');
|
|
215
453
|
// false
|
|
216
454
|
```
|
|
217
455
|
|
|
218
|
-
</details>
|
|
456
|
+
</details>
|
|
219
457
|
|
|
220
|
-
<br/>
|
|
458
|
+
<br/>
|
|
221
459
|
|
|
222
|
-
#### `
|
|
460
|
+
#### [`isBytes`](https://essential-eth.vercel.app/docs/api/modules#isbytes)
|
|
223
461
|
|
|
224
462
|
```typescript
|
|
225
|
-
|
|
226
|
-
// if the hex value provided is already longer than the padding value, the value itself is returned without alteration
|
|
227
|
-
hexZeroPad(hexValue: string | number, length: number): string
|
|
463
|
+
isBytes(value: any): value
|
|
228
464
|
```
|
|
229
465
|
|
|
230
|
-
<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>
|
|
231
502
|
<summary>View Example</summary>
|
|
232
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
|
+
|
|
233
532
|
```typescript
|
|
234
|
-
|
|
533
|
+
isHexString(value: any, length: number): boolean
|
|
534
|
+
```
|
|
235
535
|
|
|
236
|
-
|
|
237
|
-
// '0x0060'
|
|
536
|
+
<br/>
|
|
238
537
|
|
|
239
|
-
|
|
240
|
-
// '0x000060'
|
|
538
|
+
#### [`jsonRpcProvider`](https://essential-eth.vercel.app/docs/api/modules#jsonrpcprovider)
|
|
241
539
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// Throws error
|
|
540
|
+
```typescript
|
|
541
|
+
jsonRpcProvider(rpcUrl: string): JsonRpcProvider
|
|
245
542
|
```
|
|
246
543
|
|
|
247
|
-
|
|
544
|
+
<details>
|
|
545
|
+
<summary>View Example</summary>
|
|
546
|
+
|
|
547
|
+
```js
|
|
548
|
+
import { jsonRpcProvider } from 'essential-eth';
|
|
549
|
+
|
|
550
|
+
// or in a require environment
|
|
551
|
+
const { jsonRpcProvider } = require('essential-eth');
|
|
552
|
+
```
|
|
553
|
+
|
|
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/>
|
|
248
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()`_
|
|
769
|
+
|
|
770
|
+
<br/>
|
|
249
771
|
<br/>
|
|
250
772
|
|
|
251
773
|
## RPC
|
|
@@ -577,7 +1099,7 @@ await provider.getTransaction(
|
|
|
577
1099
|
|
|
578
1100
|
โ ๏ธ Only read functions are currently supported. โ ๏ธ
|
|
579
1101
|
|
|
580
|
-
- ๐งช
|
|
1102
|
+
- ๐งช `Contract` support is **experimental**, do not use this in production yet. (even though [earni.fi](https://earni.fi) does)
|
|
581
1103
|
|
|
582
1104
|
Encoding support:
|
|
583
1105
|
|
|
@@ -593,7 +1115,7 @@ Decoding support:
|
|
|
593
1115
|
- `bytes32`
|
|
594
1116
|
- `uint8`
|
|
595
1117
|
|
|
596
|
-
_Assume
|
|
1118
|
+
_Assume all types outside the above types will break for now_
|
|
597
1119
|
|
|
598
1120
|
```typescript
|
|
599
1121
|
import { Contract, jsonRpcProvider, JSONABI } from 'essential-eth';
|