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,35 +0,0 @@
1
- import { tinyBig } from '../../shared/tiny-big/tiny-big';
2
- import { toChecksumAddress } from '../../utils/to-checksum-address';
3
- import { cleanTransaction } from './clean-transaction';
4
- import { hexToDecimal } from './hex-to-decimal';
5
- export function cleanBlock(block, returnTransactionObjects) {
6
- const cleanedBlock = { ...block };
7
- Object.keys(block).forEach((key) => {
8
- if (!block[key])
9
- return;
10
- switch (key) {
11
- case 'difficulty':
12
- case 'totalDifficulty':
13
- case 'gasLimit':
14
- case 'gasUsed':
15
- case 'size':
16
- case 'timestamp':
17
- case 'baseFeePerGas':
18
- cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
19
- break;
20
- case 'number':
21
- cleanedBlock[key] = Number(hexToDecimal(block[key]));
22
- break;
23
- case 'miner':
24
- cleanedBlock[key] = toChecksumAddress(block[key]);
25
- break;
26
- }
27
- });
28
- if (returnTransactionObjects) {
29
- const txns = block.transactions;
30
- txns.forEach((transaction, index) => {
31
- cleanedBlock.transactions[index] = cleanTransaction(transaction);
32
- });
33
- }
34
- return cleanedBlock;
35
- }
@@ -1,2 +0,0 @@
1
- import type { Log, RPCLog } from './../../types/Transaction.types';
2
- export declare function cleanLog(log: RPCLog, receiptLog: boolean): Log;
@@ -1,28 +0,0 @@
1
- import { toChecksumAddress } from '../../utils/to-checksum-address';
2
- import { hexToDecimal } from './hex-to-decimal';
3
- export function cleanLog(log, receiptLog) {
4
- const cleanedLog = {
5
- ...log,
6
- };
7
- Object.keys(log).forEach((key) => {
8
- switch (key) {
9
- case 'address':
10
- cleanedLog[key] = toChecksumAddress(log[key]);
11
- break;
12
- case 'blockNumber':
13
- case 'logIndex':
14
- case 'transactionIndex':
15
- cleanedLog[key] = Number(hexToDecimal(log[key]));
16
- break;
17
- case 'removed':
18
- if (receiptLog) {
19
- delete cleanedLog[key];
20
- }
21
- else if (log[key] == null) {
22
- cleanedLog[key] === false;
23
- }
24
- break;
25
- }
26
- });
27
- return cleanedLog;
28
- }
@@ -1,2 +0,0 @@
1
- import type { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
2
- export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
@@ -1,37 +0,0 @@
1
- import { tinyBig } from '../../shared/tiny-big/tiny-big';
2
- import { toChecksumAddress } from '../../utils/to-checksum-address';
3
- import { cleanLog } from './clean-log';
4
- import { cleanTransaction } from './clean-transaction';
5
- import { hexToDecimal } from './hex-to-decimal';
6
- export function cleanTransactionReceipt(transactionReceipt) {
7
- const cleanedTransaction = cleanTransaction(transactionReceipt);
8
- const cleanedTransactionReceipt = {
9
- ...cleanedTransaction,
10
- };
11
- Object.keys(transactionReceipt).forEach((key) => {
12
- if (!transactionReceipt[key])
13
- return;
14
- switch (key) {
15
- case 'status':
16
- cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
17
- break;
18
- case 'contractAddress':
19
- if (transactionReceipt[key]) {
20
- cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
21
- }
22
- break;
23
- case 'cumulativeGasUsed':
24
- case 'effectiveGasPrice':
25
- case 'gasUsed':
26
- cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
27
- break;
28
- case 'logs':
29
- transactionReceipt[key].forEach((log, index) => {
30
- cleanedTransactionReceipt[key][index] = cleanLog(log, true);
31
- });
32
- }
33
- });
34
- cleanedTransactionReceipt.byzantium =
35
- cleanedTransactionReceipt.blockNumber >= 4370000;
36
- return cleanedTransactionReceipt;
37
- }
@@ -1,2 +0,0 @@
1
- import type { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
2
- export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
@@ -1,36 +0,0 @@
1
- import { tinyBig } from '../../shared/tiny-big/tiny-big';
2
- import { toChecksumAddress } from '../../utils/to-checksum-address';
3
- import { hexToDecimal } from './hex-to-decimal';
4
- export function cleanTransaction(transaction) {
5
- const cleanedTransaction = {
6
- ...transaction,
7
- };
8
- Object.keys(transaction).forEach((key) => {
9
- if (!transaction[key])
10
- return;
11
- switch (key) {
12
- case 'blockNumber':
13
- case 'chainId':
14
- case 'transactionIndex':
15
- case 'type':
16
- case 'v':
17
- cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
18
- break;
19
- case 'from':
20
- case 'to':
21
- if (transaction[key]) {
22
- cleanedTransaction[key] = toChecksumAddress(transaction[key]);
23
- }
24
- break;
25
- case 'value':
26
- case 'gas':
27
- case 'gasPrice':
28
- case 'maxFeePerGas':
29
- case 'maxPriorityFeePerGas':
30
- case 'nonce':
31
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
32
- break;
33
- }
34
- });
35
- return cleanedTransaction;
36
- }
@@ -1,4 +0,0 @@
1
- import type { JSONABIArgument } from '../../types/Contract.types';
2
- export declare const hexFalse: string;
3
- export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
4
- 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,143 +0,0 @@
1
- import { Keccak } from 'sha3';
2
- import { tinyBig } from '../../shared/tiny-big/tiny-big';
3
- import { toChecksumAddress } from '../../utils/to-checksum-address';
4
- import { hexToDecimal } from './hex-to-decimal';
5
- export const hexFalse = '0'.repeat(64);
6
- const hexTrue = '0'.repeat(63) + '1';
7
- function hexToUtf8(hex) {
8
- let str = '';
9
- let i = 0;
10
- const l = hex.length;
11
- if (hex.substring(0, 2) === '0x') {
12
- i = 2;
13
- }
14
- for (; i < l; i += 2) {
15
- const code = parseInt(hex.substr(i, 2), 16);
16
- if (code === 0)
17
- continue;
18
- str += String.fromCharCode(code);
19
- }
20
- try {
21
- return decodeURIComponent(escape(str));
22
- }
23
- catch (e) {
24
- return str;
25
- }
26
- }
27
- function expandType(type) {
28
- if (type === 'uint[]') {
29
- return 'uint256[]';
30
- }
31
- if (type === 'int[]') {
32
- return 'int256[]';
33
- }
34
- return type;
35
- }
36
- export function encodeData(jsonABIArgument, args) {
37
- const hash = new Keccak(256);
38
- const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
39
- const functionHash = hash.update(functionString).digest('hex');
40
- const jsonABIInputsLength = jsonABIArgument.inputs.length;
41
- let shouldValidateInputLength = true;
42
- if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
43
- shouldValidateInputLength = false;
44
- }
45
- if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
46
- throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
47
- }
48
- const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
49
- if (input.type.includes('[')) {
50
- const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1];
51
- args.forEach((arg) => {
52
- acc = acc.concat([[arg, basicType]]);
53
- });
54
- return acc;
55
- }
56
- else {
57
- return acc.concat([[args[i], input.type]]);
58
- }
59
- }, []);
60
- const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
61
- let rawArg = arg;
62
- switch (inputType) {
63
- case 'bool':
64
- return arg ? hexTrue : hexFalse;
65
- case 'address':
66
- rawArg = arg.replace(/^0x/g, '').toLowerCase();
67
- break;
68
- default:
69
- if (inputType.startsWith('bytes')) {
70
- const argEncoded = rawArg
71
- .split('')
72
- .map((character) => character.charCodeAt(0).toString(16))
73
- .join('');
74
- const paddedEncodedArg = argEncoded.padEnd(64, '0');
75
- return paddedEncodedArg;
76
- }
77
- else if (inputType === 'uint256') {
78
- const argEncoded = BigInt(arg).toString(16);
79
- const paddedEncodedArg = argEncoded.padStart(64, '0');
80
- return paddedEncodedArg;
81
- }
82
- else if (inputType.startsWith('uint')) {
83
- break;
84
- }
85
- else {
86
- throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
87
- }
88
- }
89
- const argEncoded = rawArg.toString(16);
90
- const paddedEncodedArg = argEncoded.padStart(64, '0');
91
- return paddedEncodedArg;
92
- });
93
- const functionEncoded = functionHash.slice(0, 8);
94
- const data = `0x${functionEncoded}${encodedArgs.join('')}`;
95
- return data;
96
- }
97
- export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
98
- const rawOutputs = jsonABIArgument.outputs || [];
99
- const slicedResponse = nodeResponse.slice(2);
100
- if (rawOutputs.length === 1 && rawOutputs[0].type === 'string') {
101
- const [hexOffset, responseData] = [
102
- slicedResponse.slice(0, 64),
103
- slicedResponse.slice(64),
104
- ];
105
- const decimalOffset = Number(hexToDecimal(`0x${hexOffset}`));
106
- const hexLength = responseData.slice(0, decimalOffset * 2);
107
- const decimalLength = Number(hexToDecimal(`0x${hexLength}`));
108
- const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
109
- return hexToUtf8(hexToDecode);
110
- }
111
- const encodedOutputs = slicedResponse.match(/.{1,64}/g) || [];
112
- if (rawOutputs.length === 1 && rawOutputs[0].type === 'address[]') {
113
- const unformattedAddresses = encodedOutputs.slice(2);
114
- return unformattedAddresses.map((unformattedAddress) => {
115
- return toChecksumAddress(`0x${unformattedAddress.slice(24)}`);
116
- });
117
- }
118
- if (rawOutputs?.length === 1 && rawOutputs[0].type === 'uint256[]') {
119
- const outputs = encodedOutputs.slice(2);
120
- return outputs.map((output) => {
121
- return tinyBig(hexToDecimal(`0x${output}`));
122
- });
123
- }
124
- const outputs = encodedOutputs.map((output, i) => {
125
- const outputType = rawOutputs[i].type;
126
- switch (outputType) {
127
- case 'bool':
128
- return output === hexTrue;
129
- case 'address':
130
- return toChecksumAddress(`0x${output.slice(24)}`);
131
- case 'uint256':
132
- case 'uint120':
133
- return tinyBig(hexToDecimal(`0x${output}`));
134
- case 'bytes32':
135
- return `0x${output}`;
136
- case 'uint8':
137
- return Number(hexToDecimal(`0x${output}`));
138
- default:
139
- throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
140
- }
141
- });
142
- return outputs.length === 1 ? outputs[0] : outputs;
143
- }
@@ -1,15 +0,0 @@
1
- export declare function buildFetchInit<T>(body: T): {
2
- method: string;
3
- headers: {
4
- 'Content-Type': string;
5
- };
6
- body: string;
7
- };
8
- export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
9
- 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';
10
- export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
11
- jsonrpc: string;
12
- id: number;
13
- method: RPCMethodName;
14
- params: unknown[];
15
- };
@@ -1,37 +0,0 @@
1
- import unfetch from 'isomorphic-unfetch';
2
- export function buildFetchInit(body) {
3
- return {
4
- method: 'POST',
5
- headers: {
6
- 'Content-Type': 'application/json',
7
- },
8
- body: JSON.stringify(body),
9
- };
10
- }
11
- export function post(url, body) {
12
- return unfetch(url, buildFetchInit(body))
13
- .then(async (r) => {
14
- const t = await r.text();
15
- try {
16
- return JSON.parse(t);
17
- }
18
- catch {
19
- throw new Error(`Invalid JSON RPC response: "${t}"`);
20
- }
21
- })
22
- .then((response) => {
23
- const result = response?.result;
24
- if (!result) {
25
- throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
26
- }
27
- return response.result;
28
- });
29
- }
30
- export function buildRPCPostBody(method, params) {
31
- return {
32
- jsonrpc: '2.0',
33
- id: 1,
34
- method,
35
- params,
36
- };
37
- }
@@ -1 +0,0 @@
1
- export declare function hexToDecimal(hex: string): string;
@@ -1,3 +0,0 @@
1
- export function hexToDecimal(hex) {
2
- return BigInt(hex).toString();
3
- }
@@ -1,2 +0,0 @@
1
- import type { RPCTransactionRequest, TransactionRequest } from './../../types/Transaction.types';
2
- export declare function prepareTransaction(transaction: TransactionRequest): RPCTransactionRequest;
@@ -1,36 +0,0 @@
1
- import Big from 'big.js';
2
- import { TinyBig } from '../../shared/tiny-big/tiny-big';
3
- import { hexlify } from '../../utils/bytes';
4
- export function prepareTransaction(transaction) {
5
- const preparedTransaction = {
6
- ...transaction,
7
- };
8
- Object.keys(transaction).forEach((key) => {
9
- switch (key) {
10
- case 'gas':
11
- case 'gasPrice':
12
- case 'nonce':
13
- case 'maxFeePerGas':
14
- case 'maxPriorityFeePerGas':
15
- case 'value': {
16
- const value = transaction[key];
17
- if (value instanceof TinyBig) {
18
- preparedTransaction[key] = value.toHexString();
19
- }
20
- else if (value instanceof Big) {
21
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
22
- }
23
- else if (typeof transaction[key] === 'number')
24
- preparedTransaction[key] =
25
- '0x' + transaction[key].toString(16);
26
- else
27
- preparedTransaction[key] = transaction[key].toString();
28
- break;
29
- }
30
- case 'data':
31
- preparedTransaction[key] = hexlify(transaction[key]);
32
- break;
33
- }
34
- });
35
- return preparedTransaction;
36
- }
@@ -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/esm/index.js DELETED
@@ -1,19 +0,0 @@
1
- export { BaseContract, Contract } from './classes/Contract';
2
- export { AlchemyProvider } from './providers/AlchemyProvider';
3
- export { FallthroughProvider, } from './providers/FallthroughProvider';
4
- export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
5
- export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
6
- export { arrayify, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, stripZeros, zeroPad, } from './utils/bytes';
7
- export { computeAddress } from './utils/compute-address';
8
- export { computePublicKey } from './utils/compute-public-key';
9
- export { etherToGwei } from './utils/ether-to-gwei';
10
- export { etherToWei } from './utils/ether-to-wei';
11
- export { gweiToEther } from './utils/gwei-to-ether';
12
- export { hashMessage } from './utils/hash-message';
13
- export { isAddress } from './utils/is-address';
14
- export { keccak256 } from './utils/keccak256';
15
- export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
16
- export { splitSignature } from './utils/split-signature';
17
- export { toChecksumAddress } from './utils/to-checksum-address';
18
- export { toUtf8Bytes } from './utils/to-utf8-bytes';
19
- export { weiToEther } from './utils/wei-to-ether';
@@ -1,11 +0,0 @@
1
- declare class Logger {
2
- private packageVersion;
3
- constructor();
4
- throwError(message: string, args: {
5
- [key: string]: any;
6
- }): never;
7
- throwArgumentError(message: string, arg: string, value: any): never;
8
- checkSafeUint53(value: number, message?: string): void;
9
- }
10
- export declare const logger: Logger;
11
- export {};
@@ -1,34 +0,0 @@
1
- import { version } from './package-version';
2
- class Logger {
3
- packageVersion;
4
- constructor() {
5
- this.packageVersion = version;
6
- }
7
- throwError(message, args) {
8
- const argsLength = Object.keys(args).length;
9
- throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
10
- }
11
- throwArgumentError(message, arg, value) {
12
- throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
13
- }
14
- checkSafeUint53(value, message = 'value not safe') {
15
- if (typeof value !== 'number') {
16
- return;
17
- }
18
- if (value < 0 || value >= 0x1fffffffffffff) {
19
- this.throwError(message, {
20
- operation: 'checkSafeInteger',
21
- fault: 'out-of-safe-range',
22
- value: value,
23
- });
24
- }
25
- if (value % 1) {
26
- this.throwError(message, {
27
- operation: 'checkSafeInteger',
28
- fault: 'non-integer',
29
- value: value,
30
- });
31
- }
32
- }
33
- }
34
- export const logger = new Logger();
@@ -1 +0,0 @@
1
- export declare const version = "0.10.2";
@@ -1 +0,0 @@
1
- export const version = '0.10.2';
@@ -1,4 +0,0 @@
1
- import { JsonRpcProvider } from './JsonRpcProvider';
2
- export declare class AlchemyProvider extends JsonRpcProvider {
3
- constructor(apiKey: string, network?: string);
4
- }
@@ -1,7 +0,0 @@
1
- import { JsonRpcProvider } from './JsonRpcProvider';
2
- export class AlchemyProvider extends JsonRpcProvider {
3
- constructor(apiKey, network = 'mainnet') {
4
- const alchemyUrl = `https://eth-${network}.alchemyapi.io/v2/${apiKey}`;
5
- super(alchemyUrl);
6
- }
7
- }
@@ -1,26 +0,0 @@
1
- import type { TinyBig } from '../shared/tiny-big/tiny-big';
2
- import type { BlockResponse, BlockTag } from '../types/Block.types';
3
- import type { FeeData } from '../types/FeeData.types';
4
- import type { Filter, FilterByBlockHash } from '../types/Filter.types';
5
- import type { Network } from '../types/Network.types';
6
- import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
7
- export declare abstract class BaseProvider {
8
- abstract selectRpcUrl(): string;
9
- abstract post(body: Record<string, unknown>): Promise<any>;
10
- readonly _rpcUrls: string[];
11
- protected _post: (body: Record<string, unknown>) => Promise<any>;
12
- constructor(rpcUrls: string[]);
13
- getNetwork(): Promise<Network>;
14
- getBlockNumber(): Promise<number>;
15
- getTransaction(transactionHash: string): Promise<TransactionResponse>;
16
- getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
17
- getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
18
- getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
19
- getGasPrice(): Promise<TinyBig>;
20
- getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
21
- getCode(address: string, blockTag?: BlockTag): Promise<string>;
22
- estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
23
- getFeeData(): Promise<FeeData>;
24
- getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
25
- call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
26
- }