essential-eth 0.10.2 → 0.10.4-beta.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.
Files changed (205) hide show
  1. package/dist/index.cjs +2024 -0
  2. package/dist/index.d.cts +330 -0
  3. package/dist/index.d.ts +330 -0
  4. package/dist/index.js +1952 -0
  5. package/package.json +13 -14
  6. package/readme.md +1 -1
  7. package/dist/cjs/classes/Contract.d.ts +0 -81
  8. package/dist/cjs/classes/Contract.js +0 -139
  9. package/dist/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
  10. package/dist/cjs/classes/test/Contract/crv-abi.js +0 -413
  11. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
  12. package/dist/cjs/classes/test/Contract/ens-abi.js +0 -453
  13. package/dist/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
  14. package/dist/cjs/classes/test/Contract/fei-abi.js +0 -526
  15. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
  16. package/dist/cjs/classes/test/Contract/foo-abi.js +0 -42
  17. package/dist/cjs/classes/test/Contract/jokerrace-abi.d.ts +0 -2
  18. package/dist/cjs/classes/test/Contract/jokerrace-abi.js +0 -22
  19. package/dist/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
  20. package/dist/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  21. package/dist/cjs/classes/utils/clean-block.d.ts +0 -120
  22. package/dist/cjs/classes/utils/clean-block.js +0 -160
  23. package/dist/cjs/classes/utils/clean-log.d.ts +0 -9
  24. package/dist/cjs/classes/utils/clean-log.js +0 -39
  25. package/dist/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
  26. package/dist/cjs/classes/utils/clean-transaction-receipt.js +0 -53
  27. package/dist/cjs/classes/utils/clean-transaction.d.ts +0 -14
  28. package/dist/cjs/classes/utils/clean-transaction.js +0 -54
  29. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
  30. package/dist/cjs/classes/utils/encode-decode-transaction.js +0 -186
  31. package/dist/cjs/classes/utils/fetchers.d.ts +0 -53
  32. package/dist/cjs/classes/utils/fetchers.js +0 -85
  33. package/dist/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
  34. package/dist/cjs/classes/utils/hex-to-decimal.js +0 -24
  35. package/dist/cjs/classes/utils/prepare-transaction.d.ts +0 -6
  36. package/dist/cjs/classes/utils/prepare-transaction.js +0 -47
  37. package/dist/cjs/index.d.ts +0 -24
  38. package/dist/cjs/index.js +0 -58
  39. package/dist/cjs/index.umd.js +0 -2
  40. package/dist/cjs/index.umd.js.map +0 -1
  41. package/dist/cjs/logger/logger.d.ts +0 -11
  42. package/dist/cjs/logger/logger.js +0 -37
  43. package/dist/cjs/logger/package-version.d.ts +0 -1
  44. package/dist/cjs/logger/package-version.js +0 -5
  45. package/dist/cjs/package.json +0 -1
  46. package/dist/cjs/providers/AlchemyProvider.d.ts +0 -4
  47. package/dist/cjs/providers/AlchemyProvider.js +0 -11
  48. package/dist/cjs/providers/BaseProvider.d.ts +0 -374
  49. package/dist/cjs/providers/BaseProvider.js +0 -514
  50. package/dist/cjs/providers/FallthroughProvider.d.ts +0 -24
  51. package/dist/cjs/providers/FallthroughProvider.js +0 -74
  52. package/dist/cjs/providers/JsonRpcProvider.d.ts +0 -33
  53. package/dist/cjs/providers/JsonRpcProvider.js +0 -46
  54. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
  55. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +0 -152
  56. package/dist/cjs/providers/test/mock-of.d.ts +0 -8
  57. package/dist/cjs/providers/test/mock-of.js +0 -12
  58. package/dist/cjs/providers/test/rpc-urls.d.ts +0 -12
  59. package/dist/cjs/providers/test/rpc-urls.js +0 -27
  60. package/dist/cjs/providers/utils/chains-info.d.ts +0 -24
  61. package/dist/cjs/providers/utils/chains-info.js +0 -71
  62. package/dist/cjs/shared/tiny-big/helpers.d.ts +0 -17
  63. package/dist/cjs/shared/tiny-big/helpers.js +0 -97
  64. package/dist/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
  65. package/dist/cjs/shared/tiny-big/tiny-big.js +0 -101
  66. package/dist/cjs/shared/validate-type.d.ts +0 -3
  67. package/dist/cjs/shared/validate-type.js +0 -9
  68. package/dist/cjs/types/Block.types.d.ts +0 -41
  69. package/dist/cjs/types/Block.types.js +0 -2
  70. package/dist/cjs/types/Contract.types.d.ts +0 -24
  71. package/dist/cjs/types/Contract.types.js +0 -2
  72. package/dist/cjs/types/FeeData.types.d.ts +0 -7
  73. package/dist/cjs/types/FeeData.types.js +0 -2
  74. package/dist/cjs/types/Filter.types.d.ts +0 -16
  75. package/dist/cjs/types/Filter.types.js +0 -2
  76. package/dist/cjs/types/Network.types.d.ts +0 -8
  77. package/dist/cjs/types/Network.types.js +0 -2
  78. package/dist/cjs/types/Transaction.types.d.ts +0 -123
  79. package/dist/cjs/types/Transaction.types.js +0 -2
  80. package/dist/cjs/utils/bytes.d.ts +0 -289
  81. package/dist/cjs/utils/bytes.js +0 -711
  82. package/dist/cjs/utils/compute-address.d.ts +0 -17
  83. package/dist/cjs/utils/compute-address.js +0 -34
  84. package/dist/cjs/utils/compute-public-key.d.ts +0 -18
  85. package/dist/cjs/utils/compute-public-key.js +0 -26
  86. package/dist/cjs/utils/ether-to-gwei.d.ts +0 -27
  87. package/dist/cjs/utils/ether-to-gwei.js +0 -35
  88. package/dist/cjs/utils/ether-to-wei.d.ts +0 -27
  89. package/dist/cjs/utils/ether-to-wei.js +0 -35
  90. package/dist/cjs/utils/gwei-to-ether.d.ts +0 -27
  91. package/dist/cjs/utils/gwei-to-ether.js +0 -35
  92. package/dist/cjs/utils/hash-message.d.ts +0 -14
  93. package/dist/cjs/utils/hash-message.js +0 -30
  94. package/dist/cjs/utils/is-address.d.ts +0 -24
  95. package/dist/cjs/utils/is-address.js +0 -39
  96. package/dist/cjs/utils/keccak256.d.ts +0 -16
  97. package/dist/cjs/utils/keccak256.js +0 -31
  98. package/dist/cjs/utils/solidity-keccak256.d.ts +0 -39
  99. package/dist/cjs/utils/solidity-keccak256.js +0 -138
  100. package/dist/cjs/utils/split-signature.d.ts +0 -24
  101. package/dist/cjs/utils/split-signature.js +0 -163
  102. package/dist/cjs/utils/to-checksum-address.d.ts +0 -17
  103. package/dist/cjs/utils/to-checksum-address.js +0 -46
  104. package/dist/cjs/utils/to-utf8-bytes.d.ts +0 -15
  105. package/dist/cjs/utils/to-utf8-bytes.js +0 -21
  106. package/dist/cjs/utils/wei-to-ether.d.ts +0 -27
  107. package/dist/cjs/utils/wei-to-ether.js +0 -45
  108. package/dist/esm/classes/Contract.d.ts +0 -11
  109. package/dist/esm/classes/Contract.js +0 -58
  110. package/dist/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  111. package/dist/esm/classes/test/Contract/crv-abi.js +0 -395
  112. package/dist/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  113. package/dist/esm/classes/test/Contract/ens-abi.js +0 -435
  114. package/dist/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  115. package/dist/esm/classes/test/Contract/fei-abi.js +0 -521
  116. package/dist/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  117. package/dist/esm/classes/test/Contract/foo-abi.js +0 -33
  118. package/dist/esm/classes/test/Contract/jokerrace-abi.d.ts +0 -2
  119. package/dist/esm/classes/test/Contract/jokerrace-abi.js +0 -18
  120. package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  121. package/dist/esm/classes/test/Contract/uniswap-abi.js +0 -116
  122. package/dist/esm/classes/utils/clean-block.d.ts +0 -2
  123. package/dist/esm/classes/utils/clean-block.js +0 -35
  124. package/dist/esm/classes/utils/clean-log.d.ts +0 -2
  125. package/dist/esm/classes/utils/clean-log.js +0 -28
  126. package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +0 -2
  127. package/dist/esm/classes/utils/clean-transaction-receipt.js +0 -37
  128. package/dist/esm/classes/utils/clean-transaction.d.ts +0 -2
  129. package/dist/esm/classes/utils/clean-transaction.js +0 -36
  130. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
  131. package/dist/esm/classes/utils/encode-decode-transaction.js +0 -143
  132. package/dist/esm/classes/utils/fetchers.d.ts +0 -15
  133. package/dist/esm/classes/utils/fetchers.js +0 -37
  134. package/dist/esm/classes/utils/hex-to-decimal.d.ts +0 -1
  135. package/dist/esm/classes/utils/hex-to-decimal.js +0 -3
  136. package/dist/esm/classes/utils/prepare-transaction.d.ts +0 -2
  137. package/dist/esm/classes/utils/prepare-transaction.js +0 -36
  138. package/dist/esm/index.d.ts +0 -24
  139. package/dist/esm/index.js +0 -19
  140. package/dist/esm/logger/logger.d.ts +0 -11
  141. package/dist/esm/logger/logger.js +0 -34
  142. package/dist/esm/logger/package-version.d.ts +0 -1
  143. package/dist/esm/logger/package-version.js +0 -1
  144. package/dist/esm/providers/AlchemyProvider.d.ts +0 -4
  145. package/dist/esm/providers/AlchemyProvider.js +0 -7
  146. package/dist/esm/providers/BaseProvider.d.ts +0 -26
  147. package/dist/esm/providers/BaseProvider.js +0 -137
  148. package/dist/esm/providers/FallthroughProvider.d.ts +0 -11
  149. package/dist/esm/providers/FallthroughProvider.js +0 -50
  150. package/dist/esm/providers/JsonRpcProvider.d.ts +0 -7
  151. package/dist/esm/providers/JsonRpcProvider.js +0 -15
  152. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
  153. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +0 -142
  154. package/dist/esm/providers/test/mock-of.d.ts +0 -1
  155. package/dist/esm/providers/test/mock-of.js +0 -1
  156. package/dist/esm/providers/test/rpc-urls.d.ts +0 -12
  157. package/dist/esm/providers/test/rpc-urls.js +0 -21
  158. package/dist/esm/providers/utils/chains-info.d.ts +0 -24
  159. package/dist/esm/providers/utils/chains-info.js +0 -67
  160. package/dist/esm/shared/tiny-big/helpers.d.ts +0 -1
  161. package/dist/esm/shared/tiny-big/helpers.js +0 -58
  162. package/dist/esm/shared/tiny-big/tiny-big.d.ts +0 -10
  163. package/dist/esm/shared/tiny-big/tiny-big.js +0 -45
  164. package/dist/esm/shared/validate-type.d.ts +0 -3
  165. package/dist/esm/shared/validate-type.js +0 -5
  166. package/dist/esm/types/Block.types.d.ts +0 -40
  167. package/dist/esm/types/Block.types.js +0 -1
  168. package/dist/esm/types/Contract.types.d.ts +0 -24
  169. package/dist/esm/types/Contract.types.js +0 -1
  170. package/dist/esm/types/FeeData.types.d.ts +0 -7
  171. package/dist/esm/types/FeeData.types.js +0 -1
  172. package/dist/esm/types/Filter.types.d.ts +0 -12
  173. package/dist/esm/types/Filter.types.js +0 -1
  174. package/dist/esm/types/Network.types.d.ts +0 -5
  175. package/dist/esm/types/Network.types.js +0 -1
  176. package/dist/esm/types/Transaction.types.d.ts +0 -113
  177. package/dist/esm/types/Transaction.types.js +0 -1
  178. package/dist/esm/utils/bytes.d.ts +0 -40
  179. package/dist/esm/utils/bytes.js +0 -245
  180. package/dist/esm/utils/compute-address.d.ts +0 -1
  181. package/dist/esm/utils/compute-address.js +0 -12
  182. package/dist/esm/utils/compute-public-key.d.ts +0 -2
  183. package/dist/esm/utils/compute-public-key.js +0 -6
  184. package/dist/esm/utils/ether-to-gwei.d.ts +0 -3
  185. package/dist/esm/utils/ether-to-gwei.js +0 -7
  186. package/dist/esm/utils/ether-to-wei.d.ts +0 -3
  187. package/dist/esm/utils/ether-to-wei.js +0 -7
  188. package/dist/esm/utils/gwei-to-ether.d.ts +0 -3
  189. package/dist/esm/utils/gwei-to-ether.js +0 -7
  190. package/dist/esm/utils/hash-message.d.ts +0 -2
  191. package/dist/esm/utils/hash-message.js +0 -14
  192. package/dist/esm/utils/is-address.d.ts +0 -1
  193. package/dist/esm/utils/is-address.js +0 -12
  194. package/dist/esm/utils/keccak256.d.ts +0 -2
  195. package/dist/esm/utils/keccak256.js +0 -13
  196. package/dist/esm/utils/solidity-keccak256.d.ts +0 -2
  197. package/dist/esm/utils/solidity-keccak256.js +0 -85
  198. package/dist/esm/utils/split-signature.d.ts +0 -2
  199. package/dist/esm/utils/split-signature.js +0 -126
  200. package/dist/esm/utils/to-checksum-address.d.ts +0 -1
  201. package/dist/esm/utils/to-checksum-address.js +0 -25
  202. package/dist/esm/utils/to-utf8-bytes.d.ts +0 -1
  203. package/dist/esm/utils/to-utf8-bytes.js +0 -3
  204. package/dist/esm/utils/wei-to-ether.d.ts +0 -3
  205. package/dist/esm/utils/wei-to-ether.js +0 -16
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanTransaction = void 0;
4
- const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
5
- const to_checksum_address_1 = require("../../utils/to-checksum-address");
6
- const hex_to_decimal_1 = require("./hex-to-decimal");
7
- /**
8
- * Converts RPC transaction response to more JS-friendly format
9
- *
10
- * @param transaction the transaction to clean
11
- * @returns a cleaned transaction
12
- * @example
13
- * ```javascript
14
- * const RPCTransaction = { accessList: [], blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: '0xe28f62', chainId: '0x1', from: '0x642824fab1d0141073ed74326332950bec4701e3', gas: '0x274b7', gasPrice: '0x62df1c62c', hash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', input: '0xa0712d68000000000000000000000000000000000000000000000000000000000000000a', maxFeePerGas: '0x98808e3f0', maxPriorityFeePerGas: '0x3b9aca00', nonce: '0x42', r: '0x304682f8b22006dd1347c3722f6e43a5ad8e3a1ae51939cc0d6f07981602f5c0', s: '0x207ad110eb5c014cb628814b92396785fabfbe74542293300eeadf156f50f105', to: '0x84f80ea01e26b7c11bdd241970982c7eeab6ddcc', transactionIndex: '0x29', type: '0x2', v: '0x1', value: '0x470de4df820000' }
15
- * cleanTransaction(RPCTransaction);
16
- * // { accessList: [], blockHash: '0x03ddc6a835462f750fcaf5ab511d8c48121b0813e3e80de84d7adc3ef192b7bf', blockNumber: 14847842, chainId: 1, from: '0x642824FaB1D0141073ed74326332950bEc4701e3', gas: Big { s: 1, e: 5, c: [ 1, 6, 0, 9, 5, 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, gasPrice: Big { s: 1, e: 10, c: [ 2, 6, 5, 4, 0, 6, 2, 3, 4, 0, 4 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, hash: '0xd0befcb9d10a89aba2d488534811bf5c62a889e2499d23cdd83c2a2200cde873', input: '0xa0712d68000000000000000000000000000000000000000000000000000000000000000a', maxFeePerGas: Big { s: 1, e: 10, c: [ 4, 0, 9, 3, 6, 9, 8, 9, 6, 8 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, maxPriorityFeePerGas: Big { s: 1, e: 9, c: [ 1 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, nonce: 66, r: '0x304682f8b22006dd1347c3722f6e43a5ad8e3a1ae51939cc0d6f07981602f5c0', s: '0x207ad110eb5c014cb628814b92396785fabfbe74542293300eeadf156f50f105', to: '0x84F80EA01e26B7C11bdd241970982C7EEAb6DdcC', transactionIndex: 41, type: 2, v: 1, value: Big { s: 1, e: 16, c: [ 2 ], constructor: { [λ: Big] DP: 20, RM: 1, NE: -7, PE: 21, strict: false, roundDown: 0, roundHalfUp: 1, roundHalfEven: 2, roundUp: 3, Big: [Circular], default: [Circular] }, padAndChop: [λ] }, confirmations: 53 }
17
- * ```
18
- */
19
- function cleanTransaction(transaction) {
20
- const cleanedTransaction = {
21
- ...transaction,
22
- };
23
- Object.keys(transaction).forEach((key) => {
24
- // pending blocks have null instead of a difficulty
25
- // pending blocks have null instead of a miner address
26
- if (!transaction[key])
27
- return;
28
- switch (key) {
29
- case 'blockNumber':
30
- case 'chainId':
31
- case 'transactionIndex':
32
- case 'type':
33
- case 'v':
34
- cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
35
- break;
36
- case 'from':
37
- case 'to':
38
- if (transaction[key]) {
39
- cleanedTransaction[key] = (0, to_checksum_address_1.toChecksumAddress)(transaction[key]);
40
- }
41
- break;
42
- case 'value':
43
- case 'gas':
44
- case 'gasPrice':
45
- case 'maxFeePerGas':
46
- case 'maxPriorityFeePerGas':
47
- case 'nonce':
48
- cleanedTransaction[key] = (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
49
- break;
50
- }
51
- });
52
- return cleanedTransaction;
53
- }
54
- exports.cleanTransaction = cleanTransaction;
@@ -1,16 +0,0 @@
1
- import type { JSONABIArgument } from '../../types/Contract.types';
2
- export declare const hexFalse: string;
3
- /**
4
- *
5
- * @param jsonABIArgument
6
- * @param args
7
- * @example
8
- */
9
- export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
10
- /**
11
- * @internal
12
- * @param jsonABIArgument
13
- * @param nodeResponse
14
- * @example
15
- */
16
- export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig | (string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig)[];
@@ -1,186 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeRPCResponse = exports.encodeData = exports.hexFalse = void 0;
4
- const sha3_1 = require("sha3");
5
- const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
6
- const to_checksum_address_1 = require("../../utils/to-checksum-address");
7
- const hex_to_decimal_1 = require("./hex-to-decimal");
8
- exports.hexFalse = '0'.repeat(64);
9
- const hexTrue = '0'.repeat(63) + '1';
10
- /**
11
- * @param hex
12
- * @example
13
- */
14
- function hexToUtf8(hex) {
15
- let str = '';
16
- let i = 0;
17
- const l = hex.length;
18
- if (hex.substring(0, 2) === '0x') {
19
- i = 2;
20
- }
21
- for (; i < l; i += 2) {
22
- const code = parseInt(hex.substr(i, 2), 16);
23
- if (code === 0)
24
- continue; // Skip null bytes
25
- str += String.fromCharCode(code);
26
- }
27
- try {
28
- return decodeURIComponent(escape(str)); // Convert UTF-8 to Unicode
29
- }
30
- catch (e) {
31
- return str; // Return original string if conversion fails
32
- }
33
- }
34
- /**
35
- * Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
36
- *
37
- * @see https://ethereum.stackexchange.com/questions/43241/why-write-uint256-instead-of-uint-if-theyre-the-same-thing
38
- * @param type the type to explicitly define as 256 bits
39
- * @returns the integer type expanded to explicitly be 256 bits when possible
40
- * @example
41
- * ```javascript
42
- * expandType('uint[]');
43
- * // 'uint256[]'
44
- * ```
45
- */
46
- function expandType(type) {
47
- // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
48
- if (type === 'uint[]') {
49
- return 'uint256[]';
50
- }
51
- if (type === 'int[]') {
52
- return 'int256[]';
53
- }
54
- return type;
55
- }
56
- /**
57
- *
58
- * @param jsonABIArgument
59
- * @param args
60
- * @example
61
- */
62
- function encodeData(jsonABIArgument, args) {
63
- const hash = new sha3_1.Keccak(256);
64
- /* first 4 bytes will create the data parameter */
65
- const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
66
- // encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
67
- const functionHash = hash.update(functionString).digest('hex');
68
- // no arrays
69
- const jsonABIInputsLength = jsonABIArgument.inputs.length;
70
- let shouldValidateInputLength = true;
71
- // inputs contains 1 or more arrays
72
- if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
73
- shouldValidateInputLength = false;
74
- }
75
- if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
76
- throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
77
- }
78
- const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
79
- if (input.type.includes('[')) {
80
- // strip array and length like "[2]" from type
81
- const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1];
82
- args.forEach((arg) => {
83
- acc = acc.concat([[arg, basicType]]);
84
- });
85
- return acc;
86
- }
87
- else {
88
- return acc.concat([[args[i], input.type]]);
89
- }
90
- }, []);
91
- const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
92
- let rawArg = arg;
93
- switch (inputType) {
94
- case 'bool':
95
- return arg ? hexTrue : exports.hexFalse;
96
- case 'address':
97
- // remove leading "0x"
98
- rawArg = arg.replace(/^0x/g, '').toLowerCase();
99
- break;
100
- default:
101
- if (inputType.startsWith('bytes')) {
102
- // encode each character to hex
103
- const argEncoded = rawArg
104
- .split('')
105
- .map((character) => character.charCodeAt(0).toString(16))
106
- .join('');
107
- const paddedEncodedArg = argEncoded.padEnd(64, '0');
108
- return paddedEncodedArg;
109
- }
110
- else if (inputType === 'uint256') {
111
- const argEncoded = BigInt(arg).toString(16);
112
- const paddedEncodedArg = argEncoded.padStart(64, '0');
113
- return paddedEncodedArg;
114
- }
115
- else if (inputType.startsWith('uint')) {
116
- break;
117
- }
118
- else {
119
- throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
120
- }
121
- }
122
- const argEncoded = rawArg.toString(16);
123
- const paddedEncodedArg = argEncoded.padStart(64, '0');
124
- return paddedEncodedArg;
125
- });
126
- const functionEncoded = functionHash.slice(0, 8);
127
- const data = `0x${functionEncoded}${encodedArgs.join('')}`;
128
- return data;
129
- }
130
- exports.encodeData = encodeData;
131
- /**
132
- * @internal
133
- * @param jsonABIArgument
134
- * @param nodeResponse
135
- * @example
136
- */
137
- function decodeRPCResponse(jsonABIArgument, nodeResponse) {
138
- const rawOutputs = jsonABIArgument.outputs || [];
139
- const slicedResponse = nodeResponse.slice(2);
140
- if (rawOutputs.length === 1 && rawOutputs[0].type === 'string') {
141
- const [hexOffset, responseData] = [
142
- slicedResponse.slice(0, 64),
143
- slicedResponse.slice(64),
144
- ];
145
- const decimalOffset = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexOffset}`));
146
- const hexLength = responseData.slice(0, decimalOffset * 2);
147
- const decimalLength = Number((0, hex_to_decimal_1.hexToDecimal)(`0x${hexLength}`));
148
- const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
149
- return hexToUtf8(hexToDecode);
150
- }
151
- // chunk response every 64 characters
152
- const encodedOutputs = slicedResponse.match(/.{1,64}/g) || [];
153
- if (rawOutputs.length === 1 && rawOutputs[0].type === 'address[]') {
154
- const unformattedAddresses = encodedOutputs.slice(2);
155
- return unformattedAddresses.map((unformattedAddress) => {
156
- return (0, to_checksum_address_1.toChecksumAddress)(`0x${unformattedAddress.slice(24)}`);
157
- });
158
- }
159
- if (rawOutputs?.length === 1 && rawOutputs[0].type === 'uint256[]') {
160
- const outputs = encodedOutputs.slice(2);
161
- return outputs.map((output) => {
162
- return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
163
- });
164
- }
165
- const outputs = encodedOutputs.map((output, i) => {
166
- const outputType = rawOutputs[i].type;
167
- switch (outputType) {
168
- case 'bool':
169
- return output === hexTrue;
170
- case 'address':
171
- /* address types have 24 leading zeroes to remove */
172
- return (0, to_checksum_address_1.toChecksumAddress)(`0x${output.slice(24)}`);
173
- case 'uint256':
174
- case 'uint120':
175
- return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
176
- case 'bytes32':
177
- return `0x${output}`;
178
- case 'uint8':
179
- return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
180
- default:
181
- throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
182
- }
183
- });
184
- return outputs.length === 1 ? outputs[0] : outputs;
185
- }
186
- exports.decodeRPCResponse = decodeRPCResponse;
@@ -1,53 +0,0 @@
1
- /**
2
- * Forms the init field for http fetching
3
- *
4
- * @param body
5
- * @internal
6
- */
7
- export declare function buildFetchInit<T>(body: T): {
8
- method: string;
9
- headers: {
10
- 'Content-Type': string;
11
- };
12
- body: string;
13
- };
14
- /**
15
- * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
16
- *
17
- * @internal
18
- * @param url the URL to send the request to
19
- * @param body JSON POST body
20
- * @returns the JSON response from the server
21
- * @example
22
- * ```javascript
23
- * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
24
- * // '0x66fa8dbfd'
25
- *
26
- * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
27
- * // '0x312faeb995df61d4'
28
- * ```
29
- */
30
- export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
31
- export type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
32
- /**
33
- * Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
34
- *
35
- * @internal
36
- * @param method the RPC method to be invoked
37
- * @param params the parameters to be passed to the defined method
38
- * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
39
- * @example
40
- * ```javascript
41
- * buildRPCPostBody('eth_gasPrice', []);
42
- * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
43
- *
44
- * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
45
- * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
46
- * ```
47
- */
48
- export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
49
- jsonrpc: string;
50
- id: number;
51
- method: RPCMethodName;
52
- params: unknown[];
53
- };
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildRPCPostBody = exports.post = exports.buildFetchInit = void 0;
7
- const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
8
- /**
9
- * Forms the init field for http fetching
10
- *
11
- * @param body
12
- * @internal
13
- */
14
- function buildFetchInit(body) {
15
- return {
16
- method: 'POST',
17
- headers: {
18
- 'Content-Type': 'application/json',
19
- },
20
- body: JSON.stringify(body),
21
- };
22
- }
23
- exports.buildFetchInit = buildFetchInit;
24
- /**
25
- * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
26
- *
27
- * @internal
28
- * @param url the URL to send the request to
29
- * @param body JSON POST body
30
- * @returns the JSON response from the server
31
- * @example
32
- * ```javascript
33
- * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
34
- * // '0x66fa8dbfd'
35
- *
36
- * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
37
- * // '0x312faeb995df61d4'
38
- * ```
39
- */
40
- function post(url, body) {
41
- return (0, isomorphic_unfetch_1.default)(url, buildFetchInit(body))
42
- .then(async (r) => {
43
- const t = await r.text();
44
- try {
45
- return JSON.parse(t);
46
- }
47
- catch {
48
- throw new Error(`Invalid JSON RPC response: "${t}"`);
49
- }
50
- })
51
- .then((response) => {
52
- const result = response?.result;
53
- if (!result) {
54
- throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
55
- }
56
- return response.result;
57
- });
58
- }
59
- exports.post = post;
60
- /**
61
- * Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
62
- *
63
- * @internal
64
- * @param method the RPC method to be invoked
65
- * @param params the parameters to be passed to the defined method
66
- * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
67
- * @example
68
- * ```javascript
69
- * buildRPCPostBody('eth_gasPrice', []);
70
- * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
71
- *
72
- * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
73
- * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
74
- * ```
75
- */
76
- function buildRPCPostBody(method, params) {
77
- return {
78
- jsonrpc: '2.0',
79
- // TODO: Increment ID will be needed when websocket support is added
80
- id: 1,
81
- method,
82
- params,
83
- };
84
- }
85
- exports.buildRPCPostBody = buildRPCPostBody;
@@ -1,18 +0,0 @@
1
- /**
2
- * Converts a hexadecimal string it's decimal equivalent.
3
- * This is needed instead of parseInt because parseInt loses precision.
4
- *
5
- * @param hex the hex string to be converted to decimal
6
- * @returns a decimal value equivalent to the hex string given
7
- * @example
8
- * ```javascript
9
- * hexToDecimal('0x34');
10
- * // 52
11
- * ```
12
- * @example
13
- * ```javascript
14
- * hexToDecimal('0x628608');
15
- * // 6456840
16
- * ```
17
- */
18
- export declare function hexToDecimal(hex: string): string;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexToDecimal = void 0;
4
- /**
5
- * Converts a hexadecimal string it's decimal equivalent.
6
- * This is needed instead of parseInt because parseInt loses precision.
7
- *
8
- * @param hex the hex string to be converted to decimal
9
- * @returns a decimal value equivalent to the hex string given
10
- * @example
11
- * ```javascript
12
- * hexToDecimal('0x34');
13
- * // 52
14
- * ```
15
- * @example
16
- * ```javascript
17
- * hexToDecimal('0x628608');
18
- * // 6456840
19
- * ```
20
- */
21
- function hexToDecimal(hex) {
22
- return BigInt(hex).toString();
23
- }
24
- exports.hexToDecimal = hexToDecimal;
@@ -1,6 +0,0 @@
1
- import type { RPCTransactionRequest, TransactionRequest } from './../../types/Transaction.types';
2
- /**
3
- * @param transaction
4
- * @example
5
- */
6
- export declare function prepareTransaction(transaction: TransactionRequest): RPCTransactionRequest;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.prepareTransaction = void 0;
7
- const big_js_1 = __importDefault(require("big.js"));
8
- const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
9
- const bytes_1 = require("../../utils/bytes");
10
- /**
11
- * @param transaction
12
- * @example
13
- */
14
- function prepareTransaction(transaction) {
15
- const preparedTransaction = {
16
- ...transaction,
17
- };
18
- Object.keys(transaction).forEach((key) => {
19
- switch (key) {
20
- case 'gas':
21
- case 'gasPrice':
22
- case 'nonce':
23
- case 'maxFeePerGas':
24
- case 'maxPriorityFeePerGas':
25
- case 'value': {
26
- const value = transaction[key];
27
- if (value instanceof tiny_big_1.TinyBig) {
28
- preparedTransaction[key] = value.toHexString();
29
- }
30
- else if (value instanceof big_js_1.default) {
31
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
32
- }
33
- else if (typeof transaction[key] === 'number')
34
- preparedTransaction[key] =
35
- '0x' + transaction[key].toString(16);
36
- else
37
- preparedTransaction[key] = transaction[key].toString();
38
- break;
39
- }
40
- case 'data':
41
- preparedTransaction[key] = (0, bytes_1.hexlify)(transaction[key]);
42
- break;
43
- }
44
- });
45
- return preparedTransaction;
46
- }
47
- exports.prepareTransaction = prepareTransaction;
@@ -1,24 +0,0 @@
1
- export { BaseContract, Contract } from './classes/Contract';
2
- export { AlchemyProvider } from './providers/AlchemyProvider';
3
- export { ConstructorOptions, FallthroughProvider, } from './providers/FallthroughProvider';
4
- export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
5
- export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
6
- export { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
7
- export { ContractTypes, JSONABI, JSONABIArgument, } from './types/Contract.types';
8
- export { Filter, FilterByBlockHash } from './types/Filter.types';
9
- export { Network } from './types/Network.types';
10
- export { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse, } from './types/Transaction.types';
11
- export { arrayify, Bytes, BytesLike, BytesLikeWithNumber, concat, DataOptions, Hexable, hexConcat, hexDataLength, hexDataSlice, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, Signature, SignatureLike, stripZeros, zeroPad, } from './utils/bytes';
12
- export { computeAddress } from './utils/compute-address';
13
- export { computePublicKey } from './utils/compute-public-key';
14
- export { etherToGwei } from './utils/ether-to-gwei';
15
- export { etherToWei } from './utils/ether-to-wei';
16
- export { gweiToEther } from './utils/gwei-to-ether';
17
- export { hashMessage } from './utils/hash-message';
18
- export { isAddress } from './utils/is-address';
19
- export { keccak256 } from './utils/keccak256';
20
- export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
21
- export { splitSignature } from './utils/split-signature';
22
- export { toChecksumAddress } from './utils/to-checksum-address';
23
- export { toUtf8Bytes } from './utils/to-utf8-bytes';
24
- export { weiToEther } from './utils/wei-to-ether';
package/dist/cjs/index.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.weiToEther = exports.toUtf8Bytes = exports.toChecksumAddress = exports.splitSignature = exports.solidityKeccak256 = exports.pack = exports.keccak256 = exports.isAddress = exports.hashMessage = exports.gweiToEther = exports.etherToWei = exports.etherToGwei = exports.computePublicKey = exports.computeAddress = exports.zeroPad = exports.stripZeros = exports.isHexString = exports.isBytesLike = exports.isBytes = exports.hexZeroPad = exports.hexValue = exports.hexStripZeros = exports.hexlify = exports.hexDataSlice = exports.hexDataLength = exports.hexConcat = exports.concat = exports.arrayify = exports.TinyBig = exports.tinyBig = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.FallthroughProvider = exports.AlchemyProvider = exports.Contract = exports.BaseContract = void 0;
4
- var Contract_1 = require("./classes/Contract");
5
- Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return Contract_1.BaseContract; } });
6
- Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
7
- var AlchemyProvider_1 = require("./providers/AlchemyProvider");
8
- Object.defineProperty(exports, "AlchemyProvider", { enumerable: true, get: function () { return AlchemyProvider_1.AlchemyProvider; } });
9
- var FallthroughProvider_1 = require("./providers/FallthroughProvider");
10
- Object.defineProperty(exports, "FallthroughProvider", { enumerable: true, get: function () { return FallthroughProvider_1.FallthroughProvider; } });
11
- var JsonRpcProvider_1 = require("./providers/JsonRpcProvider");
12
- Object.defineProperty(exports, "jsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.jsonRpcProvider; } });
13
- Object.defineProperty(exports, "JsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.JsonRpcProvider; } });
14
- var tiny_big_1 = require("./shared/tiny-big/tiny-big");
15
- Object.defineProperty(exports, "tinyBig", { enumerable: true, get: function () { return tiny_big_1.tinyBig; } });
16
- Object.defineProperty(exports, "TinyBig", { enumerable: true, get: function () { return tiny_big_1.TinyBig; } });
17
- var bytes_1 = require("./utils/bytes");
18
- Object.defineProperty(exports, "arrayify", { enumerable: true, get: function () { return bytes_1.arrayify; } });
19
- Object.defineProperty(exports, "concat", { enumerable: true, get: function () { return bytes_1.concat; } });
20
- Object.defineProperty(exports, "hexConcat", { enumerable: true, get: function () { return bytes_1.hexConcat; } });
21
- Object.defineProperty(exports, "hexDataLength", { enumerable: true, get: function () { return bytes_1.hexDataLength; } });
22
- Object.defineProperty(exports, "hexDataSlice", { enumerable: true, get: function () { return bytes_1.hexDataSlice; } });
23
- Object.defineProperty(exports, "hexlify", { enumerable: true, get: function () { return bytes_1.hexlify; } });
24
- Object.defineProperty(exports, "hexStripZeros", { enumerable: true, get: function () { return bytes_1.hexStripZeros; } });
25
- Object.defineProperty(exports, "hexValue", { enumerable: true, get: function () { return bytes_1.hexValue; } });
26
- Object.defineProperty(exports, "hexZeroPad", { enumerable: true, get: function () { return bytes_1.hexZeroPad; } });
27
- Object.defineProperty(exports, "isBytes", { enumerable: true, get: function () { return bytes_1.isBytes; } });
28
- Object.defineProperty(exports, "isBytesLike", { enumerable: true, get: function () { return bytes_1.isBytesLike; } });
29
- Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return bytes_1.isHexString; } });
30
- Object.defineProperty(exports, "stripZeros", { enumerable: true, get: function () { return bytes_1.stripZeros; } });
31
- Object.defineProperty(exports, "zeroPad", { enumerable: true, get: function () { return bytes_1.zeroPad; } });
32
- var compute_address_1 = require("./utils/compute-address");
33
- Object.defineProperty(exports, "computeAddress", { enumerable: true, get: function () { return compute_address_1.computeAddress; } });
34
- var compute_public_key_1 = require("./utils/compute-public-key");
35
- Object.defineProperty(exports, "computePublicKey", { enumerable: true, get: function () { return compute_public_key_1.computePublicKey; } });
36
- var ether_to_gwei_1 = require("./utils/ether-to-gwei");
37
- Object.defineProperty(exports, "etherToGwei", { enumerable: true, get: function () { return ether_to_gwei_1.etherToGwei; } });
38
- var ether_to_wei_1 = require("./utils/ether-to-wei");
39
- Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
40
- var gwei_to_ether_1 = require("./utils/gwei-to-ether");
41
- Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
42
- var hash_message_1 = require("./utils/hash-message");
43
- Object.defineProperty(exports, "hashMessage", { enumerable: true, get: function () { return hash_message_1.hashMessage; } });
44
- var is_address_1 = require("./utils/is-address");
45
- Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
46
- var keccak256_1 = require("./utils/keccak256");
47
- Object.defineProperty(exports, "keccak256", { enumerable: true, get: function () { return keccak256_1.keccak256; } });
48
- var solidity_keccak256_1 = require("./utils/solidity-keccak256");
49
- Object.defineProperty(exports, "pack", { enumerable: true, get: function () { return solidity_keccak256_1.pack; } });
50
- Object.defineProperty(exports, "solidityKeccak256", { enumerable: true, get: function () { return solidity_keccak256_1.solidityKeccak256; } });
51
- var split_signature_1 = require("./utils/split-signature");
52
- Object.defineProperty(exports, "splitSignature", { enumerable: true, get: function () { return split_signature_1.splitSignature; } });
53
- var to_checksum_address_1 = require("./utils/to-checksum-address");
54
- Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
55
- var to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
56
- Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
57
- var wei_to_ether_1 = require("./utils/wei-to-ether");
58
- Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });