essential-eth 0.4.11 → 0.5.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 (34) hide show
  1. package/lib/cjs/classes/utils/clean-block.d.ts +3 -3
  2. package/lib/cjs/classes/utils/clean-block.js +3 -2
  3. package/lib/cjs/classes/utils/clean-transaction.d.ts +3 -3
  4. package/lib/cjs/classes/utils/clean-transaction.js +10 -6
  5. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  6. package/lib/cjs/index.d.ts +4 -3
  7. package/lib/cjs/index.js +3 -1
  8. package/lib/cjs/providers/JsonRpcProvider.d.ts +172 -2
  9. package/lib/cjs/providers/JsonRpcProvider.js +193 -23
  10. package/lib/cjs/providers/utils/chains-info.d.ts +6 -0
  11. package/lib/cjs/providers/utils/chains-info.js +18 -0
  12. package/lib/cjs/shared/tiny-big/tiny-big.js +7 -1
  13. package/lib/cjs/types/Block.types.d.ts +8 -19
  14. package/lib/cjs/types/Transaction.types.d.ts +23 -14
  15. package/lib/cjs/utils/hex-zero-pad.d.ts +32 -0
  16. package/lib/cjs/utils/hex-zero-pad.js +52 -0
  17. package/lib/esm/classes/utils/clean-block.d.ts +2 -2
  18. package/lib/esm/classes/utils/clean-block.js +2 -1
  19. package/lib/esm/classes/utils/clean-transaction.d.ts +2 -2
  20. package/lib/esm/classes/utils/clean-transaction.js +10 -6
  21. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  22. package/lib/esm/index.d.ts +4 -3
  23. package/lib/esm/index.js +2 -1
  24. package/lib/esm/providers/JsonRpcProvider.d.ts +5 -2
  25. package/lib/esm/providers/JsonRpcProvider.js +25 -23
  26. package/lib/esm/providers/utils/chains-info.d.ts +6 -0
  27. package/lib/esm/providers/utils/chains-info.js +18 -0
  28. package/lib/esm/shared/tiny-big/tiny-big.js +7 -1
  29. package/lib/esm/types/Block.types.d.ts +7 -19
  30. package/lib/esm/types/Transaction.types.d.ts +22 -14
  31. package/lib/esm/utils/hex-zero-pad.d.ts +1 -0
  32. package/lib/esm/utils/hex-zero-pad.js +17 -0
  33. package/package.json +7 -7
  34. package/readme.md +225 -62
@@ -1,6 +1,6 @@
1
- import { Block } from '../..';
1
+ import { BlockResponse } from '../..';
2
2
  import { RPCBlock } from '../../types/Block.types';
3
3
  /**
4
- * Converts hex to decimal and checksum-addresses all addresses
4
+ * Converts RPC block response to more JS-friendly format
5
5
  */
6
- export declare function cleanBlock(block: RPCBlock, returnTransactionObjects: boolean): Block;
6
+ export declare function cleanBlock(block: RPCBlock, returnTransactionObjects: boolean): BlockResponse;
@@ -5,7 +5,7 @@ const __1 = require("../..");
5
5
  const clean_transaction_1 = require("./clean-transaction");
6
6
  const hex_to_decimal_1 = require("./hex-to-decimal");
7
7
  /**
8
- * Converts hex to decimal and checksum-addresses all addresses
8
+ * Converts RPC block response to more JS-friendly format
9
9
  */
10
10
  function cleanBlock(block, returnTransactionObjects) {
11
11
  const cleanedBlock = Object.assign({}, block);
@@ -36,8 +36,9 @@ function cleanBlock(block, returnTransactionObjects) {
36
36
  });
37
37
  // for all full transactions
