essential-eth 0.5.6 → 0.5.9

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 (91) hide show
  1. package/lib/cjs/classes/Contract.d.ts +10 -4
  2. package/lib/cjs/classes/Contract.js +15 -4
  3. package/lib/cjs/classes/utils/clean-block.d.ts +115 -0
  4. package/lib/cjs/classes/utils/clean-block.js +122 -9
  5. package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
  6. package/lib/cjs/classes/utils/clean-log.js +37 -0
  7. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +9 -0
  8. package/lib/cjs/classes/utils/clean-transaction-receipt.js +11 -16
  9. package/lib/cjs/classes/utils/clean-transaction.d.ts +9 -0
  10. package/lib/cjs/classes/utils/clean-transaction.js +10 -1
  11. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +12 -0
  12. package/lib/cjs/classes/utils/encode-decode-transaction.js +24 -0
  13. package/lib/cjs/classes/utils/fetchers.d.ts +31 -1
  14. package/lib/cjs/classes/utils/fetchers.js +30 -0
  15. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +14 -1
  16. package/lib/cjs/classes/utils/hex-to-decimal.js +14 -1
  17. package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
  18. package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
  19. package/lib/cjs/index.d.ts +3 -3
  20. package/lib/cjs/index.js +0 -1
  21. package/lib/cjs/logger/package-version.d.ts +1 -1
  22. package/lib/cjs/logger/package-version.js +1 -1
  23. package/lib/cjs/providers/BaseProvider.d.ts +261 -212
  24. package/lib/cjs/providers/BaseProvider.js +332 -225
  25. package/lib/cjs/providers/JsonRpcProvider.d.ts +6 -0
  26. package/lib/cjs/providers/JsonRpcProvider.js +6 -0
  27. package/lib/cjs/providers/utils/chains-info.d.ts +11 -0
  28. package/lib/cjs/providers/utils/chains-info.js +34 -1
  29. package/lib/cjs/shared/tiny-big/helpers.d.ts +16 -0
  30. package/lib/cjs/shared/tiny-big/helpers.js +27 -1
  31. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +30 -4
  32. package/lib/cjs/shared/tiny-big/tiny-big.js +34 -4
  33. package/lib/cjs/types/Block.types.d.ts +11 -7
  34. package/lib/cjs/types/Filter.types.d.ts +16 -0
  35. package/lib/cjs/{providers/types.js → types/Filter.types.js} +0 -0
  36. package/lib/cjs/types/Transaction.types.d.ts +33 -6
  37. package/lib/cjs/utils/bytes.d.ts +150 -33
  38. package/lib/cjs/utils/bytes.js +179 -32
  39. package/lib/cjs/utils/compute-address.d.ts +10 -1
  40. package/lib/cjs/utils/compute-address.js +10 -1
  41. package/lib/cjs/utils/compute-public-key.d.ts +12 -3
  42. package/lib/cjs/utils/compute-public-key.js +12 -3
  43. package/lib/cjs/utils/ether-to-gwei.d.ts +2 -1
  44. package/lib/cjs/utils/ether-to-gwei.js +2 -1
  45. package/lib/cjs/utils/ether-to-wei.d.ts +2 -1
  46. package/lib/cjs/utils/ether-to-wei.js +2 -1
  47. package/lib/cjs/utils/gwei-to-ether.d.ts +2 -1
  48. package/lib/cjs/utils/gwei-to-ether.js +2 -1
  49. package/lib/cjs/utils/hash-message.d.ts +3 -1
  50. package/lib/cjs/utils/hash-message.js +3 -1
  51. package/lib/cjs/utils/is-address.d.ts +2 -2
  52. package/lib/cjs/utils/is-address.js +2 -2
  53. package/lib/cjs/utils/keccak256.d.ts +15 -1
  54. package/lib/cjs/utils/keccak256.js +16 -2
  55. package/lib/cjs/utils/solidity-keccak256.d.ts +17 -7
  56. package/lib/cjs/utils/solidity-keccak256.js +27 -7
  57. package/lib/cjs/utils/split-signature.d.ts +1 -3
  58. package/lib/cjs/utils/split-signature.js +1 -3
  59. package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
  60. package/lib/cjs/utils/to-checksum-address.js +2 -2
  61. package/lib/cjs/utils/to-utf8-bytes.d.ts +14 -0
  62. package/lib/cjs/utils/to-utf8-bytes.js +14 -0
  63. package/lib/cjs/utils/wei-to-ether.d.ts +2 -1
  64. package/lib/cjs/utils/wei-to-ether.js +2 -1
  65. package/lib/esm/classes/utils/clean-block.js +7 -8
  66. package/lib/esm/classes/utils/clean-log.d.ts +2 -0
  67. package/lib/esm/classes/utils/clean-log.js +26 -0
  68. package/lib/esm/classes/utils/clean-transaction-receipt.js +2 -16
  69. package/lib/esm/classes/utils/clean-transaction.js +1 -1
  70. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  71. package/lib/esm/classes/utils/prepare-transaction.d.ts +2 -0
  72. package/lib/esm/classes/utils/prepare-transaction.js +34 -0
  73. package/lib/esm/index.d.ts +3 -3
  74. package/lib/esm/index.js +0 -1
  75. package/lib/esm/logger/package-version.d.ts +1 -1
  76. package/lib/esm/logger/package-version.js +1 -1
  77. package/lib/esm/providers/BaseProvider.d.ts +5 -2
  78. package/lib/esm/providers/BaseProvider.js +56 -13
  79. package/lib/esm/providers/utils/chains-info.d.ts +11 -0
  80. package/lib/esm/providers/utils/chains-info.js +34 -1
  81. package/lib/esm/shared/tiny-big/tiny-big.js +4 -0
  82. package/lib/esm/types/Block.types.d.ts +11 -7
  83. package/lib/esm/types/Filter.types.d.ts +12 -0
  84. package/lib/esm/{providers/types.js → types/Filter.types.js} +0 -0
  85. package/lib/esm/types/Transaction.types.d.ts +31 -5
  86. package/lib/esm/utils/keccak256.d.ts +1 -1
  87. package/lib/esm/utils/keccak256.js +2 -2
  88. package/package.json +30 -6
  89. package/readme.md +643 -291
  90. package/lib/cjs/providers/types.d.ts +0 -7
  91. package/lib/esm/providers/types.d.ts +0 -7
