essential-eth 0.5.0 โ†’ 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/lib/cjs/classes/Contract.d.ts +3 -2
  2. package/lib/cjs/classes/Contract.js +3 -2
  3. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +5 -0
  4. package/lib/cjs/classes/utils/clean-transaction-receipt.js +55 -0
  5. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +1 -0
  6. package/lib/cjs/classes/utils/encode-decode-transaction.js +4 -4
  7. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  8. package/lib/cjs/index.d.ts +7 -2
  9. package/lib/cjs/index.js +24 -3
  10. package/lib/cjs/logger/logger.d.ts +11 -0
  11. package/lib/cjs/logger/logger.js +36 -0
  12. package/lib/cjs/logger/package-version.d.ts +1 -0
  13. package/lib/cjs/logger/package-version.js +5 -0
  14. package/lib/cjs/providers/BaseProvider.d.ts +270 -0
  15. package/lib/cjs/providers/BaseProvider.js +361 -0
  16. package/lib/cjs/providers/FallthroughProvider.d.ts +25 -0
  17. package/lib/cjs/providers/FallthroughProvider.js +65 -0
  18. package/lib/cjs/providers/JsonRpcProvider.d.ts +4 -200
  19. package/lib/cjs/providers/JsonRpcProvider.js +11 -263
  20. package/lib/cjs/providers/test/rpc-urls.d.ts +1 -0
  21. package/lib/cjs/providers/test/rpc-urls.js +1 -0
  22. package/lib/cjs/providers/utils/chains-info.d.ts +8 -0
  23. package/lib/cjs/providers/utils/chains-info.js +24 -0
  24. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +9 -2
  25. package/lib/cjs/shared/tiny-big/tiny-big.js +27 -9
  26. package/lib/cjs/types/Transaction.types.d.ts +53 -0
  27. package/lib/cjs/utils/bytes.d.ts +172 -0
  28. package/lib/cjs/utils/bytes.js +564 -0
  29. package/lib/cjs/utils/hash-message.d.ts +12 -0
  30. package/lib/cjs/utils/hash-message.js +26 -0
  31. package/lib/cjs/utils/keccak256.d.ts +2 -0
  32. package/lib/cjs/utils/keccak256.js +17 -0
  33. package/lib/cjs/utils/solidity-keccak256.d.ts +29 -0
  34. package/lib/cjs/utils/solidity-keccak256.js +118 -0
  35. package/lib/cjs/utils/to-utf8-bytes.d.ts +1 -0
  36. package/lib/cjs/utils/to-utf8-bytes.js +7 -0
  37. package/lib/esm/classes/Contract.js +1 -1
  38. package/lib/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  39. package/lib/esm/classes/utils/clean-transaction-receipt.js +48 -0
  40. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +1 -0
  41. package/lib/esm/classes/utils/encode-decode-transaction.js +2 -2
  42. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  43. package/lib/esm/index.d.ts +7 -2
  44. package/lib/esm/index.js +7 -2
  45. package/lib/esm/logger/logger.d.ts +11 -0
  46. package/lib/esm/logger/logger.js +33 -0
  47. package/lib/esm/logger/package-version.d.ts +1 -0
  48. package/lib/esm/logger/package-version.js +1 -0
  49. package/lib/esm/providers/BaseProvider.d.ts +18 -0
  50. package/lib/esm/providers/BaseProvider.js +101 -0
  51. package/lib/esm/providers/FallthroughProvider.d.ts +12 -0
  52. package/lib/esm/providers/FallthroughProvider.js +41 -0
  53. package/lib/esm/providers/JsonRpcProvider.d.ts +4 -12
  54. package/lib/esm/providers/JsonRpcProvider.js +8 -69
  55. package/lib/esm/providers/test/rpc-urls.d.ts +1 -0
  56. package/lib/esm/providers/test/rpc-urls.js +1 -0
  57. package/lib/esm/providers/utils/chains-info.d.ts +8 -0
  58. package/lib/esm/providers/utils/chains-info.js +24 -0
  59. package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -0
  60. package/lib/esm/shared/tiny-big/tiny-big.js +20 -7
  61. package/lib/esm/types/Transaction.types.d.ts +45 -0
  62. package/lib/esm/utils/bytes.d.ts +40 -0
  63. package/lib/esm/utils/bytes.js +245 -0
  64. package/lib/esm/utils/hash-message.d.ts +2 -0
  65. package/lib/esm/utils/hash-message.js +12 -0
  66. package/lib/esm/utils/keccak256.d.ts +2 -0
  67. package/lib/esm/utils/keccak256.js +13 -0
  68. package/lib/esm/utils/solidity-keccak256.d.ts +2 -0
  69. package/lib/esm/utils/solidity-keccak256.js +85 -0
  70. package/lib/esm/utils/to-utf8-bytes.d.ts +1 -0
  71. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  72. package/package.json +19 -19
  73. package/readme.md +36 -5
  74. package/lib/cjs/utils/hex-zero-pad.d.ts +0 -32
  75. package/lib/cjs/utils/hex-zero-pad.js +0 -52
  76. package/lib/esm/utils/hex-zero-pad.d.ts +0 -1
  77. package/lib/esm/utils/hex-zero-pad.js +0 -17
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "essential-eth",
3
3
  "description": "Ultralight JS library for Ethereum utilities",
