essential-eth 0.5.6 → 0.5.10-next.2

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 (196) hide show
  1. package/{lib/esm → dist}/classes/Contract.d.ts +11 -11
  2. package/dist/classes/test/Contract/crv-abi.d.ts +2 -0
  3. package/dist/classes/test/Contract/ens-abi.d.ts +2 -0
  4. package/dist/classes/test/Contract/fei-abi.d.ts +2 -0
  5. package/dist/classes/test/Contract/foo-abi.d.ts +2 -0
  6. package/dist/classes/test/Contract/uniswap-abi.d.ts +2 -0
  7. package/dist/classes/utils/clean-block.d.ts +3 -0
  8. package/dist/classes/utils/clean-log.d.ts +2 -0
  9. package/{lib/esm → dist}/classes/utils/clean-transaction-receipt.d.ts +2 -2
  10. package/{lib/esm → dist}/classes/utils/clean-transaction.d.ts +2 -2
  11. package/{lib/cjs → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
  12. package/{lib/cjs → dist}/classes/utils/fetchers.d.ts +9 -9
  13. package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
  14. package/dist/classes/utils/prepare-transaction.d.ts +2 -0
  15. package/dist/index.cjs +2 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/{lib/cjs → dist}/index.d.ts +25 -25
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.modern.js +2 -0
  21. package/dist/index.modern.js.map +1 -0
  22. package/dist/index.modern.mjs +2 -0
  23. package/dist/index.modern.mjs.map +1 -0
  24. package/dist/index.module.js +2 -0
  25. package/dist/index.module.js.map +1 -0
  26. package/dist/index.umd.js +2 -0
  27. package/dist/index.umd.js.map +1 -0
  28. package/{lib/esm → dist}/logger/logger.d.ts +11 -11
  29. package/dist/logger/package-version.d.ts +1 -0
  30. package/{lib/esm → dist}/providers/BaseProvider.d.ts +24 -21
  31. package/{lib/esm → dist}/providers/FallthroughProvider.d.ts +11 -11
  32. package/{lib/esm → dist}/providers/JsonRpcProvider.d.ts +7 -7
  33. package/{lib/cjs → dist}/providers/test/rpc-urls.d.ts +11 -11
  34. package/{lib/esm → dist}/providers/utils/chains-info.d.ts +467 -412
  35. package/{lib/cjs → dist}/shared/tiny-big/helpers.d.ts +1 -1
  36. package/{lib/esm → dist}/shared/tiny-big/tiny-big.d.ts +10 -10
  37. package/{lib/cjs → dist}/shared/validate-type.d.ts +3 -3
  38. package/{lib/cjs → dist}/types/Block.types.d.ts +40 -37
  39. package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
  40. package/dist/types/Filter.types.d.ts +12 -0
  41. package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
  42. package/{lib/cjs → dist}/types/Transaction.types.d.ts +113 -96
  43. package/{lib/esm → dist}/utils/bytes.d.ts +40 -40
  44. package/{lib/esm → dist}/utils/compute-address.d.ts +1 -1
  45. package/{lib/esm → dist}/utils/compute-public-key.d.ts +2 -2
  46. package/{lib/esm → dist}/utils/ether-to-gwei.d.ts +3 -3
  47. package/dist/utils/ether-to-wei.d.ts +3 -0
  48. package/dist/utils/gwei-to-ether.d.ts +3 -0
  49. package/{lib/esm → dist}/utils/hash-message.d.ts +2 -2
  50. package/{lib/esm → dist}/utils/is-address.d.ts +1 -1
  51. package/dist/utils/keccak256.d.ts +2 -0
  52. package/{lib/esm → dist}/utils/solidity-keccak256.d.ts +2 -2
  53. package/{lib/esm → dist}/utils/split-signature.d.ts +2 -2
  54. package/{lib/esm → dist}/utils/to-checksum-address.d.ts +1 -1
  55. package/{lib/cjs → dist}/utils/to-utf8-bytes.d.ts +1 -1
  56. package/dist/utils/wei-to-ether.d.ts +3 -0
  57. package/package.json +66 -19
  58. package/readme.md +643 -291
  59. package/lib/cjs/classes/Contract.d.ts +0 -72
  60. package/lib/cjs/classes/Contract.js +0 -129
  61. package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
  62. package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
  63. package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
  64. package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
  65. package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
  66. package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
  67. package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
  68. package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
  69. package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
  70. package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  71. package/lib/cjs/classes/utils/clean-block.d.ts +0 -6
  72. package/lib/cjs/classes/utils/clean-block.js +0 -47
  73. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -5
  74. package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -55
  75. package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -5
  76. package/lib/cjs/classes/utils/clean-transaction.js +0 -42
  77. package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -113
  78. package/lib/cjs/classes/utils/fetchers.js +0 -51
  79. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -5
  80. package/lib/cjs/classes/utils/hex-to-decimal.js +0 -11
  81. package/lib/cjs/index.js +0 -55
  82. package/lib/cjs/logger/logger.d.ts +0 -11
  83. package/lib/cjs/logger/logger.js +0 -36
  84. package/lib/cjs/logger/package-version.d.ts +0 -1
  85. package/lib/cjs/logger/package-version.js +0 -5
  86. package/lib/cjs/providers/BaseProvider.d.ts +0 -304
  87. package/lib/cjs/providers/BaseProvider.js +0 -405
  88. package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
  89. package/lib/cjs/providers/FallthroughProvider.js +0 -65
  90. package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -27
  91. package/lib/cjs/providers/JsonRpcProvider.js +0 -40
  92. package/lib/cjs/providers/test/rpc-urls.js +0 -14
  93. package/lib/cjs/providers/types.d.ts +0 -7
  94. package/lib/cjs/providers/types.js +0 -2
  95. package/lib/cjs/providers/utils/chains-info.d.ts +0 -412
  96. package/lib/cjs/providers/utils/chains-info.js +0 -1237
  97. package/lib/cjs/shared/tiny-big/helpers.js +0 -71
  98. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -32
  99. package/lib/cjs/shared/tiny-big/tiny-big.js +0 -71
  100. package/lib/cjs/shared/validate-type.js +0 -9
  101. package/lib/cjs/types/Block.types.js +0 -2
  102. package/lib/cjs/types/Contract.types.js +0 -2
  103. package/lib/cjs/types/Network.types.d.ts +0 -8
  104. package/lib/cjs/types/Network.types.js +0 -2
  105. package/lib/cjs/types/Transaction.types.js +0 -2
  106. package/lib/cjs/utils/bytes.d.ts +0 -172
  107. package/lib/cjs/utils/bytes.js +0 -564
  108. package/lib/cjs/utils/compute-address.d.ts +0 -8
  109. package/lib/cjs/utils/compute-address.js +0 -24
  110. package/lib/cjs/utils/compute-public-key.d.ts +0 -9
  111. package/lib/cjs/utils/compute-public-key.js +0 -17
  112. package/lib/cjs/utils/ether-to-gwei.d.ts +0 -26
  113. package/lib/cjs/utils/ether-to-gwei.js +0 -34
  114. package/lib/cjs/utils/ether-to-wei.d.ts +0 -26
  115. package/lib/cjs/utils/ether-to-wei.js +0 -34
  116. package/lib/cjs/utils/gwei-to-ether.d.ts +0 -26
  117. package/lib/cjs/utils/gwei-to-ether.js +0 -34
  118. package/lib/cjs/utils/hash-message.d.ts +0 -12
  119. package/lib/cjs/utils/hash-message.js +0 -26
  120. package/lib/cjs/utils/is-address.d.ts +0 -24
  121. package/lib/cjs/utils/is-address.js +0 -39
  122. package/lib/cjs/utils/keccak256.d.ts +0 -2
  123. package/lib/cjs/utils/keccak256.js +0 -17
  124. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -29
  125. package/lib/cjs/utils/solidity-keccak256.js +0 -118
  126. package/lib/cjs/utils/split-signature.d.ts +0 -26
  127. package/lib/cjs/utils/split-signature.js +0 -165
  128. package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
  129. package/lib/cjs/utils/to-checksum-address.js +0 -46
  130. package/lib/cjs/utils/to-utf8-bytes.js +0 -7
  131. package/lib/cjs/utils/wei-to-ether.d.ts +0 -26
  132. package/lib/cjs/utils/wei-to-ether.js +0 -44
  133. package/lib/esm/classes/Contract.js +0 -65
  134. package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  135. package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
  136. package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  137. package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
  138. package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  139. package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
  140. package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  141. package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
  142. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  143. package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
  144. package/lib/esm/classes/utils/clean-block.d.ts +0 -3
  145. package/lib/esm/classes/utils/clean-block.js +0 -36
  146. package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -48
  147. package/lib/esm/classes/utils/clean-transaction.js +0 -33
  148. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
  149. package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
  150. package/lib/esm/classes/utils/fetchers.d.ts +0 -9
  151. package/lib/esm/classes/utils/fetchers.js +0 -43
  152. package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
  153. package/lib/esm/index.d.ts +0 -25
  154. package/lib/esm/index.js +0 -21
  155. package/lib/esm/logger/logger.js +0 -33
  156. package/lib/esm/logger/package-version.d.ts +0 -1
  157. package/lib/esm/logger/package-version.js +0 -1
  158. package/lib/esm/providers/BaseProvider.js +0 -114
  159. package/lib/esm/providers/FallthroughProvider.js +0 -41
  160. package/lib/esm/providers/JsonRpcProvider.js +0 -15
  161. package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
  162. package/lib/esm/providers/test/rpc-urls.js +0 -11
  163. package/lib/esm/providers/types.d.ts +0 -7
  164. package/lib/esm/providers/types.js +0 -1
  165. package/lib/esm/providers/utils/chains-info.js +0 -1233
  166. package/lib/esm/shared/tiny-big/helpers.d.ts +0 -1
  167. package/lib/esm/shared/tiny-big/helpers.js +0 -58
  168. package/lib/esm/shared/tiny-big/tiny-big.js +0 -41
  169. package/lib/esm/shared/validate-type.d.ts +0 -3
  170. package/lib/esm/shared/validate-type.js +0 -5
  171. package/lib/esm/types/Block.types.d.ts +0 -36
  172. package/lib/esm/types/Block.types.js +0 -1
  173. package/lib/esm/types/Contract.types.d.ts +0 -24
  174. package/lib/esm/types/Contract.types.js +0 -1
  175. package/lib/esm/types/Network.types.js +0 -1
  176. package/lib/esm/types/Transaction.types.d.ts +0 -87
  177. package/lib/esm/types/Transaction.types.js +0 -1
  178. package/lib/esm/utils/bytes.js +0 -245
  179. package/lib/esm/utils/compute-address.js +0 -11
  180. package/lib/esm/utils/compute-public-key.js +0 -6
  181. package/lib/esm/utils/ether-to-gwei.js +0 -7
  182. package/lib/esm/utils/ether-to-wei.d.ts +0 -3
  183. package/lib/esm/utils/ether-to-wei.js +0 -7
  184. package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
  185. package/lib/esm/utils/gwei-to-ether.js +0 -7
  186. package/lib/esm/utils/hash-message.js +0 -12
  187. package/lib/esm/utils/is-address.js +0 -12
  188. package/lib/esm/utils/keccak256.d.ts +0 -2
  189. package/lib/esm/utils/keccak256.js +0 -13
  190. package/lib/esm/utils/solidity-keccak256.js +0 -85
  191. package/lib/esm/utils/split-signature.js +0 -126
  192. package/lib/esm/utils/to-checksum-address.js +0 -25
  193. package/lib/esm/utils/to-utf8-bytes.d.ts +0 -1
  194. package/lib/esm/utils/to-utf8-bytes.js +0 -3
  195. package/lib/esm/utils/wei-to-ether.d.ts +0 -3
  196. package/lib/esm/utils/wei-to-ether.js +0 -16
@@ -1,36 +0,0 @@
1
- import { toChecksumAddress } from '../..';
2
- import { cleanTransaction } from './clean-transaction';
3
- import { hexToDecimal } from './hex-to-decimal';
4
- export function cleanBlock(block, returnTransactionObjects) {
5
- const cleanedBlock = Object.assign({}, block);
6
- Object.keys(block).forEach((key) => {
7
- if (!block[key])
8
- return;
9
- switch (key) {
10
- case 'gasLimit':
11
- case 'gasUsed':
12
- case 'number':
13
- case 'size':
14
- case 'timestamp':
15
- case 'baseFeePerGas':
16
- cleanedBlock[key] = Number(hexToDecimal(block[key]));
17
- break;
18
- case 'difficulty':
19
- case 'totalDifficulty':
20
- cleanedBlock[key] = hexToDecimal(block[key]);
21
- break;
22
- case 'miner':
23
- if (block[key]) {
24
- cleanedBlock[key] = toChecksumAddress(block[key]);
25
- }
26
- break;
27
- }
28
- });
29
- if (returnTransactionObjects) {
30
- const txns = block.transactions;
31
- txns.forEach((transaction, index) => {
32
- cleanedBlock.transactions[index] = cleanTransaction(transaction);
33
- });
34
- }
35
- return cleanedBlock;
36
- }
@@ -1,48 +0,0 @@
1
- import { tinyBig, toChecksumAddress } from '../..';
2
- import { cleanTransaction } from './clean-transaction';
3
- import { hexToDecimal } from './hex-to-decimal';
4
- export function cleanTransactionReceipt(transactionReceipt) {
5
- const cleanedTransaction = cleanTransaction(transactionReceipt);
6
- const cleanedTransactionReceipt = Object.assign({}, cleanedTransaction);
7
- Object.keys(transactionReceipt).forEach((key) => {
8
- if (!transactionReceipt[key])
9
- return;
10
- switch (key) {
11
- case 'status':
12
- cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
13
- break;
14
- case 'contractAddress':
15
- if (transactionReceipt[key]) {
16
- cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
17
- }
18
- break;
19
- case 'cumulativeGasUsed':
20
- case 'effectiveGasPrice':
21
- case 'gasUsed':
22
- cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
23
- break;
24
- case 'logs':
25
- transactionReceipt[key].forEach((log, index) => {
26
- Object.keys(log).forEach((logKey) => {
27
- switch (logKey) {
28
- case 'address':
29
- cleanedTransactionReceipt[key][index][logKey] =
30
- toChecksumAddress(log[logKey]);
31
- break;
32
- case 'blockNumber':
33
- case 'logIndex':
34
- case 'transactionIndex':
35
- cleanedTransactionReceipt[key][index][logKey] = Number(hexToDecimal(log[logKey]));
36
- break;
37
- case 'removed':
38
- delete log[logKey];
39
- break;
40
- }
41
- });
42
- });
43
- }
44
- });
45
- cleanedTransactionReceipt.byzantium =
46
- cleanedTransactionReceipt.blockNumber >= 4370000;
47
- return cleanedTransactionReceipt;
48
- }
@@ -1,33 +0,0 @@
1
- import { tinyBig, toChecksumAddress } from '../..';
2
- import { hexToDecimal } from './hex-to-decimal';
3
- export function cleanTransaction(transaction) {
4
- const cleanedTransaction = Object.assign({}, transaction);
5
- Object.keys(transaction).forEach((key) => {
6
- if (!transaction[key])
7
- return;
8
- switch (key) {
9
- case 'blockNumber':
10
- case 'chainId':
11
- case 'nonce':
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
- cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
29
- break;
30
- }
31
- });
32
- return cleanedTransaction;
33
- }
@@ -1,4 +0,0 @@
1
- import { 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("../..").TinyBig | (string | number | boolean | import("../..").TinyBig)[];
@@ -1,98 +0,0 @@
1
- import { Keccak } from 'sha3';
2
- import { tinyBig, toChecksumAddress } from '../..';
3
- import { hexToDecimal } from './hex-to-decimal';
4
- export const hexFalse = '0'.repeat(64);
5
- const hexTrue = '0'.repeat(63) + '1';
6
- function expandType(type) {
7
- if (type === 'uint[]') {
8
- return 'uint256[]';
9
- }
10
- else if (type === 'int[]') {
11
- return 'int256[]';
12
- }
13
- return type;
14
- }
15
- export function encodeData(jsonABIArgument, args) {
16
- const hash = new Keccak(256);
17
- const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
18
- const functionHash = hash.update(functionString).digest('hex');
19
- const jsonABIInputsLength = jsonABIArgument.inputs.length;
20
- let shouldValidateInputLength = true;
21
- if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
22
- shouldValidateInputLength = false;
23
- }
24
- if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
25
- throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
26
- }
27
- const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
28
- var _a;
29
- if (input.type.includes('[')) {
30
- const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
31
- args.forEach((arg) => {
32
- acc = acc.concat([[arg, basicType]]);
33
- });
34
- return acc;
35
- }
36
- else {
37
- return acc.concat([[args[i], input.type]]);
38
- }
39
- }, []);
40
- const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
41
- let rawArg = arg;
42
- switch (inputType) {
43
- case 'bool':
44
- return arg ? hexTrue : hexFalse;
45
- case 'address':
46
- rawArg = arg.replace(/^0x/g, '').toLowerCase();
47
- break;
48
- default:
49
- if (inputType.startsWith('bytes')) {
50
- const argEncoded = rawArg
51
- .split('')
52
- .map((character) => character.charCodeAt(0).toString(16))
53
- .join('');
54
- const paddedEncodedArg = argEncoded.padEnd(64, '0');
55
- return paddedEncodedArg;
56
- }
57
- else if (inputType === 'uint256') {
58
- const argEncoded = BigInt(arg).toString(16);
59
- const paddedEncodedArg = argEncoded.padStart(64, '0');
60
- return paddedEncodedArg;
61
- }
62
- else if (inputType.startsWith('uint')) {
63
- break;
64
- }
65
- else {
66
- throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
67
- }
68
- }
69
- const argEncoded = rawArg.toString(16);
70
- const paddedEncodedArg = argEncoded.padStart(64, '0');
71
- return paddedEncodedArg;
72
- });
73
- const functionEncoded = functionHash.slice(0, 8);
74
- const data = `0x${functionEncoded}${encodedArgs.join('')}`;
75
- return data;
76
- }
77
- export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
78
- const rawOutputs = jsonABIArgument.outputs;
79
- const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
80
- const outputs = (encodedOutputs || []).map((output, i) => {
81
- const outputType = (rawOutputs || [])[i].type;
82
- switch (outputType) {
83
- case 'bool':
84
- return output === hexTrue;
85
- case 'address':
86
- return toChecksumAddress(`0x${output.slice(24)}`);
87
- case 'uint256':
88
- return tinyBig(hexToDecimal(`0x${output}`));
89
- case 'bytes32':
90
- return `0x${output}`;
91
- case 'uint8':
92
- return Number(hexToDecimal(`0x${output}`));
93
- default:
94
- throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
95
- }
96
- });
97
- return outputs.length === 1 ? outputs[0] : outputs;
98
- }
@@ -1,9 +0,0 @@
1
- export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber' | 'eth_estimateGas';
3
- export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
- jsonrpc: string;
5
- id: number;
6
- method: RPCMethodName;
7
- params: unknown[];
8
- };
9
- export {};
@@ -1,43 +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 post(url, body) {
12
- return unfetch(url, {
13
- method: 'POST',
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- },
17
- body: JSON.stringify(body),
18
- })
19
- .then((r) => __awaiter(this, void 0, void 0, function* () {
20
- const t = yield r.text();
21
- try {
22
- return JSON.parse(t);
23
- }
24
- catch (_a) {
25
- throw new Error(`Invalid JSON RPC response: "${t}"`);
26
- }
27
- }))
28
- .then((response) => {
29
- const result = response === null || response === void 0 ? void 0 : response.result;
30
- if (!result) {
31
- throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
32
- }
33
- return response.result;
34
- });
35
- }
36
- export function buildRPCPostBody(method, params) {
37
- return {
38
- jsonrpc: '2.0',
39
- id: 1,
40
- method,
41
- params,
42
- };
43
- }
@@ -1,3 +0,0 @@
1
- export function hexToDecimal(hex) {
2
- return BigInt(hex).toString();
3
- }
@@ -1,25 +0,0 @@
1
- import { BaseContract, Contract } from './classes/Contract';
2
- import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
3
- import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
4
- import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
5
- import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
6
- import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
7
- import { Network } from './types/Network.types';
8
- import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, TransactionReceipt, TransactionResponse } from './types/Transaction.types';
9
- import { computeAddress } from './utils/compute-address';
10
- import { computePublicKey } from './utils/compute-public-key';
11
- import { etherToGwei } from './utils/ether-to-gwei';
12
- import { etherToWei } from './utils/ether-to-wei';
13
- import { gweiToEther } from './utils/gwei-to-ether';
14
- import { hashMessage } from './utils/hash-message';
15
- import { isAddress } from './utils/is-address';
16
- import { splitSignature } from './utils/split-signature';
17
- import { toChecksumAddress } from './utils/to-checksum-address';
18
- import { toUtf8Bytes } from './utils/to-utf8-bytes';
19
- import { weiToEther } from './utils/wei-to-ether';
20
- export * from './providers/types';
21
- export * from './utils/bytes';
22
- export * from './utils/hash-message';
23
- export * from './utils/keccak256';
24
- export * from './utils/solidity-keccak256';
25
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
package/lib/esm/index.js DELETED
@@ -1,21 +0,0 @@
1
- import { BaseContract, Contract } from './classes/Contract';
2
- import { FallthroughProvider, } from './providers/FallthroughProvider';
3
- import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
4
- import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
5
- import { computeAddress } from './utils/compute-address';
6
- import { computePublicKey } from './utils/compute-public-key';
7
- import { etherToGwei } from './utils/ether-to-gwei';
8
- import { etherToWei } from './utils/ether-to-wei';
9
- import { gweiToEther } from './utils/gwei-to-ether';
10
- import { hashMessage } from './utils/hash-message';
11
- import { isAddress } from './utils/is-address';
12
- import { splitSignature } from './utils/split-signature';
13
- import { toChecksumAddress } from './utils/to-checksum-address';
14
- import { toUtf8Bytes } from './utils/to-utf8-bytes';
15
- import { weiToEther } from './utils/wei-to-ether';
16
- export * from './providers/types';
17
- export * from './utils/bytes';
18
- export * from './utils/hash-message';
19
- export * from './utils/keccak256';
20
- export * from './utils/solidity-keccak256';
21
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
@@ -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.5.6";
@@ -1 +0,0 @@
1
- export const version = '0.5.6';
@@ -1,114 +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 { cleanBlock } from '../classes/utils/clean-block';
11
- import { cleanTransaction } from '../classes/utils/clean-transaction';
12
- import { cleanTransactionReceipt } from '../classes/utils/clean-transaction-receipt';
13
- import { buildRPCPostBody, post } from '../classes/utils/fetchers';
14
- import { hexToDecimal } from '../classes/utils/hex-to-decimal';
15
- import { tinyBig } from '../shared/tiny-big/tiny-big';
16
- import chainsInfo from './utils/chains-info';
17
- export class BaseProvider {
18
- constructor(rpcUrls) {
19
- this._rpcUrls = [];
20
- this._post = (body) => post(this.selectRpcUrl(), body);
21
- this._rpcUrls = rpcUrls;
22
- }
23
- getNetwork() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const hexChainId = (yield this.post(buildRPCPostBody('eth_chainId', [])));
26
- const chainId = hexToDecimal(hexChainId);
27
- const info = chainsInfo[chainId];
28
- return {
29
- chainId: Number(chainId),
30
- name: info[0] || 'unknown',
31
- ensAddress: info[1] || null,
32
- };
33
- });
34
- }
35
- getBlockNumber() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const currentBlockNumber = (yield this.post(buildRPCPostBody('eth_blockNumber', [])));
38
- return Number(hexToDecimal(currentBlockNumber));
39
- });
40
- }
41
- getTransaction(transactionHash) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const [rpcTransaction, blockNumber] = yield Promise.all([
44
- this.post(buildRPCPostBody('eth_getTransactionByHash', [transactionHash])),
45
- this.getBlock('latest'),
46
- ]);
47
- const cleanedTransaction = cleanTransaction(rpcTransaction);
48
- cleanedTransaction.confirmations =
49
- blockNumber.number - cleanedTransaction.blockNumber + 1;
50
- return cleanedTransaction;
51
- });
52
- }
53
- getTransactionReceipt(transactionHash) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const [rpcTransaction, blockNumber] = yield Promise.all([
56
- this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])),
57
- this.getBlock('latest'),
58
- ]);
59
- const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
60
- cleanedTransactionReceipt.confirmations =
61
- blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
62
- return cleanedTransactionReceipt;
63
- });
64
- }
65
- getTransactionCount(address, blockTag = 'latest') {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- if (typeof blockTag === 'number') {
68
- blockTag = `0x${blockTag.toString(16)}`;
69
- }
70
- const transactionCount = (yield this.post(buildRPCPostBody('eth_getTransactionCount', [address, blockTag])));
71
- return Number(hexToDecimal(transactionCount));
72
- });
73
- }
74
- getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- let rpcTimeFrame;
77
- let type = 'Number';
78
- if (typeof timeFrame === 'number') {
79
- rpcTimeFrame = `0x${timeFrame.toString(16)}`;
80
- }
81
- else if (timeFrame.startsWith('0x')) {
82
- rpcTimeFrame = timeFrame;
83
- type = 'Hash';
84
- }
85
- else {
86
- rpcTimeFrame = timeFrame;
87
- }
88
- const rpcBlock = (yield this.post(buildRPCPostBody(`eth_getBlockBy${type}`, [
89
- rpcTimeFrame,
90
- returnTransactionObjects,
91
- ])));
92
- return cleanBlock(rpcBlock, returnTransactionObjects);
93
- });
94
- }
95
- getGasPrice() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
98
- return tinyBig(hexToDecimal(hexGasPrice));
99
- });
100
- }
101
- getBalance(address, blockTag = 'latest') {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const hexBalance = (yield this.post(buildRPCPostBody('eth_getBalance', [address, blockTag])));
104
- return tinyBig(hexToDecimal(hexBalance));
105
- });
106
- }
107
- estimateGas(transaction) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- const body = buildRPCPostBody('eth_estimateGas', [transaction]);
110
- const gasUsed = (yield this.post(body));
111
- return tinyBig(hexToDecimal(gasUsed));
112
- });
113
- }
114
- }
@@ -1,41 +0,0 @@
1
- import { logger } from '../logger/logger';
2
- import { BaseProvider } from './BaseProvider';
3
- const promiseTimeout = (prom, time) => Promise.race([
4
- prom,
5
- new Promise((_r, reject) => setTimeout(() => reject('Promise timed out'), time)),
6
- ]);
7
- const DEFAULT_TIMEOUT_DURATION = 8000;
8
- export class FallthroughProvider extends BaseProvider {
9
- constructor(rpcUrls, options = {}) {
10
- if (!Array.isArray(rpcUrls)) {
11
- logger.throwError('Array required', { rpcUrls });
12
- }
13
- if (rpcUrls.length <= 1) {
14
- logger.throwError('More than one rpcUrl is required', { rpcUrls });
15
- }
16
- super(rpcUrls);
17
- this.rpcUrlCounter = 0;
18
- this.post = (body) => {
19
- const genesisCount = this.rpcUrlCounter;
20
- const recursivePostRetry = () => {
21
- const genesisRpcUrl = this.selectRpcUrl();
22
- const res = promiseTimeout(this._post(body), this.timeoutDuration).catch((e) => {
23
- if (genesisRpcUrl === this.selectRpcUrl()) {
24
- this.rpcUrlCounter =
25
- (this.rpcUrlCounter + 1) % this._rpcUrls.length;
26
- }
27
- if (this.rpcUrlCounter === genesisCount) {
28
- throw e;
29
- }
30
- return recursivePostRetry();
31
- });
32
- return res;
33
- };
34
- return recursivePostRetry();
35
- };
36
- this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
37
- }
38
- selectRpcUrl() {
39
- return this._rpcUrls[this.rpcUrlCounter];
40
- }
41
- }
@@ -1,15 +0,0 @@
1
- import { BaseProvider } from './BaseProvider';
2
- export class JsonRpcProvider extends BaseProvider {
3
- selectRpcUrl() {
4
- return this._rpcUrls[0];
5
- }
6
- post(body) {
7
- return this._post(body);
8
- }
9
- constructor(rpcUrl = 'https://free-eth-node.com/api/eth') {
10
- super([rpcUrl]);
11
- }
12
- }
13
- export function jsonRpcProvider(rpcUrl) {
14
- return new JsonRpcProvider(rpcUrl);
15
- }
@@ -1,11 +0,0 @@
1
- export declare const fakeUrls: {
2
- readonly notRPCButRealHttp: "https://httpstat.us/200";
3
- };
4
- export declare const rpcUrls: {
5
- mainnet: string;
6
- matic: string;
7
- gno: string;
8
- bnb: string;
9
- arb1: string;
10
- gor: string;
11
- };
@@ -1,11 +0,0 @@
1
- export const fakeUrls = {
2
- notRPCButRealHttp: 'https://httpstat.us/200',
3
- };
4
- export const rpcUrls = {
5
- mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
6
- matic: `${process.env.RPC_ORIGIN}/api/MATIC`,
7
- gno: `${process.env.RPC_ORIGIN}/api/gno`,
8
- bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
9
- arb1: `${process.env.RPC_ORIGIN}/api/arb1`,
10
- gor: `${process.env.RPC_ORIGIN}/api/gor`,
11
- };
@@ -1,7 +0,0 @@
1
- import { BytesLike } from '../utils/bytes';
2
- export interface TransactionRequest {
3
- to?: string;
4
- from?: string;
5
- data?: BytesLike;
6
- [key: string]: any;
7
- }
@@ -1 +0,0 @@
1
- export {};