@@ -6,6 +6,18 @@ const __1 = require("../..");
6
6
  const hex_to_decimal_1 = require("./hex-to-decimal");
7
7
  exports.hexFalse = '0'.repeat(64);
8
8
  const hexTrue = '0'.repeat(63) + '1';
9
+ /**
10
+ * Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
11
+ *
12
+ * @see https://ethereum.stackexchange.com/questions/43241/why-write-uint256-instead-of-uint-if-theyre-the-same-thing
13
+ * @param type the type to explicitly define as 256 bits
14
+ * @returns the integer type expanded to explicitly be 256 bits when possible
15
+ * @example
16
+ * ```javascript
17
+ * expandType('uint[]');
18
+ * // 'uint256[]'
19
+ * ```
20
+ */
9
21
  function expandType(type) {
10
22
  // https://docs.soliditylang.org/en/v0.8.7/types.html#integers
11
23
  if (type === 'uint[]') {
@@ -16,6 +28,12 @@ function expandType(type) {
16
28
  }
17
29
  return type;
18
30
  }
31
+ /**
32
+ *
33
+ * @param jsonABIArgument
34
+ * @param args
35
+ * @example
36
+ */
19
37
  function encodeData(jsonABIArgument, args) {
20
38
  const hash = new sha3_1.Keccak(256);
21
39
  /* first 4 bytes will create the data parameter */
@@ -86,6 +104,12 @@ function encodeData(jsonABIArgument, args) {
86
104
  return data;
87
105
  }
88
106
  exports.encodeData = encodeData;
107
+ /**
108
+ *
109
+ * @param jsonABIArgument
110
+ * @param nodeResponse
111
+ * @example
112
+ */
89
113
  function decodeRPCResponse(jsonABIArgument, nodeResponse) {
90
114
  const rawOutputs = jsonABIArgument.outputs;
91
115
  // chunk response every 64 characters
@@ -1,5 +1,35 @@
1
+ /**
2
+ * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
3
+ *
4
+ * @param url the URL to send the request to
5
+ * @param body the body data (JSON) to send with the request
6
+ * @returns the JSON response from the server
7
+ * @example
8
+ * ```javascript
9
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
10
+ * // '0x66fa8dbfd'
11
+ *
12
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
13
+ * // '0x312faeb995df61d4'
14
+ * ```
15
+ */
1
16
  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';
17
+ declare 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';
18
+ /**
19
+ * Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
20
+ *
21
+ * @param method the RPC method to be invoked
22
+ * @param params the parameters to be passed to the defined method
23
+ * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
24
+ * @example
25
+ * ```javascript
26
+ * buildRPCPostBody('eth_gasPrice', []);
27
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
28
+ *
29
+ * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
30
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
31
+ * ```
32
+ */
3
33
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
34
  jsonrpc: string;
5
35
  id: number;
@@ -14,6 +14,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.buildRPCPostBody = exports.post = void 0;
16
16
  const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
17
+ /**
18
+ * Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
19
+ *
20
+ * @param url the URL to send the request to
21
+ * @param body the body data (JSON) to send with the request
22
+ * @returns the JSON response from the server
23
+ * @example
24
+ * ```javascript
25
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
26
+ * // '0x66fa8dbfd'
27
+ *
28
+ * post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
29
+ * // '0x312faeb995df61d4'
30
+ * ```
31
+ */
17
32
  function post(url, body) {
18
33
  return (0, isomorphic_unfetch_1.default)(url, {
19
34
  method: 'POST',
@@ -40,6 +55,21 @@ function post(url, body) {
40
55
  });
41
56
  }
42
57
  exports.post = post;
58
+ /**
59
+ * Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
60
+ *
61
+ * @param method the RPC method to be invoked
62
+ * @param params the parameters to be passed to the defined method
63
+ * @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
64
+ * @example
65
+ * ```javascript
66
+ * buildRPCPostBody('eth_gasPrice', []);
67
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
68
+ *
69
+ * buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
70
+ * // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
71
+ * ```
72
+ */
43
73
  function buildRPCPostBody(method, params) {
44
74
  return {
45
75
  jsonrpc: '2.0',
@@ -1,5 +1,18 @@
1
1
  /**
2
2
  * Converts a hexadecimal string it's decimal equivalent.
3
- * This is needed instead of parseInt because parseInt loses precision
3
+ * This is needed instead of parseInt because parseInt loses precision.
4
+ *
5
+ * @param hex the hex string to be converted to decimal
6
+ * @returns a decimal value equivalent to the hex string given
7
+ * @example
8
+ * ```javascript
9
+ * hexToDecimal('0x34');
10
+ * // 52
11
+ * ```
12
+ * @example
13
+ * ```javascript
14
+ * hexToDecimal('0x628608');
15
+ * // 6456840
16
+ * ```
4
17
  */
5
18
  export declare function hexToDecimal(hex: string): string;
@@ -3,7 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hexToDecimal = void 0;
4
4
  /**
5
5
  * Converts a hexadecimal string it's decimal equivalent.
6
- * This is needed instead of parseInt because parseInt loses precision
6
+ * This is needed instead of parseInt because parseInt loses precision.
7
+ *
8
+ * @param hex the hex string to be converted to decimal
9
+ * @returns a decimal value equivalent to the hex string given
10
+ * @example
11
+ * ```javascript
12
+ * hexToDecimal('0x34');
13
+ * // 52
14
+ * ```
15
+ * @example
16
+ * ```javascript
17
+ * hexToDecimal('0x628608');
18
+ * // 6456840
19
+ * ```
7
20
  */
8
21
  function hexToDecimal(hex) {
9
22
  return BigInt(hex).toString();
@@ -0,0 +1,6 @@
1
+ import { RPCTransactionRequest, TransactionRequest } from './../../types/Transaction.types';
2
+ /**
3
+ * @param transaction
4
+ * @example
5
+ */
6
+ export declare function prepareTransaction(transaction: TransactionRequest): RPCTransactionRequest;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.prepareTransaction = void 0;
7
+ const big_js_1 = __importDefault(require("big.js"));
8
+ const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
9
+ const bytes_1 = require("../../utils/bytes");
10
+ /**
11
+ * @param transaction
12
+ * @example
13
+ */
14
+ function prepareTransaction(transaction) {
15
+ const preparedTransaction = Object.assign({}, transaction);
16
+ Object.keys(transaction).forEach((key) => {
17
+ switch (key) {
18
+ case 'gas':
19
+ case 'gasPrice':
20
+ case 'nonce':
21
+ case 'maxFeePerGas':
22
+ case 'maxPriorityFeePerGas':
23
+ case 'value': {
24
+ const value = transaction[key];
25
+ if (value instanceof tiny_big_1.TinyBig) {
26
+ preparedTransaction[key] = value.toHexString();
27
+ }
28
+ else if (value instanceof big_js_1.default) {
29
+ preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
30
+ }
31
+ else if (typeof transaction[key] === 'number')
32
+ preparedTransaction[key] =
33
+ '0x' + transaction[key].toString(16);
34
+ else
35
+ preparedTransaction[key] = transaction[key].toString();
36
+ break;
37
+ }
38
+ case 'data':
39
+ preparedTransaction[key] = (0, bytes_1.hexlify)(transaction[key]);
40
+ break;
41
+ }
42
+ });
43
+ return preparedTransaction;
44
+ }
45
+ exports.prepareTransaction = prepareTransaction;
@@ -4,8 +4,9 @@ import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
4
4
  import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
5
5
  import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
6
6
  import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
7
+ import { Filter, FilterByBlockHash } from './types/Filter.types';
7
8
  import { Network } from './types/Network.types';
8
- import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, TransactionReceipt, TransactionResponse } from './types/Transaction.types';
9
+ import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse } from './types/Transaction.types';
9
10
  import { computeAddress } from './utils/compute-address';
10
11
  import { computePublicKey } from './utils/compute-public-key';
11
12
  import { etherToGwei } from './utils/ether-to-gwei';
@@ -17,9 +18,8 @@ import { splitSignature } from './utils/split-signature';
17
18
  import { toChecksumAddress } from './utils/to-checksum-address';
18
19
  import { toUtf8Bytes } from './utils/to-utf8-bytes';
19
20
  import { weiToEther } from './utils/wei-to-ether';
20
- export * from './providers/types';
21
21
  export * from './utils/bytes';
22
22
  export * from './utils/hash-message';
23
23
  export * from './utils/keccak256';
24
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, };
25
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
package/lib/cjs/index.js CHANGED
@@ -48,7 +48,6 @@ const to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
48
48
  Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
49
49
  const wei_to_ether_1 = require("./utils/wei-to-ether");
50
50
  Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
51
- __exportStar(require("./providers/types"), exports);
52
51
  __exportStar(require("./utils/bytes"), exports);
53
52
  __exportStar(require("./utils/hash-message"), exports);
54
53
  __exportStar(require("./utils/keccak256"), exports);
@@ -1 +1 @@
1
- export declare const version = "0.5.6";
1
+ export declare const version = "0.5.9";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = '0.5.6';
5
+ exports.version = '0.5.9';