4
- "version": "0.5.0",
4
+ "version": "0.5.4",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "./lib/cjs/index.js",
@@ -17,18 +17,21 @@
17
17
  "scripts": {
18
18
  "test": "npm-run-all --parallel jest compile lint",
19
19
  "test:all-node-versions": "npx trevor",
20
- "lint": "eslint .",
20
+ "lint": "eslint --cache --fix .",
21
21
  "compile": "npm-run-all --parallel tsc:esm tsc:cjs",
22
22
  "tsc:esm": "tsc -p tsconfig.json",
23
23
  "tsc:cjs": "tsc -p tsconfig-cjs.json",
24
24
  "build": "rm -rf lib && npm run compile",
25
- "prepublishOnly": "npm run build",
26
25
  "jest": "jest",
27
26
  "build:chains-info": "npx ts-node scripts/fetch-chains-info.ts # used in getNetwork()",
28
- "pre-commit": "sh scripts/pre-commit.sh"
27
+ "update-deps": "sh ./scripts/pre-commit.sh",
28
+ "pre-commit": "run-p build:chains-info update-deps",
29
+ "prepare": "husky install",
30
+ "version": "npx genversion --es6 src/logger/package-version.ts && git add src/logger/package-version.ts",
31
+ "postversion": "git push --follow-tags",
32
+ "prepublishOnly": "npm run build"
29
33
  },
30
34
  "devDependencies": {
31
- "@ethersproject/keccak256": "^5.4.0",
32
35
  "@types/body-parser": "^1.19.1",
33
36
  "@types/eslint": "^8.4.1",
34
37
  "@types/express": "^4.17.13",
@@ -36,26 +39,27 @@
36
39
  "@types/jest-dev-server": "^5.0.0",
37
40
  "@types/node": "^16.10.1",
38
41
  "@types/prettier": "^2.4.4",
39
- "@typescript-eslint/eslint-plugin": "^5.19.0",
40
- "@typescript-eslint/parser": "^5.19.0",
42
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
43
+ "@typescript-eslint/parser": "^5.21.0",
41
44
  "body-parser": "^1.19.0",
42
45
  "dotenv": "^16.0.0",
43
- "eslint": "^8.13.0",
44
- "eslint-plugin-jest": "^26.1.4",
45
- "ethers": "^5.6.3",
46
+ "eslint": "^8.14.0",
47
+ "eslint-plugin-jest": "^26.1.5",
48
+ "ethers": "^5.6.4",
46
49
  "express": "^4.17.1",
47
- "husky": "^4.3.0",
50
+ "husky": "^7.0.4",
48
51
  "jest": "^27.5.1",
49
52
  "jest-dev-server": "^6.0.3",
50
53
  "just-omit": "^2.0.1",
51
- "lint-staged": "^12.3.7",
54
+ "lint-staged": "^12.4.1",
52
55
  "npm-run-all": "^4.1.5",
56
+ "perf_hooks": "^0.0.1",
53
57
  "prettier": "^2.6.2",
54
58
  "prettier-plugin-organize-imports": "^2.3.4",
55
59
  "ts-jest": "^27.1.4",
56
60
  "ts-node": "^10.2.1",
57
61
  "typedoc": "^0.22.13",
58
- "typescript": "^4.6.3",
62
+ "typescript": "^4.6.4",
59
63
  "web3": "^1.7.3"
60
64
  },
