essential-eth 0.9.1 → 0.9.2-beta.1

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/essential-eth.esm.mjs +2 -0
  2. package/dist/essential-eth.esm.mjs.map +1 -0
  3. package/dist/essential-eth.js +2 -0
  4. package/dist/essential-eth.js.map +1 -0
  5. package/dist/essential-eth.modern.mjs +2 -0
  6. package/dist/essential-eth.modern.mjs.map +1 -0
  7. package/dist/essential-eth.umd.js +2 -0
  8. package/dist/essential-eth.umd.js.map +1 -0
  9. package/dist/logger/package-version.d.ts +1 -0
  10. package/package.json +12 -13
  11. package/readme.md +1 -1
  12. package/dist/cjs/classes/Contract.js +0 -138
  13. package/dist/cjs/classes/test/Contract/crv-abi.js +0 -488
  14. package/dist/cjs/classes/test/Contract/ens-abi.js +0 -453
  15. package/dist/cjs/classes/test/Contract/fei-abi.js +0 -526
  16. package/dist/cjs/classes/test/Contract/foo-abi.js +0 -42
  17. package/dist/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  18. package/dist/cjs/classes/utils/clean-block.js +0 -160
  19. package/dist/cjs/classes/utils/clean-log.js +0 -37
  20. package/dist/cjs/classes/utils/clean-transaction-receipt.js +0 -51
  21. package/dist/cjs/classes/utils/clean-transaction.js +0 -52
  22. package/dist/cjs/classes/utils/encode-decode-transaction.js +0 -177
  23. package/dist/cjs/classes/utils/fetchers.js +0 -94
  24. package/dist/cjs/classes/utils/hex-to-decimal.js +0 -24
  25. package/dist/cjs/classes/utils/prepare-transaction.js +0 -45
  26. package/dist/cjs/index.js +0 -56
  27. package/dist/cjs/index.umd.js +0 -2
  28. package/dist/cjs/index.umd.js.map +0 -1
  29. package/dist/cjs/logger/logger.js +0 -36
  30. package/dist/cjs/logger/package-version.d.ts +0 -1
  31. package/dist/cjs/logger/package-version.js +0 -5
  32. package/dist/cjs/providers/AlchemyProvider.js +0 -11
  33. package/dist/cjs/providers/BaseProvider.js +0 -549
  34. package/dist/cjs/providers/FallthroughProvider.js +0 -73
  35. package/dist/cjs/providers/JsonRpcProvider.js +0 -46
  36. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +0 -152
  37. package/dist/cjs/providers/test/mock-of.js +0 -12
  38. package/dist/cjs/providers/test/rpc-urls.js +0 -25
  39. package/dist/cjs/providers/utils/chains-info.js +0 -71
  40. package/dist/cjs/shared/tiny-big/helpers.js +0 -97
  41. package/dist/cjs/shared/tiny-big/tiny-big.js +0 -101
  42. package/dist/cjs/shared/validate-type.js +0 -9
  43. package/dist/cjs/types/Block.types.js +0 -2
  44. package/dist/cjs/types/Contract.types.js +0 -2
  45. package/dist/cjs/types/FeeData.types.js +0 -2
  46. package/dist/cjs/types/Filter.types.js +0 -2
  47. package/dist/cjs/types/Network.types.js +0 -2
  48. package/dist/cjs/types/Transaction.types.js +0 -2
  49. package/dist/cjs/utils/bytes.js +0 -711
  50. package/dist/cjs/utils/compute-address.js +0 -34
  51. package/dist/cjs/utils/compute-public-key.js +0 -26
  52. package/dist/cjs/utils/ether-to-gwei.js +0 -35
  53. package/dist/cjs/utils/ether-to-wei.js +0 -35
  54. package/dist/cjs/utils/gwei-to-ether.js +0 -35
  55. package/dist/cjs/utils/hash-message.js +0 -30
  56. package/dist/cjs/utils/is-address.js +0 -39
  57. package/dist/cjs/utils/keccak256.js +0 -31
  58. package/dist/cjs/utils/solidity-keccak256.js +0 -138
  59. package/dist/cjs/utils/split-signature.js +0 -163
  60. package/dist/cjs/utils/to-checksum-address.js +0 -46
  61. package/dist/cjs/utils/to-utf8-bytes.js +0 -21
  62. package/dist/cjs/utils/wei-to-ether.js +0 -45
  63. package/dist/esm/classes/Contract.d.ts +0 -11
  64. package/dist/esm/classes/Contract.js +0 -61
  65. package/dist/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  66. package/dist/esm/classes/test/Contract/crv-abi.js +0 -470
  67. package/dist/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  68. package/dist/esm/classes/test/Contract/ens-abi.js +0 -435
  69. package/dist/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  70. package/dist/esm/classes/test/Contract/fei-abi.js +0 -521
  71. package/dist/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  72. package/dist/esm/classes/test/Contract/foo-abi.js +0 -33
  73. package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  74. package/dist/esm/classes/test/Contract/uniswap-abi.js +0 -116
  75. package/dist/esm/classes/utils/clean-block.d.ts +0 -2
  76. package/dist/esm/classes/utils/clean-block.js +0 -35
  77. package/dist/esm/classes/utils/clean-log.d.ts +0 -2
  78. package/dist/esm/classes/utils/clean-log.js +0 -26
  79. package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +0 -2
  80. package/dist/esm/classes/utils/clean-transaction-receipt.js +0 -35
  81. package/dist/esm/classes/utils/clean-transaction.d.ts +0 -2
  82. package/dist/esm/classes/utils/clean-transaction.js +0 -34
  83. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
  84. package/dist/esm/classes/utils/encode-decode-transaction.js +0 -134
  85. package/dist/esm/classes/utils/fetchers.d.ts +0 -15
  86. package/dist/esm/classes/utils/fetchers.js +0 -46
  87. package/dist/esm/classes/utils/hex-to-decimal.d.ts +0 -1
  88. package/dist/esm/classes/utils/hex-to-decimal.js +0 -3
  89. package/dist/esm/classes/utils/prepare-transaction.d.ts +0 -2
  90. package/dist/esm/classes/utils/prepare-transaction.js +0 -34
  91. package/dist/esm/index.d.ts +0 -25
  92. package/dist/esm/index.js +0 -20
  93. package/dist/esm/logger/logger.d.ts +0 -11
  94. package/dist/esm/logger/logger.js +0 -33
  95. package/dist/esm/logger/package-version.d.ts +0 -1
  96. package/dist/esm/logger/package-version.js +0 -1
  97. package/dist/esm/providers/AlchemyProvider.d.ts +0 -4
  98. package/dist/esm/providers/AlchemyProvider.js +0 -7
  99. package/dist/esm/providers/BaseProvider.d.ts +0 -26
  100. package/dist/esm/providers/BaseProvider.js +0 -172
  101. package/dist/esm/providers/FallthroughProvider.d.ts +0 -11
  102. package/dist/esm/providers/FallthroughProvider.js +0 -49
  103. package/dist/esm/providers/JsonRpcProvider.d.ts +0 -7
  104. package/dist/esm/providers/JsonRpcProvider.js +0 -15
  105. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
  106. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +0 -142
  107. package/dist/esm/providers/test/mock-of.d.ts +0 -2
  108. package/dist/esm/providers/test/mock-of.js +0 -1
  109. package/dist/esm/providers/test/rpc-urls.d.ts +0 -12
  110. package/dist/esm/providers/test/rpc-urls.js +0 -19
  111. package/dist/esm/providers/utils/chains-info.d.ts +0 -24
  112. package/dist/esm/providers/utils/chains-info.js +0 -67
  113. package/dist/esm/shared/tiny-big/helpers.d.ts +0 -1
  114. package/dist/esm/shared/tiny-big/helpers.js +0 -58
  115. package/dist/esm/shared/tiny-big/tiny-big.d.ts +0 -10
  116. package/dist/esm/shared/tiny-big/tiny-big.js +0 -45
  117. package/dist/esm/shared/validate-type.d.ts +0 -3
  118. package/dist/esm/shared/validate-type.js +0 -5
  119. package/dist/esm/types/Block.types.d.ts +0 -40
  120. package/dist/esm/types/Block.types.js +0 -1
  121. package/dist/esm/types/Contract.types.d.ts +0 -24
  122. package/dist/esm/types/Contract.types.js +0 -1
  123. package/dist/esm/types/FeeData.types.d.ts +0 -7
  124. package/dist/esm/types/FeeData.types.js +0 -1
  125. package/dist/esm/types/Filter.types.d.ts +0 -12
  126. package/dist/esm/types/Filter.types.js +0 -1
  127. package/dist/esm/types/Network.types.d.ts +0 -5
  128. package/dist/esm/types/Network.types.js +0 -1
  129. package/dist/esm/types/Transaction.types.d.ts +0 -113
  130. package/dist/esm/types/Transaction.types.js +0 -1
  131. package/dist/esm/utils/bytes.d.ts +0 -40
  132. package/dist/esm/utils/bytes.js +0 -245
  133. package/dist/esm/utils/compute-address.d.ts +0 -1
  134. package/dist/esm/utils/compute-address.js +0 -12
  135. package/dist/esm/utils/compute-public-key.d.ts +0 -2
  136. package/dist/esm/utils/compute-public-key.js +0 -6
  137. package/dist/esm/utils/ether-to-gwei.d.ts +0 -3
  138. package/dist/esm/utils/ether-to-gwei.js +0 -7
  139. package/dist/esm/utils/ether-to-wei.d.ts +0 -3
  140. package/dist/esm/utils/ether-to-wei.js +0 -7
  141. package/dist/esm/utils/gwei-to-ether.d.ts +0 -3
  142. package/dist/esm/utils/gwei-to-ether.js +0 -7
  143. package/dist/esm/utils/hash-message.d.ts +0 -2
  144. package/dist/esm/utils/hash-message.js +0 -14
  145. package/dist/esm/utils/is-address.d.ts +0 -1
  146. package/dist/esm/utils/is-address.js +0 -12
  147. package/dist/esm/utils/keccak256.d.ts +0 -2
  148. package/dist/esm/utils/keccak256.js +0 -13
  149. package/dist/esm/utils/solidity-keccak256.d.ts +0 -2
  150. package/dist/esm/utils/solidity-keccak256.js +0 -85
  151. package/dist/esm/utils/split-signature.d.ts +0 -2
  152. package/dist/esm/utils/split-signature.js +0 -126
  153. package/dist/esm/utils/to-checksum-address.d.ts +0 -1
  154. package/dist/esm/utils/to-checksum-address.js +0 -25
  155. package/dist/esm/utils/to-utf8-bytes.d.ts +0 -1
  156. package/dist/esm/utils/to-utf8-bytes.js +0 -3
  157. package/dist/esm/utils/wei-to-ether.d.ts +0 -3
  158. package/dist/esm/utils/wei-to-ether.js +0 -16
  159. /package/dist/{cjs/classes → classes}/Contract.d.ts +0 -0
  160. /package/dist/{cjs/classes → classes}/test/Contract/crv-abi.d.ts +0 -0
  161. /package/dist/{cjs/classes → classes}/test/Contract/ens-abi.d.ts +0 -0
  162. /package/dist/{cjs/classes → classes}/test/Contract/fei-abi.d.ts +0 -0
  163. /package/dist/{cjs/classes → classes}/test/Contract/foo-abi.d.ts +0 -0
  164. /package/dist/{cjs/classes → classes}/test/Contract/uniswap-abi.d.ts +0 -0
  165. /package/dist/{cjs/classes → classes}/utils/clean-block.d.ts +0 -0
  166. /package/dist/{cjs/classes → classes}/utils/clean-log.d.ts +0 -0
  167. /package/dist/{cjs/classes → classes}/utils/clean-transaction-receipt.d.ts +0 -0
  168. /package/dist/{cjs/classes → classes}/utils/clean-transaction.d.ts +0 -0
  169. /package/dist/{cjs/classes → classes}/utils/encode-decode-transaction.d.ts +0 -0
  170. /package/dist/{cjs/classes → classes}/utils/fetchers.d.ts +0 -0
  171. /package/dist/{cjs/classes → classes}/utils/hex-to-decimal.d.ts +0 -0
  172. /package/dist/{cjs/classes → classes}/utils/prepare-transaction.d.ts +0 -0
  173. /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  174. /package/dist/{cjs/logger → logger}/logger.d.ts +0 -0
  175. /package/dist/{cjs/providers → providers}/AlchemyProvider.d.ts +0 -0
  176. /package/dist/{cjs/providers → providers}/BaseProvider.d.ts +0 -0
  177. /package/dist/{cjs/providers → providers}/FallthroughProvider.d.ts +0 -0
  178. /package/dist/{cjs/providers → providers}/JsonRpcProvider.d.ts +0 -0
  179. /package/dist/{cjs/providers → providers}/test/json-rpc-provider/get-logs/mocks.d.ts +0 -0
  180. /package/dist/{cjs/providers → providers}/test/mock-of.d.ts +0 -0
  181. /package/dist/{cjs/providers → providers}/test/rpc-urls.d.ts +0 -0
  182. /package/dist/{cjs/providers → providers}/utils/chains-info.d.ts +0 -0
  183. /package/dist/{cjs/shared → shared}/tiny-big/helpers.d.ts +0 -0
  184. /package/dist/{cjs/shared → shared}/tiny-big/tiny-big.d.ts +0 -0
  185. /package/dist/{cjs/shared → shared}/validate-type.d.ts +0 -0
  186. /package/dist/{cjs/types → types}/Block.types.d.ts +0 -0
  187. /package/dist/{cjs/types → types}/Contract.types.d.ts +0 -0
  188. /package/dist/{cjs/types → types}/FeeData.types.d.ts +0 -0
  189. /package/dist/{cjs/types → types}/Filter.types.d.ts +0 -0
  190. /package/dist/{cjs/types → types}/Network.types.d.ts +0 -0
  191. /package/dist/{cjs/types → types}/Transaction.types.d.ts +0 -0
  192. /package/dist/{cjs/utils → utils}/bytes.d.ts +0 -0
  193. /package/dist/{cjs/utils → utils}/compute-address.d.ts +0 -0
  194. /package/dist/{cjs/utils → utils}/compute-public-key.d.ts +0 -0
  195. /package/dist/{cjs/utils → utils}/ether-to-gwei.d.ts +0 -0
  196. /package/dist/{cjs/utils → utils}/ether-to-wei.d.ts +0 -0
  197. /package/dist/{cjs/utils → utils}/gwei-to-ether.d.ts +0 -0
  198. /package/dist/{cjs/utils → utils}/hash-message.d.ts +0 -0
  199. /package/dist/{cjs/utils → utils}/is-address.d.ts +0 -0
  200. /package/dist/{cjs/utils → utils}/keccak256.d.ts +0 -0
  201. /package/dist/{cjs/utils → utils}/solidity-keccak256.d.ts +0 -0
  202. /package/dist/{cjs/utils → utils}/split-signature.d.ts +0 -0
  203. /package/dist/{cjs/utils → utils}/to-checksum-address.d.ts +0 -0
  204. /package/dist/{cjs/utils → utils}/to-utf8-bytes.d.ts +0 -0
  205. /package/dist/{cjs/utils → utils}/wei-to-ether.d.ts +0 -0
