essential-eth 0.6.2 → 0.8.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/cjs/classes/Contract.js +307 -66
- package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
- package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
- package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
- package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
- package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
- package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
- package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
- package/dist/cjs/classes/utils/clean-block.js +52 -30
- package/dist/cjs/classes/utils/clean-log.js +42 -20
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
- package/dist/cjs/classes/utils/clean-transaction.js +52 -29
- package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
- package/dist/cjs/classes/utils/fetchers.js +165 -41
- package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
- package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
- package/dist/cjs/index.js +25 -54
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -23
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -4
- package/dist/cjs/providers/BaseProvider.d.ts +2 -0
- package/dist/cjs/providers/BaseProvider.js +883 -475
- package/dist/cjs/providers/FallthroughProvider.js +118 -37
- package/dist/cjs/providers/JsonRpcProvider.js +93 -28
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
- package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +212 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
- package/dist/cjs/providers/test/rpc-urls.js +9 -12
- package/dist/cjs/providers/utils/chains-info.js +1 -3
- package/dist/cjs/shared/tiny-big/helpers.js +93 -42
- package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +1 -2
- package/dist/cjs/types/Contract.types.js +1 -2
- package/dist/cjs/types/FeeData.types.d.ts +7 -0
- package/dist/cjs/types/FeeData.types.js +1 -0
- package/dist/cjs/types/Filter.types.js +1 -2
- package/dist/cjs/types/Network.types.js +3 -2
- package/dist/cjs/types/Transaction.types.js +1 -2
- package/dist/cjs/utils/bytes.js +286 -318
- package/dist/cjs/utils/compute-address.js +8 -14
- package/dist/cjs/utils/compute-public-key.js +5 -10
- package/dist/cjs/utils/ether-to-gwei.js +10 -11
- package/dist/cjs/utils/ether-to-wei.js +10 -11
- package/dist/cjs/utils/gwei-to-ether.js +10 -11
- package/dist/cjs/utils/hash-message.d.ts +1 -1
- package/dist/cjs/utils/hash-message.js +11 -14
- package/dist/cjs/utils/is-address.js +8 -12
- package/dist/cjs/utils/keccak256.js +8 -14
- package/dist/cjs/utils/solidity-keccak256.js +49 -60
- package/dist/cjs/utils/split-signature.js +55 -73
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
- package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
- package/dist/cjs/utils/tests/compute-address.test.js +27 -0
- package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
- package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
- package/dist/cjs/utils/tests/hash-message.test.js +21 -0
- package/dist/cjs/utils/tests/is-address.test.js +55 -0
- package/dist/cjs/utils/tests/keccak256.test.js +97 -0
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
- package/dist/cjs/utils/tests/split-signature.test.js +25 -0
- package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
- package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
- package/dist/cjs/utils/to-checksum-address.js +15 -20
- package/dist/cjs/utils/to-utf8-bytes.js +1 -6
- package/dist/cjs/utils/wei-to-ether.js +13 -15
- package/dist/esm/classes/utils/clean-block.d.ts +1 -2
- package/dist/esm/classes/utils/clean-block.js +1 -1
- package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
- package/dist/esm/classes/utils/clean-transaction.js +2 -1
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/BaseProvider.d.ts +2 -0
- package/dist/esm/providers/BaseProvider.js +15 -0
- package/dist/esm/types/FeeData.types.d.ts +7 -0
- package/dist/esm/types/FeeData.types.js +1 -0
- package/dist/esm/utils/compute-address.js +2 -1
- package/dist/esm/utils/hash-message.d.ts +1 -1
- package/dist/esm/utils/hash-message.js +3 -1
- package/dist/esm/utils/is-address.js +1 -1
- package/package.json +10 -8
- package/readme.md +63 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
2
|
import type { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
|
+
import type { FeeData } from '../types/FeeData.types';
|
|
3
4
|
import type { Filter, FilterByBlockHash } from '../types/Filter.types';
|
|
4
5
|
import type { Network } from '../types/Network.types';
|
|
5
6
|
import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
|
|
@@ -19,6 +20,7 @@ export declare abstract class BaseProvider {
|
|
|
19
20
|
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
20
21
|
getCode(address: string, blockTag?: BlockTag): Promise<string>;
|
|
21
22
|
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
23
|
+
getFeeData(): Promise<FeeData>;
|
|
22
24
|
getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
|
|
23
25
|
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
|
|
24
26
|
}
|
|
@@ -120,6 +120,21 @@ export class BaseProvider {
|
|
|
120
120
|
return tinyBig(hexToDecimal(gasUsed));
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
+
getFeeData() {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const [block, gasPrice] = yield Promise.all([
|
|
126
|
+
this.getBlock('latest'),
|
|
127
|
+
this.getGasPrice(),
|
|
128
|
+
]);
|
|
129
|
+
let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
|
|
130
|
+
if (block && block.baseFeePerGas) {
|
|
131
|
+
lastBaseFeePerGas = block.baseFeePerGas;
|
|
132
|
+
maxPriorityFeePerGas = tinyBig('1500000000');
|
|
133
|
+
maxFeePerGas = tinyBig(block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas));
|
|
134
|
+
}
|
|
135
|
+
return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
|
|
136
|
+
});
|
|
137
|
+
}
|
|
123
138
|
getLogs(filter) {
|
|
124
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
140
|
const filterByRange = filter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { computePublicKey, toChecksumAddress } from '..';
|
|
2
1
|
import { hexDataSlice } from './bytes';
|
|
2
|
+
import { computePublicKey } from './compute-public-key';
|
|
3
3
|
import { keccak256 } from './keccak256';
|
|
4
|
+
import { toChecksumAddress } from './to-checksum-address';
|
|
4
5
|
export function computeAddress(key) {
|
|
5
6
|
if (!key.startsWith('0x04') &&
|
|
6
7
|
!key.startsWith('0x03') &&
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Bytes } from '
|
|
1
|
+
import type { Bytes } from './bytes';
|
|
2
2
|
export declare function hashMessage(message: Bytes | string): string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { concat
|
|
1
|
+
import { concat } from './bytes';
|
|
2
|
+
import { keccak256 } from './keccak256';
|
|
3
|
+
import { toUtf8Bytes } from './to-utf8-bytes';
|
|
2
4
|
const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
3
5
|
export function hashMessage(message) {
|
|
4
6
|
if (typeof message === 'string') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "essential-eth",
|
|
3
3
|
"description": "Ultralight JS for Ethereum",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"private": false,
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"name": "JsonRpcProvider",
|
|
31
31
|
"path": "src/index.ts",
|
|
32
32
|
"import": "{ JsonRpcProvider }",
|
|
33
|
-
"limit": "20.
|
|
33
|
+
"limit": "20.32kb"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
"name": "Contract",
|
|
37
37
|
"path": "src/index.ts",
|
|
38
38
|
"import": "{ Contract }",
|
|
39
|
-
"limit": "15.
|
|
39
|
+
"limit": "15.38kb"
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"compile": "npm-run-all --parallel build:esm build:cjs build:umd",
|
|
48
48
|
"build": "rm -rf dist && npm run compile",
|
|
49
49
|
"build:esm": "tsc -p tsconfig.json",
|
|
50
|
-
"build:cjs": "
|
|
50
|
+
"build:cjs": "swc src -d dist/cjs",
|
|
51
51
|
"build:umd": "microbundle --external none --format umd",
|
|
52
52
|
"build:readme": "bash ./scripts/markdown-magic/build-readme.sh",
|
|
53
53
|
"jest": "jest",
|
|
@@ -62,6 +62,8 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
65
|
+
"@swc/cli": "^0.1.57",
|
|
66
|
+
"@swc/core": "^1.3.21",
|
|
65
67
|
"@types/body-parser": "^1.19.1",
|
|
66
68
|
"@types/eslint": "^8.4.2",
|
|
67
69
|
"@types/express": "^4.17.13",
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
"eslint": "^8.16.0",
|
|
77
79
|
"eslint-plugin-jest": "^26.2.2",
|
|
78
80
|
"eslint-plugin-jsdoc": "38.0.2",
|
|
79
|
-
"ethers": "^5.7.
|
|
81
|
+
"ethers": "^5.7.2",
|
|
80
82
|
"express": "^4.17.1",
|
|
81
83
|
"husky": "^7.0.4",
|
|
82
84
|
"jest": "^27.5.1",
|
|
@@ -86,18 +88,18 @@
|
|
|
86
88
|
"microbundle": "^0.15.0",
|
|
87
89
|
"npm-run-all": "^4.1.5",
|
|
88
90
|
"perf_hooks": "^0.0.1",
|
|
89
|
-
"prettier": "^2.
|
|
91
|
+
"prettier": "^2.8.4",
|
|
90
92
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
91
93
|
"size-limit": "^7.0.8",
|
|
92
94
|
"ts-jest": "^27.1.4",
|
|
93
95
|
"ts-node": "^10.2.1",
|
|
94
96
|
"typedoc": "^0.22.15",
|
|
95
97
|
"typescript": "^4.6.4",
|
|
96
|
-
"web3": "^1.
|
|
98
|
+
"web3": "^1.8.1"
|
|
97
99
|
},
|
|
98
100
|
"dependencies": {
|
|
99
101
|
"@noble/secp256k1": "^1.5.5",
|
|
100
|
-
"@types/big.js": "^6.1.
|
|
102
|
+
"@types/big.js": "^6.1.6",
|
|
101
103
|
"big.js": "^6.2.1",
|
|
102
104
|
"isomorphic-unfetch": "^3.1.0",
|
|
103
105
|
"sha3": "^2.1.4"
|
package/readme.md
CHANGED
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
- [`getBlock`](#getblock)
|
|
92
92
|
- [`getBlockNumber`](#getblocknumber)
|
|
93
93
|
- [`getCode`](#getcode)
|
|
94
|
+
- [`getFeeData`](#getfeedata)
|
|
94
95
|
- [`getGasPrice`](#getgasprice)
|
|
95
96
|
- [`getLogs`](#getlogs)
|
|
96
97
|
- [`getNetwork`](#getnetwork)
|
|
@@ -100,8 +101,12 @@
|
|
|
100
101
|
- [Contract](#contract)
|
|
101
102
|
- [`contractFunctionName(args)`](#contractfunctionnameargs)
|
|
102
103
|
- [More Info](#more-info)
|
|
103
|
-
- [Identical vs Similar vs
|
|
104
|
+
- [Identical vs Similar vs Dissimilar {#isd}](#identical-vs-similar-vs-dissimilar-isd)
|
|
104
105
|
- [Miscellaneous](#miscellaneous)
|
|
106
|
+
- [GitPOAP](#gitpoap)
|
|
107
|
+
- [What is a GitPOAP?](#what-is-a-gitpoap)
|
|
108
|
+
- [How can I claim?](#how-can-i-claim)
|
|
109
|
+
- [What issues should I start on first?](#what-issues-should-i-start-on-first)
|
|
105
110
|
|
|
106
111
|
</details>
|
|
107
112
|
|
|
@@ -124,7 +129,7 @@ Browsers:
|
|
|
124
129
|
|
|
125
130
|
```html
|
|
126
131
|
<!-- index.html -->
|
|
127
|
-
<script src="https://unpkg.com/essential-eth@0.
|
|
132
|
+
<script src="https://unpkg.com/essential-eth@0.8.0"></script>
|
|
128
133
|
```
|
|
129
134
|
|
|
130
135
|
<!-- ⛔️ AUTO-GENERATED-CONTENT:END (UNPKG_SCRIPT_TAG) -->
|
|
@@ -1191,6 +1196,34 @@ await jsonRpcProvider().getCode(
|
|
|
1191
1196
|
|
|
1192
1197
|
<br/>
|
|
1193
1198
|
|
|
1199
|
+
#### [`getFeeData`](https://eeth.dev/docs/api/classes/JsonRpcProvider#getfeedata)
|
|
1200
|
+
|
|
1201
|
+
```typescript
|
|
1202
|
+
provider.getFeeData(): Promise<FeeData>
|
|
1203
|
+
```
|
|
1204
|
+
|
|
1205
|
+
<details>
|
|
1206
|
+
<summary>View Example</summary>
|
|
1207
|
+
|
|
1208
|
+
```js
|
|
1209
|
+
import { JsonRpcProvider } from 'essential-eth';
|
|
1210
|
+
const provider = new JsonRpcProvider('RPC URL HERE' /* Try Infura or POKT */);
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
```javascript
|
|
1214
|
+
await provider.getFeeData();
|
|
1215
|
+
// {
|
|
1216
|
+
// gasPrice: { TinyBig: "14184772639" },
|
|
1217
|
+
// lastBaseFeePerGas: { TinyBig: "14038523098" },
|
|
1218
|
+
// maxFeePerGas: { TinyBig: "29577046196" },
|
|
1219
|
+
// maxPriorityFeePerGas: { TinyBig: "1500000000" }
|
|
1220
|
+
// }
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
</details>
|
|
1224
|
+
|
|
1225
|
+
<br/>
|
|
1226
|
+
|
|
1194
1227
|
#### [`getGasPrice`](https://eeth.dev/docs/api/classes/JsonRpcProvider#getgasprice)
|
|
1195
1228
|
|
|
1196
1229
|
```typescript
|
|
@@ -1473,6 +1506,7 @@ Decoding support:
|
|
|
1473
1506
|
- `uint256`
|
|
1474
1507
|
- `bytes32`
|
|
1475
1508
|
- `uint8`
|
|
1509
|
+
- `string` (only if there is one string output, not multiple yet)
|
|
1476
1510
|
|
|
1477
1511
|
_Assume all types outside the above types will break for now_
|
|
1478
1512
|
|
|
@@ -1535,7 +1569,7 @@ Any function on a contract. Returns are the same as `ethers.js`, except that ins
|
|
|
1535
1569
|
|
|
1536
1570
|
<br/>
|
|
1537
1571
|
|
|
1538
|
-
### Identical vs Similar vs
|
|
1572
|
+
### Identical vs Similar vs Dissimilar {#isd}
|
|
1539
1573
|
|
|
1540
1574
|
Throughout the documentation for `essential-eth`, you may notice that some functions are compared to `ethers.js` and `web3.js`. The keywords `identical`, `similar`, and `dissimilar` are used to help you migrate to `essential-eth`. Here's a guide on what these keywords mean:
|
|
1541
1575
|
|
|
@@ -1549,3 +1583,29 @@ Note: In `web3.js`, almost every method or function can be passed a callback. `e
|
|
|
1549
1583
|
|
|
1550
1584
|
- [📓 View full docs](https://eeth.dev)
|
|
1551
1585
|
- [📓 View changelog (by looking at releases diff)](https://github.com/dawsbot/essential-eth/releases)
|
|
1586
|
+
|
|
1587
|
+
### GitPOAP
|
|
1588
|
+
|
|
1589
|
+
In partnership with GitPOAP, Essential ETH wants to recognize **all** contributors for their contributions toward the growth of this library. Developers can validate their contributions on Github and showcase their GitPOAP as proof-of-work toward their Web3 identity.
|
|
1590
|
+
|
|
1591
|
+
<br/>
|
|
1592
|
+
|
|
1593
|
+

|
|
1594
|
+
|
|
1595
|
+
<br/>
|
|
1596
|
+
|
|
1597
|
+
#### What is a GitPOAP?
|
|
1598
|
+
|
|
1599
|
+
GitPOAP is a contributor recognition platform built on top of the POAP Protocol (Proof of Attendance Protocol). Similar to a POAP, each GitPOAP represents a digital collectible. It serves as a badge of validation for the action taken by the individual. By serving as a bridge between Github and Web3, it allows repo maintainers to recognize contributors for their meaningful contributions. Learn more about GitPOAP, [here](https://www.gitpoap.io/).
|
|
1600
|
+
|
|
1601
|
+
#### How can I claim?
|
|
1602
|
+
|
|
1603
|
+
Here are two steps that you can take to qualify for a GitPOAP:
|
|
1604
|
+
|
|
1605
|
+
1. Contribute to [any open issue](https://github.com/dawsbot/essential-eth/issues) and submit a PR. Upon approval of PR merge, the GitPOAP will automatically be issued to the Github account.
|
|
1606
|
+
|
|
1607
|
+
2. Head to gitpoap.io and connect your GitHub account to mint!
|
|
1608
|
+
|
|
1609
|
+
#### What issues should I start on first?
|
|
1610
|
+
|
|
1611
|
+
We have set up a GitHub project [here](https://github.com/dawsbot/essential-eth/projects/1) for you to see all the issues by priority.
|