61
65
  "dependencies": {
@@ -64,15 +68,11 @@
64
68
  "isomorphic-unfetch": "^3.1.0",
65
69
  "sha3": "^2.1.4"
66
70
  },
67
- "husky": {
68
- "hooks": {
69
- "pre-commit": "lint-staged && run-p pre-commit test build:chains-info"
70
- }
71
- },
72
71
  "lint-staged": {
73
72
  "*.{js,jsx,ts,tsx,css,scss,md,json,html,yml,yaml}": [
74
73
  "prettier --write"
75
- ]
74
+ ],
75
+ "*.{ts,tsx}": "eslint --cache --fix"
76
76
  },
77
77
  "prettier": {
78
78
  "trailingComma": "all",
package/readme.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://user-images.githubusercontent.com/3408480/163274699-ae4fb0f4-fca0-4745-bcd7-4868f80deaf6.png" title="Logo"/>
2
+ <img src="https://user-images.githubusercontent.com/3408480/163274699-ae4fb0f4-fca0-4745-bcd7-4868f80deaf6.png" height="220" title="Logo"/>
3
3
 
4
4
  </p>
5
5
  <p align="center">
@@ -8,7 +8,7 @@
8
8
  ๐Ÿชถ Essential Eth ๐Ÿชถ
9
9
  </b>
10
10
  <br/>
11
- <i>A replacement for ethers & web3 that's 50x smaller</i>
11
+ <i>A replacement for ethers & web3 that's 20x smaller</i>
12
12
  <br/>
13
13
  </p>
14
14
 
@@ -37,6 +37,10 @@
37
37
 
38
38
  <br/>
39
39
 
40
+ [![๐Ÿงช tests](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml/badge.svg)](https://github.com/Earnifi/essential-eth/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/Earnifi/essential-eth/branch/master/graph/badge.svg?token=E44EK6RWTZ)](https://codecov.io/gh/Earnifi/essential-eth) ![](https://badgen.net/bundlephobia/minzip/essential-eth) ![](https://badgen.net/bundlephobia/tree-shaking/essential-eth) ![](https://img.shields.io/npm/v/essential-eth)
41
+
42
+ <br/>
43
+
40
44
  ## Install
41
45
 
42
46
  ```sh
@@ -251,10 +255,35 @@ import { JsonRpcProvider } from 'essential-eth';
251
255
  const essentialEth = new JsonRpcProvider(
252
256
  'RPC URL HERE' /* Try POKT or Infura */,
253
257
  );
254
- // OR for very quick testing (limited to 500 requests)
258
+ // OR for very quick testing (limited to 10,000 requests)
255
259
  const essentialEth = new JsonRpcProvider();
256
260
  ```
257
261
 
262
+ <details>
263
+ <summary>Want a redundant provider that handles outages?</summary>
264
+
265
+ ```typescript
266
+ import { FallthroughProvider } from 'essential-eth';
267
+
268
+ // The FallthroughProvider handles falling through to the next valid URL.
269
+ // It's dynamic to never trust one URL again when it fails * until it has tried all other provided URLs
270
+ // The default timeout for a request is 8 seconds after which it moves to the next URL
271
+ const provider = new FallthroughProvider([
272
+ 'https://bad.com',
273
+ 'https://free-eth-node.com/api/eth',
274
+ ]);
275
+ provider.getGasPrice().toNumber();
276
+ /*
277
+ 39695942769
278
+ */
279
+ ```
280
+
281
+ </details>
282
+
283
+ <br/>
284
+
285
+ #### [`getTransactionCount(address, blockTag?): Promise<number>`](https://essential-eth.vercel.app/docs/api/classes/JsonRpcProvider#gettransactioncount)
286
+
258
287
  #### `getGasPrice`
259
288
 
260
289
  Returns the current gas price in gwei
@@ -617,11 +646,13 @@ Any function on a contract. Returns are the same as `ethers.js`, except that ins
617
646
 
618
647
  ๐Ÿงช This repo is under active development. The API is less-fully featured than `web3` and `ethers`. More functions added often!
619
648
 
620
- ![](https://badgen.net/bundlephobia/minzip/essential-eth) ![](https://badgen.net/bundlephobia/tree-shaking/essential-eth) ![](https://img.shields.io/npm/v/essential-eth) ![](https://badgen.net/bundlephobia/dependency-count/essential-eth)
621
-
622
649
  ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Breaking changes will exist between minor versions until `1.0.0` (Versions go `major.minor.patch`)
623
650
 
624
651
  <br/>
625
652
 
653
+ ![Alt](https://repobeats.axiom.co/api/embed/e479d8f777288a94cdde2fe3cdedf38d5243793d.svg 'Repobeats analytics image')
654
+
655
+ <br/>
656
+
626
657
  - [๐Ÿ““ View full docs](https://essential-eth.vercel.app)
627
658
  - [๐Ÿ““ View changelog (by looking at releases diff)](https://github.com/dawsbot/essential-eth/releases)
@@ -1,32 +0,0 @@
1
- /**
2
- * Returns a hex string padded to a specified length of bytes.
3
- *
4
- * Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
5
- *
6
- * Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
7
- *
8
- * @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
9
- * @param length - The final length in bytes
10
- *
11
- * @throws - If the value is not a hex string or number
12
- * @throws - If the value is longer than the length
13
- *
14
- * @example
15
- * ```javascript
16
- * hexZeroPad('0x60', 2);
17
- * // '0x0060'
18
- * ```
19
- *
20
- * @example
21
- * ```javascript
22
- * hexZeroPad(0x60, 3);
23
- * // '0x000060'
24
- * ```
25
- *
26
- * @example
27
- * ```javascript
28
- * hexZeroPad('12345', 1);
29
- * // Throws
30
- * ```
31
- */
32
- export declare function hexZeroPad(hexValue: string | number, length: number): string;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexZeroPad = void 0;
4
- const validate_type_1 = require("../shared/validate-type");
5
- /**
6
- * Returns a hex string padded to a specified length of bytes.
7
- *
8
- * Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
9
- *
10
- * Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
11
- *
12
- * @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
13
- * @param length - The final length in bytes
14
- *
15
- * @throws - If the value is not a hex string or number
16
- * @throws - If the value is longer than the length
17
- *
18
- * @example
19
- * ```javascript
20
- * hexZeroPad('0x60', 2);
21
- * // '0x0060'
22
- * ```
23
- *
24
- * @example
25
- * ```javascript
26
- * hexZeroPad(0x60, 3);
27
- * // '0x000060'
28
- * ```
29
- *
30
- * @example
31
- * ```javascript
32
- * hexZeroPad('12345', 1);
33
- * // Throws
34
- * ```
35
- */
36
- function hexZeroPad(hexValue, length) {
37
- (0, validate_type_1.validateType)(hexValue, ['string', 'number']);
38
- let val;
39
- if (typeof hexValue === 'string') {
40
- if (!hexValue.startsWith('0x'))
41
- throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
42
- val = hexValue.substring(2);
43
- }
44
- else {
45
- val = hexValue.toString(16);
46
- }
47
- if (val.length > length * 2) {
48
- throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
49
- }
50
- return `0x${val.padStart(length * 2, '0')}`;
51
- }
52
- exports.hexZeroPad = hexZeroPad;
@@ -1 +0,0 @@
1
- export declare function hexZeroPad(hexValue: string | number, length: number): string;
@@ -1,17 +0,0 @@
1
- import { validateType } from '../shared/validate-type';
2
- export function hexZeroPad(hexValue, length) {
3
- validateType(hexValue, ['string', 'number']);
4
- let val;
5
- if (typeof hexValue === 'string') {
6
- if (!hexValue.startsWith('0x'))
7
- throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
8
- val = hexValue.substring(2);
9
- }
10
- else {
11
- val = hexValue.toString(16);
12
- }
13
- if (val.length > length * 2) {
14
- throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
15
- }
16
- return `0x${val.padStart(length * 2, '0')}`;
17
- }