essential-eth 0.11.2 โ 1.0.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.
- package/dist/chunk-CLIQ4S3P.js +780 -0
- package/dist/chunk-GFWRB7PT.js +96 -0
- package/dist/conversions.d.ts +9 -0
- package/dist/conversions.js +1 -0
- package/dist/index-utils-e8a8adc8.d.ts +63 -0
- package/dist/index.cjs +419 -286
- package/dist/index.d.ts +60 -101
- package/dist/index.js +239 -1046
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +2 -0
- package/package.json +14 -7
- package/readme.md +750 -449
- package/dist/index.d.cts +0 -330
package/readme.md
CHANGED
|
@@ -20,6 +20,25 @@
|
|
|
20
20
|
<img src="https://user-images.githubusercontent.com/3408480/133322814-f3d18424-4ba8-4a37-8cbc-c5e6828354a3.png" title="Import size comparison" width="900"/>
|
|
21
21
|
</p>
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
<!-- BUNDLE-SIZE-TABLE:START -->
|
|
25
|
+
|
|
26
|
+
### Bundle Size Comparison (ESM, minified)
|
|
27
|
+
|
|
28
|
+
Measured with esbuild. Smaller is better.
|
|
29
|
+
|
|
30
|
+
| What you import | essential-eth@1.0.0 | ethers@6.16.0 | viem@2.45.1 | web3@4.16.0 | ox@0.12.0 |
|
|
31
|
+
| ---------------------------------------- | :-----------------: | :-----------: | :---------: | :---------: | :------------: |
|
|
32
|
+
| **Full library** | **42.2 kB** ๐ | 394.0 kB | 348.3 kB | 495.8 kB | 612.8 kB |
|
|
33
|
+
| **Provider** (getBalance, getBlock, etc) | 29.9 kB | 260.0 kB | 269.5 kB | 454.5 kB | **10.9 kB** ๐ |
|
|
34
|
+
| **Contract** (read-only calls) | **24.8 kB** ๐ | 86.6 kB | 179.8 kB | 264.9 kB | 49.9 kB |
|
|
35
|
+
| **Conversions** (wei, gwei, ether) | **1.2 kB** ๐ | 10.4 kB | 2.7 kB | 454.5 kB | 3.7 kB |
|
|
36
|
+
|
|
37
|
+
essential-eth is **8x smaller** than the nearest alternative for full-library usage.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<!-- BUNDLE-SIZE-TABLE:END -->
|
|
41
|
+
|
|
23
42
|
---
|
|
24
43
|
|
|
25
44
|
[](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml) [](https://codecov.io/gh/Earnifi/essential-eth)   
|
|
@@ -45,61 +64,88 @@
|
|
|
45
64
|
|
|
46
65
|
<br/>
|
|
47
66
|
|
|
67
|
+
## Who Is This For?
|
|
68
|
+
|
|
69
|
+
Essential-eth is built for developers where size and speed matter. Check out dedicated guides for your use case:
|
|
70
|
+
|
|
71
|
+
- **[Chrome Extension Developers](https://github.com/dawsbot/essential-eth/blob/master/static/landing/chrome-extensions.md)** โ Service worker size budgets are brutal. 39.9 kB vs ethers' 394 kB makes a real difference.
|
|
72
|
+
- **[Serverless & Edge Functions](https://github.com/dawsbot/essential-eth/blob/master/static/landing/serverless.md)** โ Cold starts cost money. Get sub-10ms startup instead of 200ms+.
|
|
73
|
+
- **[React Native Apps](https://github.com/dawsbot/essential-eth/blob/master/static/landing/react-native.md)** โ Every KB impacts app store download times. Essential-eth adds 12 kB, ethers adds 104 kB.
|
|
74
|
+
- **[Telegram/Discord Bots](https://github.com/dawsbot/essential-eth/blob/master/static/landing/telegram-bots.md)** โ Minimal memory footprint, instant response times. 2 MB vs 45 MB for ethers.
|
|
75
|
+
|
|
76
|
+
<br/>
|
|
77
|
+
|
|
48
78
|
## Table of Contents
|
|
49
79
|
|
|
80
|
+
|
|
50
81
|
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click to expand) -->
|
|
51
82
|
<details>
|
|
52
83
|
<summary>Click to expand</summary>
|
|
53
84
|
|
|
54
85
|
- [Why you should replace Ethers.js and web3](#why-you-should-replace-ethersjs-and-web3)
|
|
86
|
+
- [Bundle Size Comparison (ESM, minified)](#bundle-size-comparison-esm-minified)
|
|
87
|
+
- [Who Is This For?](#who-is-this-for)
|
|
55
88
|
- [Install](#install)
|
|
56
89
|
- [๐ Utils](#-utils)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
- [`arrayify`](#arrayify)
|
|
91
|
+
- [`computeAddress`](#computeaddress)
|
|
92
|
+
- [`computePublicKey`](#computepublickey)
|
|
93
|
+
- [`concat`](#concat)
|
|
94
|
+
- [`decodeBytes32String`](#decodebytes32string)
|
|
95
|
+
- [`decodeEventLog`](#decodeeventlog)
|
|
96
|
+
- [`decodeFunctionResult`](#decodefunctionresult)
|
|
97
|
+
- [`encodeBytes32String`](#encodebytes32string)
|
|
98
|
+
- [`encodeFunctionData`](#encodefunctiondata)
|
|
99
|
+
- [`etherToGwei`](#ethertogwei)
|
|
100
|
+
- [`etherToWei`](#ethertowei)
|
|
101
|
+
- [`formatUnits`](#formatunits)
|
|
102
|
+
- [`getAddress`](#getaddress)
|
|
103
|
+
- [`getEventSignature`](#geteventsignature)
|
|
104
|
+
- [`getEventTopic`](#geteventtopic)
|
|
105
|
+
- [`gweiToEther`](#gweitoether)
|
|
106
|
+
- [`hashMessage`](#hashmessage)
|
|
107
|
+
- [`hexConcat`](#hexconcat)
|
|
108
|
+
- [`hexDataLength`](#hexdatalength)
|
|
109
|
+
- [`hexDataSlice`](#hexdataslice)
|
|
110
|
+
- [`hexStripZeros`](#hexstripzeros)
|
|
111
|
+
- [`hexValue`](#hexvalue)
|
|
112
|
+
- [`hexZeroPad`](#hexzeropad)
|
|
113
|
+
- [`hexlify`](#hexlify)
|
|
114
|
+
- [`id`](#id)
|
|
115
|
+
- [`isAddress`](#isaddress)
|
|
116
|
+
- [`isBytes`](#isbytes)
|
|
117
|
+
- [`isBytesLike`](#isbyteslike)
|
|
118
|
+
- [`isHexString`](#ishexstring)
|
|
119
|
+
- [`jsonRpcProvider`](#jsonrpcprovider)
|
|
120
|
+
- [`keccak256`](#keccak256)
|
|
121
|
+
- [`namehash`](#namehash)
|
|
122
|
+
- [`pack`](#pack)
|
|
123
|
+
- [`parseUnits`](#parseunits)
|
|
124
|
+
- [`solidityKeccak256`](#soliditykeccak256)
|
|
125
|
+
- [`splitSignature`](#splitsignature)
|
|
126
|
+
- [`stripZeros`](#stripzeros)
|
|
127
|
+
- [`toChecksumAddress`](#tochecksumaddress)
|
|
128
|
+
- [`toUtf8Bytes`](#toutf8bytes)
|
|
129
|
+
- [`toUtf8String`](#toutf8string)
|
|
130
|
+
- [`weiToEther`](#weitoether)
|
|
131
|
+
- [`zeroPad`](#zeropad)
|
|
87
132
|
- [Providers](#providers)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
133
|
+
- [`call`](#call)
|
|
134
|
+
- [`estimateGas`](#estimategas)
|
|
135
|
+
- [`getBalance`](#getbalance)
|
|
136
|
+
- [`getBlock`](#getblock)
|
|
137
|
+
- [`getBlockNumber`](#getblocknumber)
|
|
138
|
+
- [`getCode`](#getcode)
|
|
139
|
+
- [`getFeeData`](#getfeedata)
|
|
140
|
+
- [`getGasPrice`](#getgasprice)
|
|
141
|
+
- [`getLogs`](#getlogs)
|
|
142
|
+
- [`getNetwork`](#getnetwork)
|
|
143
|
+
- [`getTransaction`](#gettransaction)
|
|
144
|
+
- [`getTransactionCount`](#gettransactioncount)
|
|
145
|
+
- [`getTransactionReceipt`](#gettransactionreceipt)
|
|
146
|
+
- [`resolveName`](#resolvename)
|
|
101
147
|
- [Contract](#contract)
|
|
102
|
-
|
|
148
|
+
- [`contractFunctionName(args)`](#contractfunctionnameargs)
|
|
103
149
|
- [More Info](#more-info)
|
|
104
150
|
- [Identical vs Similar vs Dissimilar {#isd}](#identical-vs-similar-vs-dissimilar-isd)
|
|
105
151
|
- [Miscellaneous](#miscellaneous)
|
|
@@ -122,12 +168,15 @@ yarn add essential-eth # TypeScript included
|
|
|
122
168
|
|
|
123
169
|
Browsers:
|
|
124
170
|
|
|
171
|
+
|
|
125
172
|
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (UNPKG_SCRIPT_TAG) -->
|
|
126
173
|
|
|
127
174
|
```html
|
|
175
|
+
|
|
128
176
|
<!-- index.html -->
|
|
129
|
-
<script src="https://unpkg.com/essential-eth@0.
|
|
177
|
+
<script src="https://unpkg.com/essential-eth@1.0.0"></script>
|
|
130
178
|
```
|
|
179
|
+
|
|
131
180
|
|
|
132
181
|
<!-- โ๏ธ AUTO-GENERATED-CONTENT:END (UNPKG_SCRIPT_TAG) -->
|
|
133
182
|
|
|
@@ -142,33 +191,29 @@ import { etherToWei } from 'essential-eth';
|
|
|
142
191
|
const { etherToWei } = require('essential-eth');
|
|
143
192
|
```
|
|
144
193
|
|
|
145
|
-
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (FUNCTIONS) -->
|
|
146
194
|
|
|
195
|
+
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (FUNCTIONS) -->
|
|
147
196
|
#### [`arrayify`](https://eeth.dev/docs/api/modules#arrayify)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
|
|
197
|
+

|
|
198
|
+
```typescript
|
|
199
|
+
arrayify(value: number | bigint | BytesLike | Hexable, options: DataOptions): Uint8Array
|
|
200
|
+
```
|
|
201
|
+
|
|
155
202
|
<details>
|
|
156
203
|
<summary>View Example</summary>
|
|
157
204
|
|
|
158
|
-
```js
|
|
159
|
-
import { arrayify } from 'essential-eth';
|
|
160
|
-
```
|
|
205
|
+
```js
|
|
206
|
+
import { arrayify } from 'essential-eth';
|
|
207
|
+
```
|
|
161
208
|
|
|
162
|
-
```javascript
|
|
209
|
+
```javascript
|
|
163
210
|
arrayify(1);
|
|
164
211
|
// Uint8Array(1) [ 1 ]
|
|
165
212
|
```
|
|
166
|
-
|
|
167
213
|
```javascript
|
|
168
214
|
arrayify(0x1234);
|
|
169
215
|
// Uint8Array(2) [ 18, 52 ]
|
|
170
216
|
```
|
|
171
|
-
|
|
172
217
|
```javascript
|
|
173
218
|
arrayify('0x1', { hexPad: 'right' });
|
|
174
219
|
// Uint8Array(1) [ 16 ]
|
|
@@ -179,31 +224,24 @@ arrayify('0x1', { hexPad: 'right' });
|
|
|
179
224
|
<br/>
|
|
180
225
|
|
|
181
226
|
#### [`computeAddress`](https://eeth.dev/docs/api/modules#computeaddress)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
```
|
|
188
|
-
|
|
227
|
+

|
|
228
|
+
```typescript
|
|
229
|
+
computeAddress(key: string): string
|
|
230
|
+
```
|
|
231
|
+
|
|
189
232
|
<details>
|
|
190
233
|
<summary>View Example</summary>
|
|
191
234
|
|
|
192
|
-
```js
|
|
193
|
-
import { computeAddress } from 'essential-eth';
|
|
194
|
-
```
|
|
235
|
+
```js
|
|
236
|
+
import { computeAddress } from 'essential-eth';
|
|
237
|
+
```
|
|
195
238
|
|
|
196
|
-
```javascript
|
|
197
|
-
computeAddress(
|
|
198
|
-
'0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952',
|
|
199
|
-
); // public key
|
|
239
|
+
```javascript
|
|
240
|
+
computeAddress('0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952'); // public key
|
|
200
241
|
// '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
201
242
|
```
|
|
202
|
-
|
|
203
243
|
```javascript
|
|
204
|
-
computeAddress(
|
|
205
|
-
'0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427',
|
|
206
|
-
); // private key
|
|
244
|
+
computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
|
|
207
245
|
// '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
208
246
|
```
|
|
209
247
|
|
|
@@ -212,32 +250,24 @@ computeAddress(
|
|
|
212
250
|
<br/>
|
|
213
251
|
|
|
214
252
|
#### [`computePublicKey`](https://eeth.dev/docs/api/modules#computepublickey)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
```
|
|
221
|
-
|
|
253
|
+

|
|
254
|
+
```typescript
|
|
255
|
+
computePublicKey(privKey: BytesLike): string
|
|
256
|
+
```
|
|
257
|
+
|
|
222
258
|
<details>
|
|
223
259
|
<summary>View Example</summary>
|
|
224
260
|
|
|
225
|
-
```js
|
|
226
|
-
import { computePublicKey } from 'essential-eth';
|
|
227
|
-
```
|
|
261
|
+
```js
|
|
262
|
+
import { computePublicKey } from 'essential-eth';
|
|
263
|
+
```
|
|
228
264
|
|
|
229
|
-
```javascript
|
|
230
|
-
computePublicKey(
|
|
231
|
-
'0xb27cc8dea0177d910110e8d3ec5480d56c723abf433529f4063f261ffdb9297c',
|
|
232
|
-
);
|
|
265
|
+
```javascript
|
|
266
|
+
computePublicKey('0xb27cc8dea0177d910110e8d3ec5480d56c723abf433529f4063f261ffdb9297c');
|
|
233
267
|
// '0x045cd0032015eecfde49f82f4e149d804e8ac6e3a0bface32e37c72a71ceac864fe84da7e8df84342f7b11dfb753c4d158f636142b46b29cf7f0f171ae0aa4fb87'
|
|
234
268
|
```
|
|
235
|
-
|
|
236
269
|
```javascript
|
|
237
|
-
computePublicKey([
|
|
238
|
-
50, 102, 50, 99, 52, 49, 57, 97, 99, 102, 52, 97, 49, 100, 97, 56, 99, 49,
|
|
239
|
-
101, 98, 101, 97, 55, 53, 98, 98, 51, 102, 99, 102, 98, 100,
|
|
240
|
-
]);
|
|
270
|
+
computePublicKey([50,102,50,99,52,49,57,97,99,102,52,97,49,100,97,56,99,49,101,98,101,97,55,53,98,98,51,102,99,102,98,100]);
|
|
241
271
|
// '0x04a9cea77eca949df84f661cee153426fb51f2294b9364b4fac240df57360b9b0ac9c99e4d7966491ab4c81f8c82e0cd24ec5759832ad4ab736d22c7d90b806ee8'
|
|
242
272
|
```
|
|
243
273
|
|
|
@@ -246,196 +276,407 @@ computePublicKey([
|
|
|
246
276
|
<br/>
|
|
247
277
|
|
|
248
278
|
#### [`concat`](https://eeth.dev/docs/api/modules#concat)
|
|
279
|
+

|
|
280
|
+
```typescript
|
|
281
|
+
concat(arrayOfBytesLike: Array<BytesLikeWithNumber>): Uint8Array
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
<details>
|
|
285
|
+
<summary>View Example</summary>
|
|
249
286
|
|
|
250
|
-
|
|
287
|
+
```js
|
|
288
|
+
import { concat } from 'essential-eth';
|
|
289
|
+
```
|
|
251
290
|
|
|
252
|
-
```
|
|
253
|
-
concat(
|
|
291
|
+
```javascript
|
|
292
|
+
concat([0, 1]);
|
|
293
|
+
// Uint8Array(2) [ 0, 1 ]
|
|
254
294
|
```
|
|
255
295
|
|
|
296
|
+
</details>
|
|
297
|
+
|
|
298
|
+
<br/>
|
|
299
|
+
|
|
300
|
+
#### [`decodeBytes32String`](https://eeth.dev/docs/api/modules#decodebytes32string)
|
|
301
|
+

|
|
302
|
+
```typescript
|
|
303
|
+
decodeBytes32String(bytes32: string): string
|
|
304
|
+
```
|
|
305
|
+
|
|
256
306
|
<details>
|
|
257
307
|
<summary>View Example</summary>
|
|
258
308
|
|
|
259
|
-
```js
|
|
260
|
-
import {
|
|
261
|
-
```
|
|
309
|
+
```js
|
|
310
|
+
import { decodeBytes32String } from 'essential-eth';
|
|
311
|
+
```
|
|
262
312
|
|
|
263
|
-
```javascript
|
|
264
|
-
|
|
265
|
-
//
|
|
313
|
+
```javascript
|
|
314
|
+
decodeBytes32String('0x657373656e7469616c2d657468000000000000000000000000000000000000')
|
|
315
|
+
// 'essential-eth'
|
|
266
316
|
```
|
|
267
317
|
|
|
268
318
|
</details>
|
|
269
319
|
|
|
270
320
|
<br/>
|
|
271
321
|
|
|
272
|
-
#### [`
|
|
322
|
+
#### [`decodeEventLog`](https://eeth.dev/docs/api/modules#decodeeventlog)
|
|
323
|
+

|
|
324
|
+
```typescript
|
|
325
|
+
decodeEventLog(abi: JSONABI, log: undefined): undefined
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
<details>
|
|
329
|
+
<summary>View Example</summary>
|
|
273
330
|
|
|
274
|
-
|
|
331
|
+
```js
|
|
332
|
+
import { decodeEventLog } from 'essential-eth';
|
|
333
|
+
```
|
|
275
334
|
|
|
276
|
-
```
|
|
277
|
-
|
|
335
|
+
```javascript
|
|
336
|
+
const result = decodeEventLog(erc20ABI, {
|
|
337
|
+
topics: [
|
|
338
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
339
|
+
'0x000000000000000000000000abc0000000000000000000000000000000000001',
|
|
340
|
+
'0x000000000000000000000000abc0000000000000000000000000000000000002',
|
|
341
|
+
],
|
|
342
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000064',
|
|
343
|
+
});
|
|
344
|
+
// { eventName: 'Transfer', args: { from: '0xABC0...0001', to: '0xaBc0...0002', value: 100n } }
|
|
278
345
|
```
|
|
279
346
|
|
|
347
|
+
</details>
|
|
348
|
+
|
|
349
|
+
<br/>
|
|
350
|
+
|
|
351
|
+
#### [`decodeFunctionResult`](https://eeth.dev/docs/api/modules#decodefunctionresult)
|
|
352
|
+

|
|
353
|
+
```typescript
|
|
354
|
+
decodeFunctionResult(abi: JSONABI, functionName: string, data: string): any
|
|
355
|
+
```
|
|
356
|
+
|
|
280
357
|
<details>
|
|
281
358
|
<summary>View Example</summary>
|
|
282
359
|
|
|
283
|
-
```js
|
|
284
|
-
import {
|
|
285
|
-
```
|
|
360
|
+
```js
|
|
361
|
+
import { decodeFunctionResult } from 'essential-eth';
|
|
362
|
+
```
|
|
286
363
|
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
// '1000000000000'
|
|
290
|
-
etherToGwei(1000).toString();
|
|
291
|
-
// '1000000000000'
|
|
292
|
-
```
|
|
364
|
+
```typescript
|
|
365
|
+
import { decodeFunctionResult } from 'essential-eth';
|
|
293
366
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
367
|
+
const abi = [
|
|
368
|
+
{
|
|
369
|
+
name: 'balanceOf',
|
|
370
|
+
type: 'function',
|
|
371
|
+
inputs: [{ name: 'owner', type: 'address' }],
|
|
372
|
+
outputs: [{ name: 'balance', type: 'uint256' }],
|
|
373
|
+
},
|
|
374
|
+
];
|
|
375
|
+
|
|
376
|
+
const result = decodeFunctionResult(abi, 'balanceOf', '0x000...0001');
|
|
377
|
+
// result === 1n
|
|
299
378
|
```
|
|
300
379
|
|
|
301
380
|
</details>
|
|
302
381
|
|
|
303
382
|
<br/>
|
|
304
383
|
|
|
305
|
-
#### [`
|
|
384
|
+
#### [`encodeBytes32String`](https://eeth.dev/docs/api/modules#encodebytes32string)
|
|
385
|
+

|
|
386
|
+
```typescript
|
|
387
|
+
encodeBytes32String(text: string): string
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
<details>
|
|
391
|
+
<summary>View Example</summary>
|
|
306
392
|
|
|
307
|
-
|
|
393
|
+
```js
|
|
394
|
+
import { encodeBytes32String } from 'essential-eth';
|
|
395
|
+
```
|
|
308
396
|
|
|
309
|
-
```
|
|
310
|
-
|
|
397
|
+
```javascript
|
|
398
|
+
encodeBytes32String('essential-eth')
|
|
399
|
+
// '0x657373656e7469616c2d657468000000000000000000000000000000000000'
|
|
311
400
|
```
|
|
312
401
|
|
|
402
|
+
</details>
|
|
403
|
+
|
|
404
|
+
<br/>
|
|
405
|
+
|
|
406
|
+
#### [`encodeFunctionData`](https://eeth.dev/docs/api/modules#encodefunctiondata)
|
|
407
|
+

|
|
408
|
+
```typescript
|
|
409
|
+
encodeFunctionData(abi: JSONABI, functionName: string, args?: undefined): string
|
|
410
|
+
```
|
|
411
|
+
|
|
313
412
|
<details>
|
|
314
413
|
<summary>View Example</summary>
|
|
315
414
|
|
|
316
|
-
```js
|
|
317
|
-
import {
|
|
318
|
-
```
|
|
415
|
+
```js
|
|
416
|
+
import { encodeFunctionData } from 'essential-eth';
|
|
417
|
+
```
|
|
319
418
|
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
// '1000000000000000000000'
|
|
323
|
-
etherToWei(1000).toString();
|
|
324
|
-
// '1000000000000000000000'
|
|
325
|
-
```
|
|
419
|
+
```typescript
|
|
420
|
+
import { encodeFunctionData } from 'essential-eth';
|
|
326
421
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
422
|
+
const abi = [
|
|
423
|
+
{
|
|
424
|
+
name: 'balanceOf',
|
|
425
|
+
type: 'function',
|
|
426
|
+
inputs: [{ name: 'owner', type: 'address' }],
|
|
427
|
+
outputs: [{ name: 'balance', type: 'uint256' }],
|
|
428
|
+
},
|
|
429
|
+
];
|
|
430
|
+
|
|
431
|
+
const data = encodeFunctionData(abi, 'balanceOf', [
|
|
432
|
+
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
433
|
+
]);
|
|
332
434
|
```
|
|
333
435
|
|
|
334
436
|
</details>
|
|
335
437
|
|
|
336
438
|
<br/>
|
|
337
439
|
|
|
338
|
-
#### [`
|
|
440
|
+
#### [`etherToGwei`](https://eeth.dev/docs/api/modules#ethertogwei)
|
|
441
|
+

|
|
442
|
+
```typescript
|
|
443
|
+
etherToGwei(etherQuantity: string | number | bigint): bigint
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
<details>
|
|
447
|
+
<summary>View Example</summary>
|
|
339
448
|
|
|
340
|
-
|
|
449
|
+
```js
|
|
450
|
+
import { etherToGwei } from 'essential-eth';
|
|
451
|
+
```
|
|
341
452
|
|
|
342
|
-
```
|
|
343
|
-
|
|
453
|
+
```javascript
|
|
454
|
+
etherToGwei('1000').toString()
|
|
455
|
+
// '1000000000000'
|
|
456
|
+
etherToGwei(1000).toString()
|
|
457
|
+
// '1000000000000'
|
|
344
458
|
```
|
|
345
459
|
|
|
460
|
+
</details>
|
|
461
|
+
|
|
462
|
+
<br/>
|
|
463
|
+
|
|
464
|
+
#### [`etherToWei`](https://eeth.dev/docs/api/modules#ethertowei)
|
|
465
|
+

|
|
466
|
+
```typescript
|
|
467
|
+
etherToWei(etherQuantity: string | number | bigint): bigint
|
|
468
|
+
```
|
|
469
|
+
|
|
346
470
|
<details>
|
|
347
471
|
<summary>View Example</summary>
|
|
348
472
|
|
|
349
|
-
```js
|
|
350
|
-
import {
|
|
473
|
+
```js
|
|
474
|
+
import { etherToWei } from 'essential-eth';
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
```javascript
|
|
478
|
+
etherToWei('1000').toString()
|
|
479
|
+
// '1000000000000000000000'
|
|
480
|
+
etherToWei(1000).toString()
|
|
481
|
+
// '1000000000000000000000'
|
|
351
482
|
```
|
|
352
483
|
|
|
484
|
+
</details>
|
|
485
|
+
|
|
486
|
+
<br/>
|
|
487
|
+
|
|
488
|
+
#### [`formatUnits`](https://eeth.dev/docs/api/modules#formatunits)
|
|
489
|
+

|
|
490
|
+
```typescript
|
|
491
|
+
formatUnits(value: string | number | bigint, decimals?: number): string
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
<details>
|
|
495
|
+
<summary>View Example</summary>
|
|
496
|
+
|
|
497
|
+
```js
|
|
498
|
+
import { formatUnits } from 'essential-eth';
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
```javascript
|
|
502
|
+
formatUnits(1000000n, 6)
|
|
503
|
+
// '1'
|
|
504
|
+
```
|
|
353
505
|
```javascript
|
|
354
|
-
|
|
355
|
-
// '
|
|
356
|
-
gweiToEther(1000000000000).toString();
|
|
357
|
-
// '1000'
|
|
506
|
+
formatUnits('1000000000000000000', 18)
|
|
507
|
+
// '1'
|
|
358
508
|
```
|
|
359
|
-
|
|
360
509
|
```javascript
|
|
361
|
-
|
|
362
|
-
//
|
|
363
|
-
gweiToEther(1000000000000).toNumber();
|
|
364
|
-
// 1000
|
|
510
|
+
formatUnits(1500000n, 6)
|
|
511
|
+
// '1.5'
|
|
365
512
|
```
|
|
366
513
|
|
|
367
514
|
</details>
|
|
368
515
|
|
|
369
516
|
<br/>
|
|
370
517
|
|
|
371
|
-
#### [`
|
|
518
|
+
#### [`getAddress`](https://eeth.dev/docs/api/modules#getaddress)
|
|
519
|
+

|
|
520
|
+
```typescript
|
|
521
|
+
getAddress(address: string): string
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
<details>
|
|
525
|
+
<summary>View Example</summary>
|
|
372
526
|
|
|
373
|
-
|
|
527
|
+
```js
|
|
528
|
+
import { getAddress } from 'essential-eth';
|
|
529
|
+
```
|
|
374
530
|
|
|
375
|
-
```
|
|
376
|
-
|
|
531
|
+
```javascript
|
|
532
|
+
getAddress('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
|
|
533
|
+
// '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
|
|
377
534
|
```
|
|
378
535
|
|
|
536
|
+
</details>
|
|
537
|
+
|
|
538
|
+
<br/>
|
|
539
|
+
|
|
540
|
+
#### [`getEventSignature`](https://eeth.dev/docs/api/modules#geteventsignature)
|
|
541
|
+

|
|
542
|
+
```typescript
|
|
543
|
+
getEventSignature(abi: JSONABI, eventName: string): string
|
|
544
|
+
```
|
|
545
|
+
|
|
379
546
|
<details>
|
|
380
547
|
<summary>View Example</summary>
|
|
381
548
|
|
|
382
|
-
```js
|
|
383
|
-
import {
|
|
384
|
-
```
|
|
549
|
+
```js
|
|
550
|
+
import { getEventSignature } from 'essential-eth';
|
|
551
|
+
```
|
|
385
552
|
|
|
386
|
-
```javascript
|
|
387
|
-
|
|
388
|
-
|
|
553
|
+
```javascript
|
|
554
|
+
const abi = [
|
|
555
|
+
{
|
|
556
|
+
type: 'event',
|
|
557
|
+
name: 'Transfer',
|
|
558
|
+
inputs: [
|
|
559
|
+
{ name: 'from', type: 'address', indexed: true },
|
|
560
|
+
{ name: 'to', type: 'address', indexed: true },
|
|
561
|
+
{ name: 'value', type: 'uint256', indexed: false },
|
|
562
|
+
],
|
|
563
|
+
},
|
|
564
|
+
];
|
|
565
|
+
getEventSignature(abi, 'Transfer');
|
|
566
|
+
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
389
567
|
```
|
|
390
568
|
|
|
391
569
|
</details>
|
|
392
570
|
|
|
393
571
|
<br/>
|
|
394
572
|
|
|
395
|
-
#### [`
|
|
573
|
+
#### [`getEventTopic`](https://eeth.dev/docs/api/modules#geteventtopic)
|
|
574
|
+

|
|
575
|
+
```typescript
|
|
576
|
+
getEventTopic(eventSignature: string): string
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
<details>
|
|
580
|
+
<summary>View Example</summary>
|
|
396
581
|
|
|
397
|
-
|
|
582
|
+
```js
|
|
583
|
+
import { getEventTopic } from 'essential-eth';
|
|
584
|
+
```
|
|
398
585
|
|
|
399
|
-
```
|
|
400
|
-
|
|
586
|
+
```javascript
|
|
587
|
+
getEventTopic('Transfer(address,address,uint256)');
|
|
588
|
+
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
401
589
|
```
|
|
402
590
|
|
|
591
|
+
</details>
|
|
592
|
+
|
|
593
|
+
<br/>
|
|
594
|
+
|
|
595
|
+
#### [`gweiToEther`](https://eeth.dev/docs/api/modules#gweitoether)
|
|
596
|
+

|
|
597
|
+
```typescript
|
|
598
|
+
gweiToEther(gweiQuantity: string | number | bigint): string
|
|
599
|
+
```
|
|
600
|
+
|
|
403
601
|
<details>
|
|
404
602
|
<summary>View Example</summary>
|
|
405
603
|
|
|
406
|
-
```js
|
|
407
|
-
import {
|
|
408
|
-
```
|
|
604
|
+
```js
|
|
605
|
+
import { gweiToEther } from 'essential-eth';
|
|
606
|
+
```
|
|
409
607
|
|
|
410
|
-
```javascript
|
|
411
|
-
|
|
412
|
-
// '
|
|
608
|
+
```javascript
|
|
609
|
+
gweiToEther('1000000000000')
|
|
610
|
+
// '1000'
|
|
611
|
+
gweiToEther(1000000000000)
|
|
612
|
+
// '1000'
|
|
413
613
|
```
|
|
414
614
|
|
|
415
615
|
</details>
|
|
416
616
|
|
|
417
617
|
<br/>
|
|
418
618
|
|
|
419
|
-
#### [`
|
|
619
|
+
#### [`hashMessage`](https://eeth.dev/docs/api/modules#hashmessage)
|
|
620
|
+

|
|
621
|
+
```typescript
|
|
622
|
+
hashMessage(message: string | Bytes): string
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
<details>
|
|
626
|
+
<summary>View Example</summary>
|
|
420
627
|
|
|
421
|
-
|
|
628
|
+
```js
|
|
629
|
+
import { hashMessage } from 'essential-eth';
|
|
630
|
+
```
|
|
422
631
|
|
|
423
|
-
```
|
|
424
|
-
|
|
632
|
+
```javascript
|
|
633
|
+
hashMessage("Hello World");
|
|
634
|
+
// '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
|
|
425
635
|
```
|
|
426
636
|
|
|
637
|
+
</details>
|
|
638
|
+
|
|
639
|
+
<br/>
|
|
640
|
+
|
|
641
|
+
#### [`hexConcat`](https://eeth.dev/docs/api/modules#hexconcat)
|
|
642
|
+

|
|
643
|
+
```typescript
|
|
644
|
+
hexConcat(items: Array<BytesLike>): string
|
|
645
|
+
```
|
|
646
|
+
|
|
427
647
|
<details>
|
|
428
648
|
<summary>View Example</summary>
|
|
429
649
|
|
|
430
|
-
```js
|
|
431
|
-
import {
|
|
650
|
+
```js
|
|
651
|
+
import { hexConcat } from 'essential-eth';
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
```javascript
|
|
655
|
+
hexConcat([[2, 4, 0, 1], 9, '0x2934', '0x3947']);
|
|
656
|
+
// '0x020400010929343947'
|
|
432
657
|
```
|
|
433
658
|
|
|
434
|
-
|
|
659
|
+
</details>
|
|
660
|
+
|
|
661
|
+
<br/>
|
|
662
|
+
|
|
663
|
+
#### [`hexDataLength`](https://eeth.dev/docs/api/modules#hexdatalength)
|
|
664
|
+

|
|
665
|
+
```typescript
|
|
666
|
+
hexDataLength(data: BytesLike): undefined
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
<details>
|
|
670
|
+
<summary>View Example</summary>
|
|
671
|
+
|
|
672
|
+
```js
|
|
673
|
+
import { hexDataLength } from 'essential-eth';
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
```javascript
|
|
435
677
|
hexDataLength([2, 4, 0, 1]);
|
|
436
678
|
// 4
|
|
437
679
|
```
|
|
438
|
-
|
|
439
680
|
```javascript
|
|
440
681
|
hexDataLength('0x3925');
|
|
441
682
|
// 2
|
|
@@ -446,21 +687,19 @@ hexDataLength('0x3925');
|
|
|
446
687
|
<br/>
|
|
447
688
|
|
|
448
689
|
#### [`hexDataSlice`](https://eeth.dev/docs/api/modules#hexdataslice)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
```
|
|
455
|
-
|
|
690
|
+

|
|
691
|
+
```typescript
|
|
692
|
+
hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset: number): string
|
|
693
|
+
```
|
|
694
|
+
|
|
456
695
|
<details>
|
|
457
696
|
<summary>View Example</summary>
|
|
458
697
|
|
|
459
|
-
```js
|
|
460
|
-
import { hexDataSlice } from 'essential-eth';
|
|
461
|
-
```
|
|
698
|
+
```js
|
|
699
|
+
import { hexDataSlice } from 'essential-eth';
|
|
700
|
+
```
|
|
462
701
|
|
|
463
|
-
```javascript
|
|
702
|
+
```javascript
|
|
464
703
|
hexDataSlice([20, 6, 48], 0, 2);
|
|
465
704
|
// '0x1406'
|
|
466
705
|
```
|
|
@@ -470,22 +709,20 @@ hexDataSlice([20, 6, 48], 0, 2);
|
|
|
470
709
|
<br/>
|
|
471
710
|
|
|
472
711
|
#### [`hexStripZeros`](https://eeth.dev/docs/api/modules#hexstripzeros)
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
```
|
|
479
|
-
|
|
712
|
+

|
|
713
|
+
```typescript
|
|
714
|
+
hexStripZeros(value: BytesLike): string
|
|
715
|
+
```
|
|
716
|
+
|
|
480
717
|
<details>
|
|
481
718
|
<summary>View Example</summary>
|
|
482
719
|
|
|
483
|
-
```js
|
|
484
|
-
import { hexStripZeros } from 'essential-eth';
|
|
485
|
-
```
|
|
720
|
+
```js
|
|
721
|
+
import { hexStripZeros } from 'essential-eth';
|
|
722
|
+
```
|
|
486
723
|
|
|
487
|
-
```javascript
|
|
488
|
-
hexStripZeros([0,
|
|
724
|
+
```javascript
|
|
725
|
+
hexStripZeros([0,0,0,48]);
|
|
489
726
|
// '0x30'
|
|
490
727
|
```
|
|
491
728
|
|
|
@@ -494,25 +731,22 @@ hexStripZeros([0, 0, 0, 48]);
|
|
|
494
731
|
<br/>
|
|
495
732
|
|
|
496
733
|
#### [`hexValue`](https://eeth.dev/docs/api/modules#hexvalue)
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
```
|
|
503
|
-
|
|
734
|
+

|
|
735
|
+
```typescript
|
|
736
|
+
hexValue(value: number | bigint | BytesLike | Hexable): string
|
|
737
|
+
```
|
|
738
|
+
|
|
504
739
|
<details>
|
|
505
740
|
<summary>View Example</summary>
|
|
506
741
|
|
|
507
|
-
```js
|
|
508
|
-
import { hexValue } from 'essential-eth';
|
|
509
|
-
```
|
|
742
|
+
```js
|
|
743
|
+
import { hexValue } from 'essential-eth';
|
|
744
|
+
```
|
|
510
745
|
|
|
511
|
-
```javascript
|
|
746
|
+
```javascript
|
|
512
747
|
hexValue(39);
|
|
513
748
|
// '0x27'
|
|
514
749
|
```
|
|
515
|
-
|
|
516
750
|
```javascript
|
|
517
751
|
hexValue([9, 4, 19, 4]);
|
|
518
752
|
// '0x9041304'
|
|
@@ -523,30 +757,26 @@ hexValue([9, 4, 19, 4]);
|
|
|
523
757
|
<br/>
|
|
524
758
|
|
|
525
759
|
#### [`hexZeroPad`](https://eeth.dev/docs/api/modules#hexzeropad)
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
```
|
|
532
|
-
|
|
760
|
+

|
|
761
|
+
```typescript
|
|
762
|
+
hexZeroPad(value: BytesLikeWithNumber, length: number): string
|
|
763
|
+
```
|
|
764
|
+
|
|
533
765
|
<details>
|
|
534
766
|
<summary>View Example</summary>
|
|
535
767
|
|
|
536
|
-
```js
|
|
537
|
-
import { hexZeroPad } from 'essential-eth';
|
|
538
|
-
```
|
|
768
|
+
```js
|
|
769
|
+
import { hexZeroPad } from 'essential-eth';
|
|
770
|
+
```
|
|
539
771
|
|
|
540
|
-
```javascript
|
|
772
|
+
```javascript
|
|
541
773
|
hexZeroPad('0x60', 2);
|
|
542
774
|
// '0x0060'
|
|
543
775
|
```
|
|
544
|
-
|
|
545
776
|
```javascript
|
|
546
777
|
hexZeroPad(0x60, 3);
|
|
547
778
|
// '0x000060'
|
|
548
779
|
```
|
|
549
|
-
|
|
550
780
|
```javascript
|
|
551
781
|
hexZeroPad('12345', 1);
|
|
552
782
|
// Throws
|
|
@@ -557,25 +787,22 @@ hexZeroPad('12345', 1);
|
|
|
557
787
|
<br/>
|
|
558
788
|
|
|
559
789
|
#### [`hexlify`](https://eeth.dev/docs/api/modules#hexlify)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
```
|
|
566
|
-
|
|
790
|
+

|
|
791
|
+
```typescript
|
|
792
|
+
hexlify(value: number | bigint | BytesLike | Hexable, options: DataOptions): string
|
|
793
|
+
```
|
|
794
|
+
|
|
567
795
|
<details>
|
|
568
796
|
<summary>View Example</summary>
|
|
569
797
|
|
|
570
|
-
```js
|
|
571
|
-
import { hexlify } from 'essential-eth';
|
|
572
|
-
```
|
|
798
|
+
```js
|
|
799
|
+
import { hexlify } from 'essential-eth';
|
|
800
|
+
```
|
|
573
801
|
|
|
574
|
-
```javascript
|
|
802
|
+
```javascript
|
|
575
803
|
hexlify(4);
|
|
576
804
|
// '0x04'
|
|
577
805
|
```
|
|
578
|
-
|
|
579
806
|
```javascript
|
|
580
807
|
hexlify(14);
|
|
581
808
|
// '0x0e'
|
|
@@ -585,31 +812,54 @@ hexlify(14);
|
|
|
585
812
|
|
|
586
813
|
<br/>
|
|
587
814
|
|
|
588
|
-
#### [`
|
|
815
|
+
#### [`id`](https://eeth.dev/docs/api/modules#id)
|
|
816
|
+

|
|
817
|
+
```typescript
|
|
818
|
+
id(text: string): string
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
<details>
|
|
822
|
+
<summary>View Example</summary>
|
|
589
823
|
|
|
590
|
-
|
|
824
|
+
```js
|
|
825
|
+
import { id } from 'essential-eth';
|
|
826
|
+
```
|
|
591
827
|
|
|
592
|
-
```
|
|
593
|
-
|
|
828
|
+
```javascript
|
|
829
|
+
id('Transfer(address,address,uint256)')
|
|
830
|
+
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
831
|
+
```
|
|
832
|
+
```javascript
|
|
833
|
+
// Get a function selector (first 4 bytes)
|
|
834
|
+
id('balanceOf(address)').slice(0, 10)
|
|
835
|
+
// '0x70a08231'
|
|
594
836
|
```
|
|
595
837
|
|
|
838
|
+
</details>
|
|
839
|
+
|
|
840
|
+
<br/>
|
|
841
|
+
|
|
842
|
+
#### [`isAddress`](https://eeth.dev/docs/api/modules#isaddress)
|
|
843
|
+

|
|
844
|
+
```typescript
|
|
845
|
+
isAddress(address: string): boolean
|
|
846
|
+
```
|
|
847
|
+
|
|
596
848
|
<details>
|
|
597
849
|
<summary>View Example</summary>
|
|
598
850
|
|
|
599
|
-
```js
|
|
600
|
-
import { isAddress } from 'essential-eth';
|
|
601
|
-
```
|
|
851
|
+
```js
|
|
852
|
+
import { isAddress } from 'essential-eth';
|
|
853
|
+
```
|
|
602
854
|
|
|
603
|
-
```javascript
|
|
855
|
+
```javascript
|
|
604
856
|
isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
|
|
605
857
|
// true
|
|
606
858
|
```
|
|
607
|
-
|
|
608
859
|
```javascript
|
|
609
860
|
isAddress('bad');
|
|
610
861
|
// false
|
|
611
862
|
```
|
|
612
|
-
|
|
613
863
|
```javascript
|
|
614
864
|
// Does NOT support ENS.
|
|
615
865
|
isAddress('vitalik.eth');
|
|
@@ -621,30 +871,26 @@ isAddress('vitalik.eth');
|
|
|
621
871
|
<br/>
|
|
622
872
|
|
|
623
873
|
#### [`isBytes`](https://eeth.dev/docs/api/modules#isbytes)
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
```
|
|
630
|
-
|
|
874
|
+

|
|
875
|
+
```typescript
|
|
876
|
+
isBytes(value: any): value
|
|
877
|
+
```
|
|
878
|
+
|
|
631
879
|
<details>
|
|
632
880
|
<summary>View Example</summary>
|
|
633
881
|
|
|
634
|
-
```js
|
|
635
|
-
import { isBytes } from 'essential-eth';
|
|
636
|
-
```
|
|
882
|
+
```js
|
|
883
|
+
import { isBytes } from 'essential-eth';
|
|
884
|
+
```
|
|
637
885
|
|
|
638
|
-
```javascript
|
|
639
|
-
isBytes([1,
|
|
886
|
+
```javascript
|
|
887
|
+
isBytes([1,2,3]);
|
|
640
888
|
// true
|
|
641
889
|
```
|
|
642
|
-
|
|
643
890
|
```javascript
|
|
644
891
|
isBytes(false);
|
|
645
892
|
// false
|
|
646
893
|
```
|
|
647
|
-
|
|
648
894
|
```javascript
|
|
649
895
|
isBytes(new Uint8Array(1));
|
|
650
896
|
// true
|
|
@@ -655,30 +901,26 @@ isBytes(new Uint8Array(1));
|
|
|
655
901
|
<br/>
|
|
656
902
|
|
|
657
903
|
#### [`isBytesLike`](https://eeth.dev/docs/api/modules#isbyteslike)
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
```
|
|
664
|
-
|
|
904
|
+

|
|
905
|
+
```typescript
|
|
906
|
+
isBytesLike(value: any): value
|
|
907
|
+
```
|
|
908
|
+
|
|
665
909
|
<details>
|
|
666
910
|
<summary>View Example</summary>
|
|
667
911
|
|
|
668
|
-
```js
|
|
669
|
-
import { isBytesLike } from 'essential-eth';
|
|
670
|
-
```
|
|
912
|
+
```js
|
|
913
|
+
import { isBytesLike } from 'essential-eth';
|
|
914
|
+
```
|
|
671
915
|
|
|
672
|
-
```javascript
|
|
673
|
-
isBytesLike([1,
|
|
916
|
+
```javascript
|
|
917
|
+
isBytesLike([1,2,3]);
|
|
674
918
|
// true
|
|
675
919
|
```
|
|
676
|
-
|
|
677
920
|
```javascript
|
|
678
921
|
isBytesLike(false);
|
|
679
922
|
// false
|
|
680
923
|
```
|
|
681
|
-
|
|
682
924
|
```javascript
|
|
683
925
|
isBytesLike(new Uint8Array(1));
|
|
684
926
|
// true
|
|
@@ -689,25 +931,22 @@ isBytesLike(new Uint8Array(1));
|
|
|
689
931
|
<br/>
|
|
690
932
|
|
|
691
933
|
#### [`isHexString`](https://eeth.dev/docs/api/modules#ishexstring)
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
```
|
|
696
|
-
|
|
697
|
-
```
|
|
698
|
-
|
|
934
|
+

|
|
935
|
+
```typescript
|
|
936
|
+
isHexString(value: any, length: number): boolean
|
|
937
|
+
```
|
|
938
|
+
|
|
699
939
|
<details>
|
|
700
940
|
<summary>View Example</summary>
|
|
701
941
|
|
|
702
|
-
```js
|
|
703
|
-
import { isHexString } from 'essential-eth';
|
|
704
|
-
```
|
|
942
|
+
```js
|
|
943
|
+
import { isHexString } from 'essential-eth';
|
|
944
|
+
```
|
|
705
945
|
|
|
706
|
-
```javascript
|
|
946
|
+
```javascript
|
|
707
947
|
isHexString('0x4924');
|
|
708
948
|
// true
|
|
709
949
|
```
|
|
710
|
-
|
|
711
950
|
```javascript
|
|
712
951
|
isHexString('0x4924', 4);
|
|
713
952
|
// false
|
|
@@ -719,26 +958,22 @@ isHexString('0x4924', 4);
|
|
|
719
958
|
<br/>
|
|
720
959
|
|
|
721
960
|
#### [`jsonRpcProvider`](https://eeth.dev/docs/api/modules#jsonrpcprovider)
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
```
|
|
726
|
-
|
|
727
|
-
```
|
|
728
|
-
|
|
961
|
+

|
|
962
|
+
```typescript
|
|
963
|
+
jsonRpcProvider(rpcUrl: string): JsonRpcProvider
|
|
964
|
+
```
|
|
965
|
+
|
|
729
966
|
<details>
|
|
730
967
|
<summary>View Example</summary>
|
|
731
968
|
|
|
732
|
-
```js
|
|
733
|
-
import { jsonRpcProvider } from 'essential-eth';
|
|
734
|
-
```
|
|
969
|
+
```js
|
|
970
|
+
import { jsonRpcProvider } from 'essential-eth';
|
|
971
|
+
```
|
|
735
972
|
|
|
736
|
-
```javascript
|
|
737
|
-
jsonRpcProvider()
|
|
738
|
-
.
|
|
739
|
-
|
|
740
|
-
console.log(block.number);
|
|
741
|
-
});
|
|
973
|
+
```javascript
|
|
974
|
+
jsonRpcProvider().getBlock('latest').then(block => {
|
|
975
|
+
console.log(block.number);
|
|
976
|
+
})
|
|
742
977
|
// 14530496
|
|
743
978
|
```
|
|
744
979
|
|
|
@@ -747,21 +982,19 @@ jsonRpcProvider()
|
|
|
747
982
|
<br/>
|
|
748
983
|
|
|
749
984
|
#### [`keccak256`](https://eeth.dev/docs/api/modules#keccak256)
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
```
|
|
754
|
-
|
|
755
|
-
```
|
|
756
|
-
|
|
985
|
+

|
|
986
|
+
```typescript
|
|
987
|
+
keccak256(data: BytesLike): string
|
|
988
|
+
```
|
|
989
|
+
|
|
757
990
|
<details>
|
|
758
991
|
<summary>View Example</summary>
|
|
759
992
|
|
|
760
|
-
```js
|
|
761
|
-
import { keccak256 } from 'essential-eth';
|
|
762
|
-
```
|
|
993
|
+
```js
|
|
994
|
+
import { keccak256 } from 'essential-eth';
|
|
995
|
+
```
|
|
763
996
|
|
|
764
|
-
```javascript
|
|
997
|
+
```javascript
|
|
765
998
|
keccak256('essential-eth');
|
|
766
999
|
// '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
|
|
767
1000
|
|
|
@@ -773,22 +1006,48 @@ keccak256('0x123');
|
|
|
773
1006
|
|
|
774
1007
|
<br/>
|
|
775
1008
|
|
|
776
|
-
#### [`
|
|
1009
|
+
#### [`namehash`](https://eeth.dev/docs/api/modules#namehash)
|
|
1010
|
+

|
|
1011
|
+
```typescript
|
|
1012
|
+
namehash(name: string): string
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
<details>
|
|
1016
|
+
<summary>View Example</summary>
|
|
777
1017
|
|
|
778
|
-
|
|
1018
|
+
```js
|
|
1019
|
+
import { namehash } from 'essential-eth';
|
|
1020
|
+
```
|
|
779
1021
|
|
|
780
|
-
```
|
|
781
|
-
|
|
1022
|
+
```javascript
|
|
1023
|
+
namehash('');
|
|
1024
|
+
// '0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
1025
|
+
|
|
1026
|
+
namehash('eth');
|
|
1027
|
+
// '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae'
|
|
1028
|
+
|
|
1029
|
+
namehash('vitalik.eth');
|
|
1030
|
+
// '0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835'
|
|
782
1031
|
```
|
|
783
1032
|
|
|
1033
|
+
</details>
|
|
1034
|
+
|
|
1035
|
+
<br/>
|
|
1036
|
+
|
|
1037
|
+
#### [`pack`](https://eeth.dev/docs/api/modules#pack)
|
|
1038
|
+

|
|
1039
|
+
```typescript
|
|
1040
|
+
pack(types: Array<string>, values: Array<any>): string
|
|
1041
|
+
```
|
|
1042
|
+
|
|
784
1043
|
<details>
|
|
785
1044
|
<summary>View Example</summary>
|
|
786
1045
|
|
|
787
|
-
```js
|
|
788
|
-
import { pack } from 'essential-eth';
|
|
789
|
-
```
|
|
1046
|
+
```js
|
|
1047
|
+
import { pack } from 'essential-eth';
|
|
1048
|
+
```
|
|
790
1049
|
|
|
791
|
-
```javascript
|
|
1050
|
+
```javascript
|
|
792
1051
|
const types = ['bool', 'string', 'uint64'];
|
|
793
1052
|
const values = [true, 'text', 30];
|
|
794
1053
|
pack(types, values);
|
|
@@ -799,34 +1058,58 @@ pack(types, values);
|
|
|
799
1058
|
|
|
800
1059
|
<br/>
|
|
801
1060
|
|
|
802
|
-
#### [`
|
|
1061
|
+
#### [`parseUnits`](https://eeth.dev/docs/api/modules#parseunits)
|
|
1062
|
+

|
|
1063
|
+
```typescript
|
|
1064
|
+
parseUnits(value: string, decimals?: number): bigint
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
<details>
|
|
1068
|
+
<summary>View Example</summary>
|
|
803
1069
|
|
|
804
|
-
|
|
1070
|
+
```js
|
|
1071
|
+
import { parseUnits } from 'essential-eth';
|
|
1072
|
+
```
|
|
805
1073
|
|
|
806
|
-
```
|
|
807
|
-
|
|
1074
|
+
```javascript
|
|
1075
|
+
parseUnits('1', 6)
|
|
1076
|
+
// 1000000n
|
|
808
1077
|
```
|
|
1078
|
+
```javascript
|
|
1079
|
+
parseUnits('1.5', 6)
|
|
1080
|
+
// 1500000n
|
|
1081
|
+
```
|
|
1082
|
+
```javascript
|
|
1083
|
+
parseUnits('1', 18)
|
|
1084
|
+
// 1000000000000000000n
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
</details>
|
|
809
1088
|
|
|
1089
|
+
<br/>
|
|
1090
|
+
|
|
1091
|
+
#### [`solidityKeccak256`](https://eeth.dev/docs/api/modules#soliditykeccak256)
|
|
1092
|
+

|
|
1093
|
+
```typescript
|
|
1094
|
+
solidityKeccak256(types: Array<string>, values: Array<any>): string
|
|
1095
|
+
```
|
|
1096
|
+
|
|
810
1097
|
<details>
|
|
811
1098
|
<summary>View Example</summary>
|
|
812
1099
|
|
|
813
|
-
```js
|
|
814
|
-
import { solidityKeccak256 } from 'essential-eth';
|
|
815
|
-
```
|
|
1100
|
+
```js
|
|
1101
|
+
import { solidityKeccak256 } from 'essential-eth';
|
|
1102
|
+
```
|
|
816
1103
|
|
|
817
|
-
```javascript
|
|
1104
|
+
```javascript
|
|
818
1105
|
const types = ['string', 'bool', 'uint32'];
|
|
819
1106
|
const values = ['essential-eth is great', true, 14];
|
|
820
1107
|
solidityKeccak256(types, values);
|
|
821
1108
|
// '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
822
1109
|
```
|
|
823
|
-
|
|
824
1110
|
```javascript
|
|
825
1111
|
const types = ['bytes4', 'uint32[5]'];
|
|
826
|
-
const values = [
|
|
827
|
-
[116, 101, 115, 116],
|
|
828
|
-
[5, 3, 4, 9, 18],
|
|
829
|
-
];
|
|
1112
|
+
const values = [[116, 101, 115, 116], [5, 3, 4, 9, 18]];
|
|
830
1113
|
solidityKeccak256(types, values);
|
|
831
1114
|
// '0x038707a887f09355dc545412b058e7ba8f3c74047050c7c5e5e52eec608053d9'
|
|
832
1115
|
```
|
|
@@ -836,32 +1119,30 @@ solidityKeccak256(types, values);
|
|
|
836
1119
|
<br/>
|
|
837
1120
|
|
|
838
1121
|
#### [`splitSignature`](https://eeth.dev/docs/api/modules#splitsignature)
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
```
|
|
843
|
-
|
|
844
|
-
```
|
|
845
|
-
|
|
1122
|
+

|
|
1123
|
+
```typescript
|
|
1124
|
+
splitSignature(signature: SignatureLike): Signature
|
|
1125
|
+
```
|
|
1126
|
+
|
|
846
1127
|
<details>
|
|
847
1128
|
<summary>View Example</summary>
|
|
848
1129
|
|
|
849
|
-
```js
|
|
850
|
-
import { splitSignature } from 'essential-eth';
|
|
851
|
-
```
|
|
1130
|
+
```js
|
|
1131
|
+
import { splitSignature } from 'essential-eth';
|
|
1132
|
+
```
|
|
852
1133
|
|
|
853
|
-
```javascript
|
|
1134
|
+
```javascript
|
|
854
1135
|
const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
855
1136
|
splitSignature(signature);
|
|
856
|
-
{
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
1137
|
+
{
|
|
1138
|
+
r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
1139
|
+
s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
1140
|
+
_vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
1141
|
+
recoveryParam: 0,
|
|
1142
|
+
v: 27,
|
|
1143
|
+
yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
1144
|
+
compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
1145
|
+
}
|
|
865
1146
|
```
|
|
866
1147
|
|
|
867
1148
|
</details>
|
|
@@ -869,21 +1150,19 @@ splitSignature(signature);
|
|
|
869
1150
|
<br/>
|
|
870
1151
|
|
|
871
1152
|
#### [`stripZeros`](https://eeth.dev/docs/api/modules#stripzeros)
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
```
|
|
876
|
-
|
|
877
|
-
```
|
|
878
|
-
|
|
1153
|
+

|
|
1154
|
+
```typescript
|
|
1155
|
+
stripZeros(value: BytesLike): Uint8Array
|
|
1156
|
+
```
|
|
1157
|
+
|
|
879
1158
|
<details>
|
|
880
1159
|
<summary>View Example</summary>
|
|
881
1160
|
|
|
882
|
-
```js
|
|
883
|
-
import { stripZeros } from 'essential-eth';
|
|
884
|
-
```
|
|
1161
|
+
```js
|
|
1162
|
+
import { stripZeros } from 'essential-eth';
|
|
1163
|
+
```
|
|
885
1164
|
|
|
886
|
-
```javascript
|
|
1165
|
+
```javascript
|
|
887
1166
|
stripZeros('0x00002834');
|
|
888
1167
|
// Uint8Array { [Iterator] 0: 40, 1: 52 }
|
|
889
1168
|
// Equivalent to '0x2834'
|
|
@@ -893,50 +1172,25 @@ stripZeros('0x00002834');
|
|
|
893
1172
|
|
|
894
1173
|
<br/>
|
|
895
1174
|
|
|
896
|
-
#### [`tinyBig`](https://eeth.dev/docs/api/modules#tinybig)
|
|
897
|
-
|
|
898
|
-

|
|
899
|
-
|
|
900
|
-
```typescript
|
|
901
|
-
tinyBig(value: string | number | TinyBig | Big): TinyBig
|
|
902
|
-
```
|
|
903
|
-
|
|
904
|
-
<details>
|
|
905
|
-
<summary>View Example</summary>
|
|
906
|
-
|
|
907
|
-
```js
|
|
908
|
-
import { tinyBig } from 'essential-eth';
|
|
909
|
-
```
|
|
910
|
-
|
|
911
|
-
```javascript
|
|
912
|
-
tinyBig(10).times(3).toNumber();
|
|
913
|
-
// 30
|
|
914
|
-
```
|
|
915
|
-
|
|
916
|
-
</details>
|
|
917
|
-
|
|
918
|
-
<br/>
|
|
919
|
-
|
|
920
1175
|
#### [`toChecksumAddress`](https://eeth.dev/docs/api/modules#tochecksumaddress)
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
```
|
|
925
|
-
|
|
926
|
-
```
|
|
927
|
-
|
|
1176
|
+

|
|
1177
|
+
```typescript
|
|
1178
|
+
toChecksumAddress(address: string): string
|
|
1179
|
+
```
|
|
1180
|
+
|
|
928
1181
|
<details>
|
|
929
1182
|
<summary>View Example</summary>
|
|
930
1183
|
|
|
931
|
-
```js
|
|
932
|
-
import { toChecksumAddress } from 'essential-eth';
|
|
933
|
-
```
|
|
1184
|
+
```js
|
|
1185
|
+
import { toChecksumAddress } from 'essential-eth';
|
|
1186
|
+
```
|
|
934
1187
|
|
|
935
|
-
```javascript
|
|
1188
|
+
```javascript
|
|
936
1189
|
toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
937
1190
|
// '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
|
|
938
1191
|
```
|
|
939
1192
|
|
|
1193
|
+
|
|
940
1194
|
Similar to ["getAddress" in ethers.js](https://docs.ethers.io/v5/api/utils/address/#utils-getAddress)
|
|
941
1195
|
|
|
942
1196
|
Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#tochecksumaddress)
|
|
@@ -946,21 +1200,19 @@ Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.
|
|
|
946
1200
|
<br/>
|
|
947
1201
|
|
|
948
1202
|
#### [`toUtf8Bytes`](https://eeth.dev/docs/api/modules#toutf8bytes)
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
```
|
|
953
|
-
|
|
954
|
-
```
|
|
955
|
-
|
|
1203
|
+

|
|
1204
|
+
```typescript
|
|
1205
|
+
toUtf8Bytes(data: string): Uint8Array
|
|
1206
|
+
```
|
|
1207
|
+
|
|
956
1208
|
<details>
|
|
957
1209
|
<summary>View Example</summary>
|
|
958
1210
|
|
|
959
|
-
```js
|
|
960
|
-
import { toUtf8Bytes } from 'essential-eth';
|
|
961
|
-
```
|
|
1211
|
+
```js
|
|
1212
|
+
import { toUtf8Bytes } from 'essential-eth';
|
|
1213
|
+
```
|
|
962
1214
|
|
|
963
|
-
```javascript
|
|
1215
|
+
```javascript
|
|
964
1216
|
toUtf8Bytes('essential-eth');
|
|
965
1217
|
// Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
|
|
966
1218
|
|
|
@@ -972,33 +1224,50 @@ toUtf8Bytes('ethereum');
|
|
|
972
1224
|
|
|
973
1225
|
<br/>
|
|
974
1226
|
|
|
975
|
-
#### [`
|
|
1227
|
+
#### [`toUtf8String`](https://eeth.dev/docs/api/modules#toutf8string)
|
|
1228
|
+

|
|
1229
|
+
```typescript
|
|
1230
|
+
toUtf8String(bytes: BytesLike): string
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
<details>
|
|
1234
|
+
<summary>View Example</summary>
|
|
976
1235
|
|
|
977
|
-
|
|
1236
|
+
```js
|
|
1237
|
+
import { toUtf8String } from 'essential-eth';
|
|
1238
|
+
```
|
|
978
1239
|
|
|
979
|
-
```
|
|
980
|
-
|
|
1240
|
+
```javascript
|
|
1241
|
+
toUtf8String(new Uint8Array([101, 116, 104]))
|
|
1242
|
+
// 'eth'
|
|
1243
|
+
```
|
|
1244
|
+
```javascript
|
|
1245
|
+
toUtf8String('0x657468')
|
|
1246
|
+
// 'eth'
|
|
981
1247
|
```
|
|
982
1248
|
|
|
1249
|
+
</details>
|
|
1250
|
+
|
|
1251
|
+
<br/>
|
|
1252
|
+
|
|
1253
|
+
#### [`weiToEther`](https://eeth.dev/docs/api/modules#weitoether)
|
|
1254
|
+

|
|
1255
|
+
```typescript
|
|
1256
|
+
weiToEther(weiQuantity: string | number | bigint): string
|
|
1257
|
+
```
|
|
1258
|
+
|
|
983
1259
|
<details>
|
|
984
1260
|
<summary>View Example</summary>
|
|
985
1261
|
|
|
986
|
-
```js
|
|
987
|
-
import { weiToEther } from 'essential-eth';
|
|
988
|
-
```
|
|
1262
|
+
```js
|
|
1263
|
+
import { weiToEther } from 'essential-eth';
|
|
1264
|
+
```
|
|
989
1265
|
|
|
990
|
-
```javascript
|
|
991
|
-
weiToEther('1000000000000000000000')
|
|
1266
|
+
```javascript
|
|
1267
|
+
weiToEther('1000000000000000000000')
|
|
992
1268
|
// '1000'
|
|
993
|
-
weiToEther(1000000000000000000000)
|
|
1269
|
+
weiToEther(1000000000000000000000)
|
|
994
1270
|
// '1000'
|
|
995
|
-
```
|
|
996
|
-
|
|
997
|
-
```javascript
|
|
998
|
-
weiToEther('1000000000000000000000').toNumber();
|
|
999
|
-
// 1000
|
|
1000
|
-
weiToEther(1000000000000000000000).toNumber();
|
|
1001
|
-
// 1000
|
|
1002
1271
|
```
|
|
1003
1272
|
|
|
1004
1273
|
</details>
|
|
@@ -1006,26 +1275,23 @@ weiToEther(1000000000000000000000).toNumber();
|
|
|
1006
1275
|
<br/>
|
|
1007
1276
|
|
|
1008
1277
|
#### [`zeroPad`](https://eeth.dev/docs/api/modules#zeropad)
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
```
|
|
1013
|
-
|
|
1014
|
-
```
|
|
1015
|
-
|
|
1278
|
+

|
|
1279
|
+
```typescript
|
|
1280
|
+
zeroPad(value: BytesLike, length: number): Uint8Array
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1016
1283
|
<details>
|
|
1017
1284
|
<summary>View Example</summary>
|
|
1018
1285
|
|
|
1019
|
-
```js
|
|
1020
|
-
import { zeroPad } from 'essential-eth';
|
|
1021
|
-
```
|
|
1286
|
+
```js
|
|
1287
|
+
import { zeroPad } from 'essential-eth';
|
|
1288
|
+
```
|
|
1022
1289
|
|
|
1023
|
-
```javascript
|
|
1290
|
+
```javascript
|
|
1024
1291
|
zeroPad('0x039284');
|
|
1025
1292
|
// Uint8Array { [Iterator] 0: 0, 1: 0, 2: 0, 3: 3, 4: 146, 5: 132 }
|
|
1026
1293
|
// Equivalent to 0x000000039284
|
|
1027
1294
|
```
|
|
1028
|
-
|
|
1029
1295
|
```javascript
|
|
1030
1296
|
zeroPad([39, 25, 103, 45], 5);
|
|
1031
1297
|
// Uint8Array { [Iterator] 0: 0, 1: 39, 2: 25, 3: 103, 4: 45 }
|
|
@@ -1035,6 +1301,8 @@ zeroPad([39, 25, 103, 45], 5);
|
|
|
1035
1301
|
|
|
1036
1302
|
<br/>
|
|
1037
1303
|
|
|
1304
|
+
|
|
1305
|
+
|
|
1038
1306
|
<!-- โ๏ธ AUTO-GENERATED-CONTENT:END -->
|
|
1039
1307
|
|
|
1040
1308
|
- _The return-type `TinyBig` is just [`Big`](https://github.com/MikeMcl/big.js) but expands scientific notation on `toNumber()` and `toString()`_
|
|
@@ -1074,8 +1342,8 @@ provider.getGasPrice().toNumber();
|
|
|
1074
1342
|
|
|
1075
1343
|
<br/>
|
|
1076
1344
|
|
|
1077
|
-
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (PROVIDER) -->
|
|
1078
1345
|
|
|
1346
|
+
<!-- โ๏ธ AUTO-GENERATED-CONTENT:START (PROVIDER) -->
|
|
1079
1347
|
#### [`call`](https://eeth.dev/docs/api/classes/JsonRpcProvider#call)
|
|
1080
1348
|
|
|
1081
1349
|
```typescript
|
|
@@ -1540,6 +1808,39 @@ await provider.getTransactionReceipt(
|
|
|
1540
1808
|
|
|
1541
1809
|
<br/>
|
|
1542
1810
|
|
|
1811
|
+
#### [`resolveName`](https://eeth.dev/docs/api/classes/JsonRpcProvider#resolvename)
|
|
1812
|
+
|
|
1813
|
+
```typescript
|
|
1814
|
+
provider.resolveName(name: string): Promise<string | null>
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1817
|
+
Resolves an ENS name to an Ethereum address. Returns `null` if the name has no resolver or no address set.
|
|
1818
|
+
|
|
1819
|
+
Similar to ["resolveName" in ethers.js](https://docs.ethers.io/v5/api/providers/provider/#Provider-ResolveName)
|
|
1820
|
+
|
|
1821
|
+
<details>
|
|
1822
|
+
<summary>View Example</summary>
|
|
1823
|
+
|
|
1824
|
+
```js
|
|
1825
|
+
import { JsonRpcProvider } from 'essential-eth';
|
|
1826
|
+
const provider = new JsonRpcProvider('RPC URL HERE' /* Try Infura or POKT */);
|
|
1827
|
+
```
|
|
1828
|
+
|
|
1829
|
+
```javascript
|
|
1830
|
+
await provider.resolveName('vitalik.eth');
|
|
1831
|
+
// '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
|
|
1832
|
+
|
|
1833
|
+
await provider.resolveName('daws.eth');
|
|
1834
|
+
// '0x5C389...' (resolved address)
|
|
1835
|
+
|
|
1836
|
+
await provider.resolveName('thisdoesnotexist12345.eth');
|
|
1837
|
+
// null
|
|
1838
|
+
```
|
|
1839
|
+
|
|
1840
|
+
</details>
|
|
1841
|
+
|
|
1842
|
+
<br/>
|
|
1843
|
+
|
|
1543
1844
|
<!-- โ๏ธ AUTO-GENERATED-CONTENT:END -->
|
|
1544
1845
|
|
|
1545
1846
|
<br/>
|