@@ -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 = Object.assign({}, 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,26 +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 = Object.assign({}, log);
5
- Object.keys(log).forEach((key) => {
6
- switch (key) {
7
- case 'address':
8
- cleanedLog[key] = toChecksumAddress(log[key]);
9
- break;
10
- case 'blockNumber':
11
- case 'logIndex':
12
- case 'transactionIndex':
13
- cleanedLog[key] = Number(hexToDecimal(log[key]));
14
- break;
15
- case 'removed':
16
- if (receiptLog) {
17
- delete cleanedLog[key];
18
- }
19
- else if (log[key] == null) {
20
- cleanedLog[key] === false;
21
- }
22
- break;
23
- }
24
- });
25
- return cleanedLog;
26
- }
@@ -1,2 +0,0 @@
1
- import type { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
2
- export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
@@ -1,35 +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 = Object.assign({}, cleanedTransaction);
9
- Object.keys(transactionReceipt).forEach((key) => {
10
- if (!transactionReceipt[key])
11
- return;
12
- switch (key) {
13
- case 'status':
14
- cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
15
- break;
16
- case 'contractAddress':
17
- if (transactionReceipt[key]) {
18
- cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
19
- }
20
- break;
21
- case 'cumulativeGasUsed':
22
- case 'effectiveGasPrice':
23
- case 'gasUsed':
24
- cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
25
- break;
26
- case 'logs':
27
- transactionReceipt[key].forEach((log, index) => {
28
- cleanedTransactionReceipt[key][index] = cleanLog(log, true);
29
- });
30
- }
31
- });
32
- cleanedTransactionReceipt.byzantium =
33
- cleanedTransactionReceipt.blockNumber >= 4370000;
34
- return cleanedTransactionReceipt;
35
- }
@@ -1,2 +0,0 @@
1
- import type { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
2
- export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
@@ -1,34 +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 = Object.assign({}, transaction);
6
- Object.keys(transaction).forEach((key) => {
7
- if (!transaction[key])
8
- return;
9
- switch (key) {
10
- case 'blockNumber':
11
- case 'chainId':
12
- case 'transactionIndex':
13
- case 'type':
14
- case 'v':
15
- cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
16
- break;
17
- case 'from':
18
- case 'to':
19
- if (transaction[key]) {
20
- cleanedTransaction[key] = toChecksumAddress(transaction[key]);
21
- }
22
- break;
23
- case 'value':
24
- case 'gas':
25
- case 'gasPrice':
26
- case 'maxFeePerGas':
27
- case 'maxPriorityFeePerGas':
28
- case 'nonce':
29
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
30
- break;
31
- }
32
- });
33
- return cleanedTransaction;
34
- }
@@ -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,134 +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
- else 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
- var _a;
50
- if (input.type.includes('[')) {
51
- const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
52
- args.forEach((arg) => {
53
- acc = acc.concat([[arg, basicType]]);
54
- });
55
- return acc;
56
- }
57
- else {
58
- return acc.concat([[args[i], input.type]]);
59
- }
60
- }, []);
61
- const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
62
- let rawArg = arg;
63
- switch (inputType) {
64
- case 'bool':
65
- return arg ? hexTrue : hexFalse;
66
- case 'address':
67
- rawArg = arg.replace(/^0x/g, '').toLowerCase();
68
- break;
69
- default:
70
- if (inputType.startsWith('bytes')) {
71
- const argEncoded = rawArg
72
- .split('')
73
- .map((character) => character.charCodeAt(0).toString(16))
74
- .join('');
75
- const paddedEncodedArg = argEncoded.padEnd(64, '0');
76
- return paddedEncodedArg;
77
- }
78
- else if (inputType === 'uint256') {
79
- const argEncoded = BigInt(arg).toString(16);
80
- const paddedEncodedArg = argEncoded.padStart(64, '0');
81
- return paddedEncodedArg;
82
- }
83
- else if (inputType.startsWith('uint')) {
84
- break;
85
- }
86
- else {
87
- throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
88
- }
89
- }
90
- const argEncoded = rawArg.toString(16);
91
- const paddedEncodedArg = argEncoded.padStart(64, '0');
92
- return paddedEncodedArg;
93
- });
94
- const functionEncoded = functionHash.slice(0, 8);
95
- const data = `0x${functionEncoded}${encodedArgs.join('')}`;
96
- return data;
97
- }
98
- export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
99
- var _a;
100
- const rawOutputs = jsonABIArgument.outputs;
101
- const slicedResponse = nodeResponse.slice(2);
102
- if (((_a = jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : jsonABIArgument.outputs) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
103
- jsonABIArgument.outputs[0].type === 'string') {
104
- const [hexOffset, responseData] = [
105
- slicedResponse.slice(0, 64),
106
- slicedResponse.slice(64),
107
- ];
108
- const decimalOffset = Number(hexToDecimal(`0x${hexOffset}`));
109
- const hexLength = responseData.slice(0, decimalOffset * 2);
110
- const decimalLength = Number(hexToDecimal(`0x${hexLength}`));
111
- const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
112
- return hexToUtf8(hexToDecode);
113
- }
114
- const encodedOutputs = slicedResponse.match(/.{1,64}/g);
115
- const outputs = (encodedOutputs || []).map((output, i) => {
116
- const outputType = (rawOutputs || [])[i].type;
117
- switch (outputType) {
118
- case 'bool':
119
- return output === hexTrue;
120
- case 'address':
121
- return toChecksumAddress(`0x${output.slice(24)}`);
122
- case 'uint256':
123
- case 'uint120':
124
- return tinyBig(hexToDecimal(`0x${output}`));
125
- case 'bytes32':
126
- return `0x${output}`;
127
- case 'uint8':
128
- return Number(hexToDecimal(`0x${output}`));
129
- default:
130
- throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
131
- }
132
- });
133
- return outputs.length === 1 ? outputs[0] : outputs;
134
- }
@@ -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,46 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import unfetch from 'isomorphic-unfetch';
11
- export function buildFetchInit(body) {
12
- return {
13
- method: 'POST',
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- },
17
- body: JSON.stringify(body),
18
- };
19
- }
20
- export function post(url, body) {
21
- return unfetch(url, buildFetchInit(body))
22
- .then((r) => __awaiter(this, void 0, void 0, function* () {
23
- const t = yield r.text();
24
- try {
25
- return JSON.parse(t);
26
- }
27
- catch (_a) {
28
- throw new Error(`Invalid JSON RPC response: "${t}"`);
29
- }
30
- }))
31
- .then((response) => {
32
- const result = response === null || response === void 0 ? void 0 : response.result;
33
- if (!result) {
34
- throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
35
- }
36
- return response.result;
37
- });
38
- }
39
- export function buildRPCPostBody(method, params) {
40
- return {
41
- jsonrpc: '2.0',
42
- id: 1,
43
- method,
44
- params,
45
- };
46
- }
@@ -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,34 +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 = Object.assign({}, transaction);
6
- Object.keys(transaction).forEach((key) => {
7
- switch (key) {
8
- case 'gas':
9
- case 'gasPrice':
10
- case 'nonce':
11
- case 'maxFeePerGas':
12
- case 'maxPriorityFeePerGas':
13
- case 'value': {
14
- const value = transaction[key];
15
- if (value instanceof TinyBig) {
16
- preparedTransaction[key] = value.toHexString();
17
- }
18
- else if (value instanceof Big) {
19
- preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
20
- }
21
- else if (typeof transaction[key] === 'number')
22
- preparedTransaction[key] =
23
- '0x' + transaction[key].toString(16);
24
- else
25
- preparedTransaction[key] = transaction[key].toString();
26
- break;
27
- }
28
- case 'data':
29
- preparedTransaction[key] = hexlify(transaction[key]);
30
- break;
31
- }
32
- });
33
- return preparedTransaction;
34
- }
@@ -1,25 +0,0 @@
1
- export { Contract, BaseContract } from './classes/Contract';
2
- export { AlchemyProvider } from './providers/AlchemyProvider';
3
- export { FallthroughProvider, ConstructorOptions, } from './providers/FallthroughProvider';
4
- export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
5
- export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
6
- export { BlockResponse, RPCBlock, BlockTag } 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 { TransactionResponse, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, RPCLog, Log, BlockTransactionResponse, } from './types/Transaction.types';
11
- export { computeAddress } from './utils/compute-address';
12
- export { computePublicKey } from './utils/compute-public-key';
13
- export { etherToGwei } from './utils/ether-to-gwei';
14
- export { etherToWei } from './utils/ether-to-wei';
15
- export { gweiToEther } from './utils/gwei-to-ether';
16
- export { hashMessage } from './utils/hash-message';
17
- export { isAddress } from './utils/is-address';
18
- export { splitSignature } from './utils/split-signature';
19
- export { toChecksumAddress } from './utils/to-checksum-address';
20
- export { toUtf8Bytes } from './utils/to-utf8-bytes';
21
- export { weiToEther } from './utils/wei-to-ether';
22
- export * from './utils/bytes';
23
- export * from './utils/hash-message';
24
- export * from './utils/keccak256';
25
- export * from './utils/solidity-keccak256';
package/dist/esm/index.js DELETED
@@ -1,20 +0,0 @@
1
- export { Contract, BaseContract } 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 { computeAddress } from './utils/compute-address';
7
- export { computePublicKey } from './utils/compute-public-key';
8
- export { etherToGwei } from './utils/ether-to-gwei';
9
- export { etherToWei } from './utils/ether-to-wei';
10
- export { gweiToEther } from './utils/gwei-to-ether';
11
- export { hashMessage } from './utils/hash-message';
12
- export { isAddress } from './utils/is-address';
13
- export { splitSignature } from './utils/split-signature';
14
- export { toChecksumAddress } from './utils/to-checksum-address';
15
- export { toUtf8Bytes } from './utils/to-utf8-bytes';
16
- export { weiToEther } from './utils/wei-to-ether';
17
- export * from './utils/bytes';
18
- export * from './utils/hash-message';
19
- export * from './utils/keccak256';
20
- export * from './utils/solidity-keccak256';
@@ -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,33 +0,0 @@
1
- import { version } from './package-version';
2
- class Logger {
3
- constructor() {
4
- this.packageVersion = version;
5
- }
6
- throwError(message, args) {
7
- const argsLength = Object.keys(args).length;
8
- throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
9
- }
10
- throwArgumentError(message, arg, value) {
11
- throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
12
- }
13
- checkSafeUint53(value, message = 'value not safe') {
14
- if (typeof value !== 'number') {
15
- return;
16
- }
17
- if (value < 0 || value >= 0x1fffffffffffff) {
18
- this.throwError(message, {
19
- operation: 'checkSafeInteger',
20
- fault: 'out-of-safe-range',
21
- value: value,
22
- });
23
- }
24
- if (value % 1) {
25
- this.throwError(message, {
26
- operation: 'checkSafeInteger',
27
- fault: 'non-integer',
28
- value: value,
29
- });
30
- }
31
- }
32
- }
33
- export const logger = new Logger();
@@ -1 +0,0 @@
1
- export declare const version = "0.9.1";
@@ -1 +0,0 @@
1
- export const version = '0.9.1';
@@ -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
- }