38
38
  if (returnTransactionObjects) {
39
+ const txns = block.transactions;
39
40
  // could be renamed "cleanTransaction" in the future
40
- cleanedBlock.transactions.forEach((transaction, index) => {
41
+ txns.forEach((transaction, index) => {
41
42
  cleanedBlock.transactions[index] = (0, clean_transaction_1.cleanTransaction)(transaction);
42
43
  });
43
44
  }
@@ -1,5 +1,5 @@
1
- import { RPCTransaction, Transaction } from '../../types/Transaction.types';
1
+ import { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
2
2
  /**
3
- * Converts hex to decimal and checksum-addresses all addresses
3
+ * Converts RPC transaction response to more JS-friendly format
4
4
  */
5
- export declare function cleanTransaction(transaction: RPCTransaction): Transaction;
5
+ export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
@@ -4,7 +4,7 @@ exports.cleanTransaction = void 0;
4
4
  const __1 = require("../..");
5
5
  const hex_to_decimal_1 = require("./hex-to-decimal");
6
6
  /**
7
- * Converts hex to decimal and checksum-addresses all addresses
7
+ * Converts RPC transaction response to more JS-friendly format
8
8
  */
9
9
  function cleanTransaction(transaction) {
10
10
  const cleanedTransaction = Object.assign({}, transaction);
@@ -15,22 +15,26 @@ function cleanTransaction(transaction) {
15
15
  return;
16
16
  switch (key) {
17
17
  case 'blockNumber':
18
- case 'gas':
18
+ case 'chainId':
19
19
  case 'nonce':
20
20
  case 'transactionIndex':
21
21
  case 'type':
22
+ case 'v':
22
23
  cleanedTransaction[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
23
24
  break;
24
- case 'gasPrice':
25
- case 'value':
26
- cleanedTransaction[key] = (0, hex_to_decimal_1.hexToDecimal)(transaction[key]);
27
- break;
28
25
  case 'from':
29
26
  case 'to':
30
27
  if (transaction[key]) {
31
28
  cleanedTransaction[key] = (0, __1.toChecksumAddress)(transaction[key]);
32
29
  }
33
30
  break;
31
+ case 'value':
32
+ case 'gas':
33
+ case 'gasPrice':
34
+ case 'maxFeePerGas':
35
+ case 'maxPriorityFeePerGas':
36
+ cleanedTransaction[key] = (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transaction[key]));
37
+ break;
34
38
  }
35
39
  });
36
40
  return cleanedTransaction;
@@ -1,5 +1,5 @@
1
1
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance';
2
+ declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash';
3
3
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
4
  jsonrpc: string;
5
5
  id: number;
@@ -1,14 +1,15 @@
1
1
  import { Contract } from './classes/Contract';
2
2
  import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
3
3
  import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
4
- import { Block } from './types/Block.types';
4
+ import { BlockResponse } from './types/Block.types';
5
5
  import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
6
6
  import { Network } from './types/Network.types';
7
- import { Transaction } from './types/Transaction.types';
7
+ import { TransactionResponse } from './types/Transaction.types';
8
8
  import { etherToGwei } from './utils/ether-to-gwei';
9
9
  import { etherToWei } from './utils/ether-to-wei';
10
10
  import { gweiToEther } from './utils/gwei-to-ether';
11
+ import { hexZeroPad } from './utils/hex-zero-pad';
11
12
  import { isAddress } from './utils/is-address';
12
13
  import { toChecksumAddress } from './utils/to-checksum-address';
13
14
  import { weiToEther } from './utils/wei-to-ether';
14
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, Block, ContractTypes, JSONABI, JSONABIArgument, Network, Transaction, };
15
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hexZeroPad, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TinyBig = exports.Contract = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
3
+ exports.TinyBig = exports.Contract = exports.hexZeroPad = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
4
4
  const Contract_1 = require("./classes/Contract");
5
5
  Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
6
6
  const JsonRpcProvider_1 = require("./providers/JsonRpcProvider");
@@ -15,6 +15,8 @@ const ether_to_wei_1 = require("./utils/ether-to-wei");
15
15
  Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
16
16
  const gwei_to_ether_1 = require("./utils/gwei-to-ether");
17
17
  Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
18
+ const hex_zero_pad_1 = require("./utils/hex-zero-pad");
19
+ Object.defineProperty(exports, "hexZeroPad", { enumerable: true, get: function () { return hex_zero_pad_1.hexZeroPad; } });
18
20
  const is_address_1 = require("./utils/is-address");
19
21
  Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
20
22
  const to_checksum_address_1 = require("./utils/to-checksum-address");
@@ -1,11 +1,16 @@
1
1
  import { TinyBig } from '../shared/tiny-big/tiny-big';
2
- import { Block, BlockTag } from '../types/Block.types';
2
+ import { BlockResponse, BlockTag } from '../types/Block.types';
3
3
  import { Network } from '../types/Network.types';
4
+ import { TransactionResponse } from '../types/Transaction.types';
4
5
  export declare class JsonRpcProvider {
5
6
  /**
6
7
  * @ignore
7
8
  */
8
9
  readonly _rpcUrl: string;
10
+ /**
11
+ * @ignore
12
+ */
13
+ private post;
9
14
  /**
10
15
  * @param rpcUrl The URL to your Eth node. Consider POKT or Infura
11
16
  */
@@ -13,8 +18,47 @@ export declare class JsonRpcProvider {
13
18
  /**
14
19
  * Returns the block requested
15
20
  * Same as `web3.eth.getBlock`
21
+ * @example
22
+ * ```js
23
+ * await provider.getBlock('latest');
24
+ * {
25
+ * number: 4232826,
26
+ * hash: '0x93211a1cd17e154b183565ec685254a03f844a8e34824a46ce1bdd6753dcb669',
27
+ * parentHash: '0x1b32bfcba1bb2a57f56e166a3bb06875a1978992999dfc8828397b4c1526f472',
28
+ * sha3Uncles: '0x0fb399c67bb5a071ec8a22549223215ab76b7d4009941c9c37aa3c3936010463',
29
+ * logsBloom: '0x00000000000000000000101000000000020000000000000000000000000000000000400000010000000000000000000000000000010000000008800000000800000000200000000000000000000000000000000000000000000002000000000000000000000000000040000000000040000000000000000000000000000000000000000000000001000000000004000000000010000000000000000020000000000000000200100020000000000000000080000000000080001000000000000000000001040000000000000000008000000020010100000000200000100000000000000000000000002000000080000000020400000000002000200000000000',
30
+ * transactionsRoot: '0xc43b3f13e1fe810e34d3a26ffe465b72c7063a5c70a02de2c78e91e4d10bd9fb',
31
+ * stateRoot: '0x04d7bc816537ea7ef3a16e76c9879d29f34f99d4154273c2e98e012a31bad745',
32
+ * receiptsRoot: '0x89c6f781ceac0bd49c4d9aa9115df4a5d4dd0e0220ff7668012f15bc04222c6b',
33
+ * miner: '0x31fe561eb2c628cD32Ec52573D7c4b7E4C278Bfa',
34
+ * difficulty: '1300907486001755331049',
35
+ * totalDifficulty: '5989929395521171616186006183',
36
+ * extraData: '0xce018c495249532d62613031656132',
37
+ * size: 5416,
38
+ * gasLimit: 6800000,
39
+ * gasUsed: 202955,
40
+ * timestamp: 1649884910,
41
+ * transactions: [
42
+ * '0x6b34a59c7b9aead24fa6dad782f8a3ad84ed4a23ee09bcbf0bcf880840fbbe20',
43
+ * '0x9a3851ca24d5336c6a0d48aba2c4b4769d7a672c9b01729c5eb9924efd1b19a7',
44
+ * '0xc3ed3d198b62f2f3427ebfa3bbd0fcada4e3c0c189e4464e7eeceb403c75981e'
45
+ * ],
46
+ * uncles: [
47
+ * '0x0c567c054e98153f10d651fbbc018891c1dd9d62a9ffd998e87678803e95b6ed',
48
+ * '0xb7d69389dbfb057c6fcb4bc0582d46a2ba01170703f0dadf8cd1462b83e88753',
49
+ * '0xd5f74ccd0ad4c58b3161e8c2c507c264231e5f28925061b809c02e5e4bb6db28'
50
+ * ],
51
+ * minimumGasPrice: '0x387ee40',
52
+ * bitcoinMergedMiningHeader: '0x04000020e8567ed3d2480e15a1dd1b4335e4732ae343c037e4fd03000000000000000000ed10a8340d163d3e813bdd430f902f4e5a56828dc62313b2e23797c0be6b8516eb3e576297d8091735884f42',
53
+ * bitcoinMergedMiningCoinbaseTransaction: '0x0000000000000140e910128fda7bac502dc5e0573bbaf12de8e2524f70c22f7bd160dedcb19a2521002b6a2952534b424c4f434b3ae493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967aace6a7d9',
54
+ * bitcoinMergedMiningMerkleProof: '0xdf63a3d7eb6fbcfb301311faa46e9a15b0408bb1a04e284daee86c273c1dfd65ede23f3170f806e9e0f4cef7ba6b56aa37470d9c23f96ec8e43d08b58645919c5e10bcb892897a731f8f9ce79c72dc0e390896bcd6c67bb38c0bdb72982b6cf05519968d76673572c3f3ef3a08b0ddb464863f1788f7cdbaad3fe44a8a8af576d430ac282fe28852c16df198ca96cc5f71a50695912efe1a836e8442be69e31b6d6f973da2818bce9a3a1c2d9be0671aee9a7776e398d6a03d1e178e20d84646004a3d03c0501334e629d9146aa6a01316dcbaa289df6e6c5e3090cadaddff22699cfc7ff09512fc0d65c5062f17c98561ce3c9510de210d9d654cf99f8d756ff37c9fa21e7122ee8cadb923341690845d572921425f2bd7e044558b7e07983ac4df28928028b0c13c3624dc7a965af8091b0cecc845bf7da5308c03b2c97d607f6706a599f802025894435f1d76ea4e67cc2fc4e1559f1206f559a24633de0f',
55
+ * hashForMergedMining: '0xe493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967a',
56
+ * paidFees: '0xc0744dcb7a0',
57
+ * cumulativeDifficulty: '0x1190930db285269e582'
58
+ * }
59
+ *```
16
60
  */
17
- getBlock(timeFrame: BlockTag, returnTransactionObjects?: boolean): Promise<Block>;
61
+ getBlock(timeFrame: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
18
62
  /**
19
63
  * Returns the network this provider is connected to
20
64
  */
@@ -38,6 +82,132 @@ export declare class JsonRpcProvider {
38
82
  * ```
39
83
  */
40
84
  getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
85
+ /**
86
+ * Similar to `ethers.provider.getTransaction`, some information not included
87
+ *
88
+ * @params hash A transaction hash
89
+ * @returns information about one transaction
90
+ * @example
91
+ * ```js
92
+ * await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
93
+ * {
94
+ * accessList: [],
95
+ * blockHash: '0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d',
96
+ * blockNumber: 14578286,
97
+ * chainId: 1,
98
+ * from: '0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4',
99
+ * gas: Big {
100
+ * s: 1,
101
+ * e: 5,
102
+ * c: [ 1, 1, 2, 1, 6, 3 ],
103
+ * constructor: <ref *1> [Function: Big] {
104
+ * DP: 20,
105
+ * RM: 1,
106
+ * NE: -7,
107
+ * PE: 21,
108
+ * strict: false,
109
+ * roundDown: 0,
110
+ * roundHalfUp: 1,
111
+ * roundHalfEven: 2,
112
+ * roundUp: 3,
113
+ * Big: [Circular *1],
114
+ * default: [Circular *1]
115
+ * }
116
+ * },
117
+ * gasPrice: Big {
118
+ * s: 1,
119
+ * e: 10,
120
+ * c: [
121
+ * 4, 8, 5, 9, 2,
122
+ * 4, 2, 6, 8, 5,
123
+ * 8
124
+ * ],
125
+ * constructor: <ref *1> [Function: Big] {
126
+ * DP: 20,
127
+ * RM: 1,
128
+ * NE: -7,
129
+ * PE: 21,
130
+ * strict: false,
131
+ * roundDown: 0,
132
+ * roundHalfUp: 1,
133
+ * roundHalfEven: 2,
134
+ * roundUp: 3,
135
+ * Big: [Circular *1],
136
+ * default: [Circular *1]
137
+ * }
138
+ * },
139
+ * hash: '0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789',
140
+ * input: '0x83259f170000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009e99ad11a214fd016b19dc3648678c5944859ae292b21c24ca94f857836c4596f1950c82dd0c23dd621af4763edc2f66466e63c5df9de0c1107b1cd16bf460fe93e43fd308e3444bc79c3d88a4cb961dc8367ab6ad048867afc76d193bca99cf3a068864ed4a7df1dbf1d4c52238eced3e5e05644b4040fc2b3ccb8557b0e99fff6131305a0ea2b8061b90bd418db5bbdd2e92129f52d93f90531465e309c4caec5b85285822b6196398d36f16f511811b61bbda6461e80e29210cd303118bdcee8df6fa0505ffbe8642094fd2ba4dd458496fe3b459ac880bbf71877c713e969ccf5ed7efab8a84ebc07e3939901371ca427e1192e455a8f35a6a1d7ad09e1475dd1758b36fa631dab5d70e99316b23c4c43094188d360cd9c3457355904e07c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000162074a7047f',
141
+ * maxFeePerGas: Big {
142
+ * s: 1,
143
+ * e: 10,
144
+ * c: [
145
+ * 6, 7, 6, 8, 1,
146
+ * 2, 6, 1, 6, 1,
147
+ * 8
148
+ * ],
149
+ * constructor: <ref *1> [Function: Big] {
150
+ * DP: 20,
151
+ * RM: 1,
152
+ * NE: -7,
153
+ * PE: 21,
154
+ * strict: false,
155
+ * roundDown: 0,
156
+ * roundHalfUp: 1,
157
+ * roundHalfEven: 2,
158
+ * roundUp: 3,
159
+ * Big: [Circular *1],
160
+ * default: [Circular *1]
161
+ * }
162
+ * },
163
+ * maxPriorityFeePerGas: Big {
164
+ * s: 1,
165
+ * e: 9,
166
+ * c: [ 1, 5 ],
167
+ * constructor: <ref *1> [Function: Big] {
168
+ * DP: 20,
169
+ * RM: 1,
170
+ * NE: -7,
171
+ * PE: 21,
172
+ * strict: false,
173
+ * roundDown: 0,
174
+ * roundHalfUp: 1,
175
+ * roundHalfEven: 2,
176
+ * roundUp: 3,
177
+ * Big: [Circular *1],
178
+ * default: [Circular *1]
179
+ * }
180
+ * },
181
+ * nonce: 129,
182
+ * r: '0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc',
183
+ * s: '0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c',
184
+ * to: '0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B',
185
+ * transactionIndex: 29,
186
+ * type: 2,
187
+ * v: 0,
188
+ * value: Big {
189
+ * s: 1,
190
+ * e: 0,
191
+ * c: [ 0 ],
192
+ * constructor: <ref *1> [Function: Big] {
193
+ * DP: 20,
194
+ * RM: 1,
195
+ * NE: -7,
196
+ * PE: 21,
197
+ * strict: false,
198
+ * roundDown: 0,
199
+ * roundHalfUp: 1,
200
+ * roundHalfEven: 2,
201
+ * roundUp: 3,
202
+ * Big: [Circular *1],
203
+ * default: [Circular *1]
204
+ * }
205
+ * },
206
+ * confirmations: 1210
207
+ * }
208
+ * ```
209
+ */
210
+ getTransaction(hash: string): Promise<TransactionResponse>;
41
211
  }
42
212
  /**
43
213
  * Helper function to avoid "new"
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.jsonRpcProvider = exports.JsonRpcProvider = void 0;
16
16
  const clean_block_1 = require("../classes/utils/clean-block");
17
+ const clean_transaction_1 = require("../classes/utils/clean-transaction");
17
18
  const fetchers_1 = require("../classes/utils/fetchers");
18
19
  const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
19
20
  const tiny_big_1 = require("../shared/tiny-big/tiny-big");
@@ -23,11 +24,54 @@ class JsonRpcProvider {
23
24
  * @param rpcUrl The URL to your Eth node. Consider POKT or Infura
24
25
  */
25
26
  constructor(rpcUrl) {
27
+ /**
28
+ * @ignore
29
+ */
30
+ this.post = (body) => (0, fetchers_1.post)(this._rpcUrl, body);
26
31
  this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
27
32
  }
28
33
  /**
29
34
  * Returns the block requested
30
35
  * Same as `web3.eth.getBlock`
36
+ * @example
37
+ * ```js
38
+ * await provider.getBlock('latest');
39
+ * {
40
+ * number: 4232826,
41
+ * hash: '0x93211a1cd17e154b183565ec685254a03f844a8e34824a46ce1bdd6753dcb669',
42
+ * parentHash: '0x1b32bfcba1bb2a57f56e166a3bb06875a1978992999dfc8828397b4c1526f472',
43
+ * sha3Uncles: '0x0fb399c67bb5a071ec8a22549223215ab76b7d4009941c9c37aa3c3936010463',
44
+ * logsBloom: '0x00000000000000000000101000000000020000000000000000000000000000000000400000010000000000000000000000000000010000000008800000000800000000200000000000000000000000000000000000000000000002000000000000000000000000000040000000000040000000000000000000000000000000000000000000000001000000000004000000000010000000000000000020000000000000000200100020000000000000000080000000000080001000000000000000000001040000000000000000008000000020010100000000200000100000000000000000000000002000000080000000020400000000002000200000000000',
45
+ * transactionsRoot: '0xc43b3f13e1fe810e34d3a26ffe465b72c7063a5c70a02de2c78e91e4d10bd9fb',
46
+ * stateRoot: '0x04d7bc816537ea7ef3a16e76c9879d29f34f99d4154273c2e98e012a31bad745',
47
+ * receiptsRoot: '0x89c6f781ceac0bd49c4d9aa9115df4a5d4dd0e0220ff7668012f15bc04222c6b',
48
+ * miner: '0x31fe561eb2c628cD32Ec52573D7c4b7E4C278Bfa',
49
+ * difficulty: '1300907486001755331049',
50
+ * totalDifficulty: '5989929395521171616186006183',
51
+ * extraData: '0xce018c495249532d62613031656132',
52
+ * size: 5416,
53
+ * gasLimit: 6800000,
54
+ * gasUsed: 202955,
55
+ * timestamp: 1649884910,
56
+ * transactions: [
57
+ * '0x6b34a59c7b9aead24fa6dad782f8a3ad84ed4a23ee09bcbf0bcf880840fbbe20',
58
+ * '0x9a3851ca24d5336c6a0d48aba2c4b4769d7a672c9b01729c5eb9924efd1b19a7',
59
+ * '0xc3ed3d198b62f2f3427ebfa3bbd0fcada4e3c0c189e4464e7eeceb403c75981e'
60
+ * ],
61
+ * uncles: [
62
+ * '0x0c567c054e98153f10d651fbbc018891c1dd9d62a9ffd998e87678803e95b6ed',
63
+ * '0xb7d69389dbfb057c6fcb4bc0582d46a2ba01170703f0dadf8cd1462b83e88753',
64
+ * '0xd5f74ccd0ad4c58b3161e8c2c507c264231e5f28925061b809c02e5e4bb6db28'
65
+ * ],
66
+ * minimumGasPrice: '0x387ee40',
67
+ * bitcoinMergedMiningHeader: '0x04000020e8567ed3d2480e15a1dd1b4335e4732ae343c037e4fd03000000000000000000ed10a8340d163d3e813bdd430f902f4e5a56828dc62313b2e23797c0be6b8516eb3e576297d8091735884f42',
68
+ * bitcoinMergedMiningCoinbaseTransaction: '0x0000000000000140e910128fda7bac502dc5e0573bbaf12de8e2524f70c22f7bd160dedcb19a2521002b6a2952534b424c4f434b3ae493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967aace6a7d9',
69
+ * bitcoinMergedMiningMerkleProof: '0xdf63a3d7eb6fbcfb301311faa46e9a15b0408bb1a04e284daee86c273c1dfd65ede23f3170f806e9e0f4cef7ba6b56aa37470d9c23f96ec8e43d08b58645919c5e10bcb892897a731f8f9ce79c72dc0e390896bcd6c67bb38c0bdb72982b6cf05519968d76673572c3f3ef3a08b0ddb464863f1788f7cdbaad3fe44a8a8af576d430ac282fe28852c16df198ca96cc5f71a50695912efe1a836e8442be69e31b6d6f973da2818bce9a3a1c2d9be0671aee9a7776e398d6a03d1e178e20d84646004a3d03c0501334e629d9146aa6a01316dcbaa289df6e6c5e3090cadaddff22699cfc7ff09512fc0d65c5062f17c98561ce3c9510de210d9d654cf99f8d756ff37c9fa21e7122ee8cadb923341690845d572921425f2bd7e044558b7e07983ac4df28928028b0c13c3624dc7a965af8091b0cecc845bf7da5308c03b2c97d607f6706a599f802025894435f1d76ea4e67cc2fc4e1559f1206f559a24633de0f',
70
+ * hashForMergedMining: '0xe493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967a',
71
+ * paidFees: '0xc0744dcb7a0',
72
+ * cumulativeDifficulty: '0x1190930db285269e582'
73
+ * }
74
+ *```
31
75
  */
32
76
  getBlock(timeFrame, returnTransactionObjects = false) {
33
77
  return __awaiter(this, void 0, void 0, function* () {
@@ -40,14 +84,11 @@ class JsonRpcProvider {
40
84
  // "latest", "earliest", and "pending" require no manipulation
41
85
  rpcTimeFrame = timeFrame;
42
86
  }
43
- const req = () => {
44
- return (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_getBlockByNumber', [
45
- rpcTimeFrame,
46
- returnTransactionObjects,
47
- ]));
48
- };
49
- const nodeResponse = (yield req());
50
- return (0, clean_block_1.cleanBlock)(nodeResponse, returnTransactionObjects);
87
+ const rpcBlock = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBlockByNumber', [
88
+ rpcTimeFrame,
89
+ returnTransactionObjects,
90
+ ])));
91
+ return (0, clean_block_1.cleanBlock)(rpcBlock, returnTransactionObjects);
51
92
  });
52
93
  }
53
94
  /**
@@ -55,11 +96,8 @@ class JsonRpcProvider {
55
96
  */
56
97
  getNetwork() {
57
98
  return __awaiter(this, void 0, void 0, function* () {
58
- const req = () => {
59
- return (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_chainId', []));
60
- };
61
- const nodeResponse = (yield req());
62
- const chainId = (0, hex_to_decimal_1.hexToDecimal)(nodeResponse);
99
+ const hexChainId = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_chainId', [])));
100
+ const chainId = (0, hex_to_decimal_1.hexToDecimal)(hexChainId);
63
101
  const info = chains_info_1.default[chainId];
64
102
  return {
65
103
  chainId: Number(chainId),
@@ -74,11 +112,8 @@ class JsonRpcProvider {
74
112
  */
75
113
  getGasPrice() {
76
114
  return __awaiter(this, void 0, void 0, function* () {
77
- const req = () => {
78
- return (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_gasPrice', []));
79
- };
80
- const nodeResponse = (yield req()); /* '0x153cfb1ad0' */
81
- return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(nodeResponse));
115
+ const hexGasPrice = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_gasPrice', [])));
116
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexGasPrice));
82
117
  });
83
118
  }
84
119
  /**
@@ -96,11 +131,146 @@ class JsonRpcProvider {
96
131
  */
97
132
  getBalance(address, blockTag = 'latest') {
98
133
  return __awaiter(this, void 0, void 0, function* () {
99
- const req = () => {
100
- return (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag]));
101
- };
102
- const nodeResponse = (yield req()); /* '0x153cfb1ad0' */
103
- return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(nodeResponse));
134
+ const hexBalance = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag])));
135
+ return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
136
+ });
137
+ }
138
+ /**
139
+ * Similar to `ethers.provider.getTransaction`, some information not included
140
+ *
141
+ * @params hash A transaction hash
142
+ * @returns information about one transaction
143
+ * @example
144
+ * ```js
145
+ * await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
146
+ * {
147
+ * accessList: [],
148
+ * blockHash: '0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d',
149
+ * blockNumber: 14578286,
150
+ * chainId: 1,
151
+ * from: '0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4',
152
+ * gas: Big {
153
+ * s: 1,
154
+ * e: 5,
155
+ * c: [ 1, 1, 2, 1, 6, 3 ],
156
+ * constructor: <ref *1> [Function: Big] {
157
+ * DP: 20,
158
+ * RM: 1,
159
+ * NE: -7,
160
+ * PE: 21,
161
+ * strict: false,
162
+ * roundDown: 0,
163
+ * roundHalfUp: 1,
164
+ * roundHalfEven: 2,
165
+ * roundUp: 3,
166
+ * Big: [Circular *1],
167
+ * default: [Circular *1]
168
+ * }
169
+ * },
170
+ * gasPrice: Big {
171
+ * s: 1,
172
+ * e: 10,
173
+ * c: [
174
+ * 4, 8, 5, 9, 2,
175
+ * 4, 2, 6, 8, 5,
176
+ * 8
177
+ * ],
178
+ * constructor: <ref *1> [Function: Big] {
179
+ * DP: 20,
180
+ * RM: 1,
181
+ * NE: -7,
182
+ * PE: 21,
183
+ * strict: false,
184
+ * roundDown: 0,
185
+ * roundHalfUp: 1,
186
+ * roundHalfEven: 2,
187
+ * roundUp: 3,
188
+ * Big: [Circular *1],
189
+ * default: [Circular *1]
190
+ * }
191
+ * },
192
+ * hash: '0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789',
193
+ * input: '0x83259f170000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009e99ad11a214fd016b19dc3648678c5944859ae292b21c24ca94f857836c4596f1950c82dd0c23dd621af4763edc2f66466e63c5df9de0c1107b1cd16bf460fe93e43fd308e3444bc79c3d88a4cb961dc8367ab6ad048867afc76d193bca99cf3a068864ed4a7df1dbf1d4c52238eced3e5e05644b4040fc2b3ccb8557b0e99fff6131305a0ea2b8061b90bd418db5bbdd2e92129f52d93f90531465e309c4caec5b85285822b6196398d36f16f511811b61bbda6461e80e29210cd303118bdcee8df6fa0505ffbe8642094fd2ba4dd458496fe3b459ac880bbf71877c713e969ccf5ed7efab8a84ebc07e3939901371ca427e1192e455a8f35a6a1d7ad09e1475dd1758b36fa631dab5d70e99316b23c4c43094188d360cd9c3457355904e07c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000162074a7047f',
194
+ * maxFeePerGas: Big {
195
+ * s: 1,
196
+ * e: 10,
197
+ * c: [
198
+ * 6, 7, 6, 8, 1,
199
+ * 2, 6, 1, 6, 1,
200
+ * 8
201
+ * ],
202
+ * constructor: <ref *1> [Function: Big] {
203
+ * DP: 20,
204
+ * RM: 1,
205
+ * NE: -7,
206
+ * PE: 21,
207
+ * strict: false,
208
+ * roundDown: 0,
209
+ * roundHalfUp: 1,
210
+ * roundHalfEven: 2,
211
+ * roundUp: 3,
212
+ * Big: [Circular *1],
213
+ * default: [Circular *1]
214
+ * }
215
+ * },
216
+ * maxPriorityFeePerGas: Big {
217
+ * s: 1,
218
+ * e: 9,
219
+ * c: [ 1, 5 ],
220
+ * constructor: <ref *1> [Function: Big] {
221
+ * DP: 20,
222
+ * RM: 1,
223
+ * NE: -7,
224
+ * PE: 21,
225
+ * strict: false,
226
+ * roundDown: 0,
227
+ * roundHalfUp: 1,
228
+ * roundHalfEven: 2,
229
+ * roundUp: 3,
230
+ * Big: [Circular *1],
231
+ * default: [Circular *1]
232
+ * }
233
+ * },
234
+ * nonce: 129,
235
+ * r: '0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc',
236
+ * s: '0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c',
237
+ * to: '0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B',
238
+ * transactionIndex: 29,
239
+ * type: 2,
240
+ * v: 0,
241
+ * value: Big {
242
+ * s: 1,
243
+ * e: 0,
244
+ * c: [ 0 ],
245
+ * constructor: <ref *1> [Function: Big] {
246
+ * DP: 20,
247
+ * RM: 1,
248
+ * NE: -7,
249
+ * PE: 21,
250
+ * strict: false,
251
+ * roundDown: 0,
252
+ * roundHalfUp: 1,
253
+ * roundHalfEven: 2,
254
+ * roundUp: 3,
255
+ * Big: [Circular *1],
256
+ * default: [Circular *1]
257
+ * }
258
+ * },
259
+ * confirmations: 1210
260
+ * }
261
+ * ```
262
+ */
263
+ getTransaction(hash) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ const [rpcTransaction, blockNumber] = yield Promise.all([
266
+ this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionByHash', [hash])),
267
+ this.getBlock('latest'),
268
+ ]);
269
+ const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(rpcTransaction);
270
+ // https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
271
+ cleanedTransaction.confirmations =
272
+ blockNumber.number - cleanedTransaction.blockNumber + 1;
273
+ return cleanedTransaction;
104
274
  });
105
275
  }
106
276
  }
@@ -66,7 +66,9 @@ declare const _default: {
66
66
  "76": string[];
67
67
  "77": string[];
68
68
  "78": string[];
69
+ "79": string[];
69
70
  "80": string[];
71
+ "81": string[];
70
72
  "82": string[];
71
73
  "83": string[];
72
74
  "85": string[];
@@ -147,6 +149,7 @@ declare const _default: {
147
149
  "600": string[];
148
150
  "666": string[];
149
151
  "686": string[];
152
+ "700": string[];
150
153
  "707": string[];
151
154
  "708": string[];
152
155
  "721": string[];
@@ -208,6 +211,8 @@ declare const _default: {
208
211
  "2025": string[];
209
212
  "2100": string[];
210
213
  "2101": string[];
214
+ "2152": string[];
215
+ "2153": string[];
211
216
  "2213": string[];
212
217
  "2221": string[];
213
218
  "2559": string[];
@@ -292,6 +297,7 @@ declare const _default: {
292
297
  "62320": string[];
293
298
  "63000": string[];
294
299
  "63001": string[];
300
+ "69420": string[];
295
301
  "70000": string[];
296
302
  "70001": string[];
297
303
  "70002": string[];