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.
- package/lib/cjs/classes/Contract.d.ts +10 -4
- package/lib/cjs/classes/Contract.js +15 -4
- package/lib/cjs/classes/utils/clean-block.d.ts +115 -0
- package/lib/cjs/classes/utils/clean-block.js +122 -9
- package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-log.js +37 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +11 -16
- package/lib/cjs/classes/utils/clean-transaction.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction.js +10 -1
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +12 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.js +24 -0
- package/lib/cjs/classes/utils/fetchers.d.ts +31 -1
- package/lib/cjs/classes/utils/fetchers.js +30 -0
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +14 -1
- package/lib/cjs/classes/utils/hex-to-decimal.js +14 -1
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
- package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
- package/lib/cjs/index.d.ts +3 -3
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +261 -212
- package/lib/cjs/providers/BaseProvider.js +332 -225
- package/lib/cjs/providers/JsonRpcProvider.d.ts +6 -0
- package/lib/cjs/providers/JsonRpcProvider.js +6 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +11 -0
- package/lib/cjs/providers/utils/chains-info.js +34 -1
- package/lib/cjs/shared/tiny-big/helpers.d.ts +16 -0
- package/lib/cjs/shared/tiny-big/helpers.js +27 -1
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +30 -4
- package/lib/cjs/shared/tiny-big/tiny-big.js +34 -4
- package/lib/cjs/types/Block.types.d.ts +11 -7
- package/lib/cjs/types/Filter.types.d.ts +16 -0
- package/lib/cjs/{providers/types.js → types/Filter.types.js} +0 -0
- package/lib/cjs/types/Transaction.types.d.ts +33 -6
- package/lib/cjs/utils/bytes.d.ts +150 -33
- package/lib/cjs/utils/bytes.js +179 -32
- package/lib/cjs/utils/compute-address.d.ts +10 -1
- package/lib/cjs/utils/compute-address.js +10 -1
- package/lib/cjs/utils/compute-public-key.d.ts +12 -3
- package/lib/cjs/utils/compute-public-key.js +12 -3
- package/lib/cjs/utils/ether-to-gwei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-gwei.js +2 -1
- package/lib/cjs/utils/ether-to-wei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-wei.js +2 -1
- package/lib/cjs/utils/gwei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/gwei-to-ether.js +2 -1
- package/lib/cjs/utils/hash-message.d.ts +3 -1
- package/lib/cjs/utils/hash-message.js +3 -1
- package/lib/cjs/utils/is-address.d.ts +2 -2
- package/lib/cjs/utils/is-address.js +2 -2
- package/lib/cjs/utils/keccak256.d.ts +15 -1
- package/lib/cjs/utils/keccak256.js +16 -2
- package/lib/cjs/utils/solidity-keccak256.d.ts +17 -7
- package/lib/cjs/utils/solidity-keccak256.js +27 -7
- package/lib/cjs/utils/split-signature.d.ts +1 -3
- package/lib/cjs/utils/split-signature.js +1 -3
- package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
- package/lib/cjs/utils/to-checksum-address.js +2 -2
- package/lib/cjs/utils/to-utf8-bytes.d.ts +14 -0
- package/lib/cjs/utils/to-utf8-bytes.js +14 -0
- package/lib/cjs/utils/wei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/wei-to-ether.js +2 -1
- package/lib/esm/classes/utils/clean-block.js +7 -8
- package/lib/esm/classes/utils/clean-log.d.ts +2 -0
- package/lib/esm/classes/utils/clean-log.js +26 -0
- package/lib/esm/classes/utils/clean-transaction-receipt.js +2 -16
- package/lib/esm/classes/utils/clean-transaction.js +1 -1
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/lib/esm/classes/utils/prepare-transaction.js +34 -0
- package/lib/esm/index.d.ts +3 -3
- package/lib/esm/index.js +0 -1
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +5 -2
- package/lib/esm/providers/BaseProvider.js +56 -13
- package/lib/esm/providers/utils/chains-info.d.ts +11 -0
- package/lib/esm/providers/utils/chains-info.js +34 -1
- package/lib/esm/shared/tiny-big/tiny-big.js +4 -0
- package/lib/esm/types/Block.types.d.ts +11 -7
- package/lib/esm/types/Filter.types.d.ts +12 -0
- package/lib/esm/{providers/types.js → types/Filter.types.js} +0 -0
- package/lib/esm/types/Transaction.types.d.ts +31 -5
- package/lib/esm/utils/keccak256.d.ts +1 -1
- package/lib/esm/utils/keccak256.js +2 -2
- package/package.json +30 -6
- package/readme.md +643 -291
- package/lib/cjs/providers/types.d.ts +0 -7
- package/lib/esm/providers/types.d.ts +0 -7
|
@@ -14,15 +14,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BaseProvider = void 0;
|
|
16
16
|
const clean_block_1 = require("../classes/utils/clean-block");
|
|
17
|
+
const clean_log_1 = require("../classes/utils/clean-log");
|
|
17
18
|
const clean_transaction_1 = require("../classes/utils/clean-transaction");
|
|
18
19
|
const clean_transaction_receipt_1 = require("../classes/utils/clean-transaction-receipt");
|
|
19
20
|
const fetchers_1 = require("../classes/utils/fetchers");
|
|
20
21
|
const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
|
|
22
|
+
const prepare_transaction_1 = require("../classes/utils/prepare-transaction");
|
|
23
|
+
const logger_1 = require("../logger/logger");
|
|
21
24
|
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
22
25
|
const chains_info_1 = __importDefault(require("./utils/chains-info"));
|
|
26
|
+
/**
|
|
27
|
+
* Converts a block tag into the right format when needed.
|
|
28
|
+
*
|
|
29
|
+
* * No equivalent in ethers.js
|
|
30
|
+
* * No equivalent in web3.js
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
* @param blockTag the block tag to convert/return as a hex string
|
|
34
|
+
* @returns the specified block tag formatted as a hex string
|
|
35
|
+
* @example
|
|
36
|
+
* ```javascript
|
|
37
|
+
* prepBlockTag(14848183);
|
|
38
|
+
* // '0xe290b7'
|
|
39
|
+
* ```
|
|
40
|
+
* @example
|
|
41
|
+
* ```javascript
|
|
42
|
+
* prepBlockTag('0xe290b7');
|
|
43
|
+
* // '0xe290b7'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function prepBlockTag(blockTag) {
|
|
47
|
+
return typeof blockTag === 'number'
|
|
48
|
+
? (0, tiny_big_1.tinyBig)(blockTag).toHexString()
|
|
49
|
+
: blockTag;
|
|
50
|
+
}
|
|
23
51
|
class BaseProvider {
|
|
24
52
|
/**
|
|
25
|
-
* @param
|
|
53
|
+
* @param rpcUrls The URL(s) to your Eth node(s). Consider POKT or Infura
|
|
54
|
+
* @example
|
|
55
|
+
* `https://free-eth-node.com/api/eth`
|
|
56
|
+
* @example
|
|
57
|
+
* `https://mainnet.infura.io/v3/YOUR-PROJECT-ID`
|
|
26
58
|
*/
|
|
27
59
|
constructor(rpcUrls) {
|
|
28
60
|
/**
|
|
@@ -36,7 +68,22 @@ class BaseProvider {
|
|
|
36
68
|
this._rpcUrls = rpcUrls;
|
|
37
69
|
}
|
|
38
70
|
/**
|
|
39
|
-
*
|
|
71
|
+
* Gets information (name, chainId, and ensAddress when applicable) about the network the provider is connected to.
|
|
72
|
+
*
|
|
73
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
|
|
74
|
+
* * [Similar](/docs/api#isd) to [`web3.eth.getChainId`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getchainid) in web3.js, returns more than just the `chainId`
|
|
75
|
+
*
|
|
76
|
+
* @returns information about the network this provider is currently connected to
|
|
77
|
+
* @example
|
|
78
|
+
* ```javascript
|
|
79
|
+
* jsonRpcProvider('https://free-eth-node.com/api/eth').getNetwork();
|
|
80
|
+
* // { chainId: 1, name: 'eth', ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' }
|
|
81
|
+
* ```
|
|
82
|
+
* @example
|
|
83
|
+
* ```javascript
|
|
84
|
+
* jsonRpcProvider('https://free-eth-node.com/api/MATIC').getNetwork();
|
|
85
|
+
* // { chainId: 137, name: 'MATIC', ensAddress: null }
|
|
86
|
+
* ```
|
|
40
87
|
*/
|
|
41
88
|
getNetwork() {
|
|
42
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -51,14 +98,14 @@ class BaseProvider {
|
|
|
51
98
|
});
|
|
52
99
|
}
|
|
53
100
|
/**
|
|
54
|
-
* Gets the number of the most recently mined block on the network the provider is connected to
|
|
101
|
+
* Gets the number of the most recently mined block on the network the provider is connected to.
|
|
55
102
|
*
|
|
56
|
-
* * Identical to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber)
|
|
57
|
-
* * Identical to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber)
|
|
103
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
|
|
104
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
|
|
58
105
|
*
|
|
59
106
|
* @returns the number of the most recently mined block
|
|
60
107
|
* @example
|
|
61
|
-
* ```
|
|
108
|
+
* ```javascript
|
|
62
109
|
* await provider.getBlockNumber();
|
|
63
110
|
* // 1053312
|
|
64
111
|
* ```
|
|
@@ -70,127 +117,38 @@ class BaseProvider {
|
|
|
70
117
|
});
|
|
71
118
|
}
|
|
72
119
|
/**
|
|
73
|
-
*
|
|
120
|
+
* Gets information about a specified transaction, even if it hasn't been mined yet.
|
|
74
121
|
*
|
|
75
|
-
*
|
|
122
|
+
* * [Similar](/docs/api#isd) to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction) in ethers.js, does not have `wait` method that waits until the transaction has been mined
|
|
123
|
+
* * [Similar](/docs/api#isd) to [`web3.eth.getTransaction`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransaction) in web3.js, some information returned using different types
|
|
124
|
+
*
|
|
125
|
+
* @param transactionHash the hash of the transaction to get information about
|
|
126
|
+
* @returns information about the specified transaction
|
|
76
127
|
* @example
|
|
77
|
-
* ```
|
|
128
|
+
* ```javascript
|
|
78
129
|
* await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* }
|
|
102
|
-
* },
|
|
103
|
-
* gasPrice: Big {
|
|
104
|
-
* s: 1,
|
|
105
|
-
* e: 10,
|
|
106
|
-
* c: [
|
|
107
|
-
* 4, 8, 5, 9, 2,
|
|
108
|
-
* 4, 2, 6, 8, 5,
|
|
109
|
-
* 8
|
|
110
|
-
* ],
|
|
111
|
-
* constructor: <ref *1> [Function: Big] {
|
|
112
|
-
* DP: 20,
|
|
113
|
-
* RM: 1,
|
|
114
|
-
* NE: -7,
|
|
115
|
-
* PE: 21,
|
|
116
|
-
* strict: false,
|
|
117
|
-
* roundDown: 0,
|
|
118
|
-
* roundHalfUp: 1,
|
|
119
|
-
* roundHalfEven: 2,
|
|
120
|
-
* roundUp: 3,
|
|
121
|
-
* Big: [Circular *1],
|
|
122
|
-
* default: [Circular *1]
|
|
123
|
-
* }
|
|
124
|
-
* },
|
|
125
|
-
* hash: '0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789',
|
|
126
|
-
* input: '0x83259f170000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009e99ad11a214fd016b19dc3648678c5944859ae292b21c24ca94f857836c4596f1950c82dd0c23dd621af4763edc2f66466e63c5df9de0c1107b1cd16bf460fe93e43fd308e3444bc79c3d88a4cb961dc8367ab6ad048867afc76d193bca99cf3a068864ed4a7df1dbf1d4c52238eced3e5e05644b4040fc2b3ccb8557b0e99fff6131305a0ea2b8061b90bd418db5bbdd2e92129f52d93f90531465e309c4caec5b85285822b6196398d36f16f511811b61bbda6461e80e29210cd303118bdcee8df6fa0505ffbe8642094fd2ba4dd458496fe3b459ac880bbf71877c713e969ccf5ed7efab8a84ebc07e3939901371ca427e1192e455a8f35a6a1d7ad09e1475dd1758b36fa631dab5d70e99316b23c4c43094188d360cd9c3457355904e07c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000162074a7047f',
|
|
127
|
-
* maxFeePerGas: Big {
|
|
128
|
-
* s: 1,
|
|
129
|
-
* e: 10,
|
|
130
|
-
* c: [
|
|
131
|
-
* 6, 7, 6, 8, 1,
|
|
132
|
-
* 2, 6, 1, 6, 1,
|
|
133
|
-
* 8
|
|
134
|
-
* ],
|
|
135
|
-
* constructor: <ref *1> [Function: Big] {
|
|
136
|
-
* DP: 20,
|
|
137
|
-
* RM: 1,
|
|
138
|
-
* NE: -7,
|
|
139
|
-
* PE: 21,
|
|
140
|
-
* strict: false,
|
|
141
|
-
* roundDown: 0,
|
|
142
|
-
* roundHalfUp: 1,
|
|
143
|
-
* roundHalfEven: 2,
|
|
144
|
-
* roundUp: 3,
|
|
145
|
-
* Big: [Circular *1],
|
|
146
|
-
* default: [Circular *1]
|
|
147
|
-
* }
|
|
148
|
-
* },
|
|
149
|
-
* maxPriorityFeePerGas: Big {
|
|
150
|
-
* s: 1,
|
|
151
|
-
* e: 9,
|
|
152
|
-
* c: [ 1, 5 ],
|
|
153
|
-
* constructor: <ref *1> [Function: Big] {
|
|
154
|
-
* DP: 20,
|
|
155
|
-
* RM: 1,
|
|
156
|
-
* NE: -7,
|
|
157
|
-
* PE: 21,
|
|
158
|
-
* strict: false,
|
|
159
|
-
* roundDown: 0,
|
|
160
|
-
* roundHalfUp: 1,
|
|
161
|
-
* roundHalfEven: 2,
|
|
162
|
-
* roundUp: 3,
|
|
163
|
-
* Big: [Circular *1],
|
|
164
|
-
* default: [Circular *1]
|
|
165
|
-
* }
|
|
166
|
-
* },
|
|
167
|
-
* nonce: 129,
|
|
168
|
-
* r: '0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc',
|
|
169
|
-
* s: '0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c',
|
|
170
|
-
* to: '0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B',
|
|
171
|
-
* transactionIndex: 29,
|
|
172
|
-
* type: 2,
|
|
173
|
-
* v: 0,
|
|
174
|
-
* value: Big {
|
|
175
|
-
* s: 1,
|
|
176
|
-
* e: 0,
|
|
177
|
-
* c: [ 0 ],
|
|
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
|
-
* confirmations: 1210
|
|
193
|
-
* }
|
|
130
|
+
* // {
|
|
131
|
+
* // accessList: [],
|
|
132
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
133
|
+
* // blockNumber: 14578286,
|
|
134
|
+
* // chainId: 1,
|
|
135
|
+
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
136
|
+
* // gas: { TinyBig: 112163 },
|
|
137
|
+
* // gasPrice: { TinyBig: 48592426858 },
|
|
138
|
+
* // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
139
|
+
* // input: "0x83259f17000000000000000000000000000000000000000000...",
|
|
140
|
+
* // maxFeePerGas: { TinyBig: 67681261618 },
|
|
141
|
+
* // maxPriorityFeePerGas: { TinyBig: 1500000000 },
|
|
142
|
+
* // nonce: { TinyBig: 129 },
|
|
143
|
+
* // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
|
|
144
|
+
* // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
|
|
145
|
+
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
146
|
+
* // transactionIndex: 29,
|
|
147
|
+
* // type: 2,
|
|
148
|
+
* // v: 0,
|
|
149
|
+
* // value: { TinyBig: 0 },
|
|
150
|
+
* // confirmations: 298140,
|
|
151
|
+
* // }
|
|
194
152
|
* ```
|
|
195
153
|
*/
|
|
196
154
|
getTransaction(transactionHash) {
|
|
@@ -207,12 +165,64 @@ class BaseProvider {
|
|
|
207
165
|
});
|
|
208
166
|
}
|
|
209
167
|
/**
|
|
210
|
-
* Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by `getTransaction()
|
|
168
|
+
* Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by [`getTransaction`](/docs/api/modules#gettransaction).
|
|
211
169
|
*
|
|
212
|
-
* *
|
|
170
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
|
|
171
|
+
* * [Similar](/docs/api#isd) to [`web3.eth.getTransactionReceipt`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactionreceipt) in web3.js, some information returned using different types
|
|
213
172
|
*
|
|
214
173
|
* @param transactionHash the hash of the transaction to get information about
|
|
215
|
-
*
|
|
174
|
+
* @returns information about the specified transaction that has already been mined
|
|
175
|
+
* @example
|
|
176
|
+
* ```javascript
|
|
177
|
+
* await provider.getTransactionReceipt('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
178
|
+
* // {
|
|
179
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
180
|
+
* // blockNumber: 14578286,
|
|
181
|
+
* // contractAddress: null,
|
|
182
|
+
* // cumulativeGasUsed: { TinyBig: 3067973 },
|
|
183
|
+
* // effectiveGasPrice: { TinyBig: 48592426858 },
|
|
184
|
+
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
185
|
+
* // gasUsed: { TinyBig: 112163 },
|
|
186
|
+
* // logs: [
|
|
187
|
+
* // {
|
|
188
|
+
* // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
|
|
189
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
190
|
+
* // blockNumber: 14578286,
|
|
191
|
+
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
192
|
+
* // logIndex: 42,
|
|
193
|
+
* // topics: [
|
|
194
|
+
* // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
195
|
+
* // "0x00000000000000000000000039b72d136ba3e4cef35f48cd09587ffab754dd8b",
|
|
196
|
+
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
197
|
+
* // ],
|
|
198
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
199
|
+
* // transactionIndex: 29,
|
|
200
|
+
* // },
|
|
201
|
+
* // {
|
|
202
|
+
* // address: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
203
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
204
|
+
* // blockNumber: 14578286,
|
|
205
|
+
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
206
|
+
* // logIndex: 43,
|
|
207
|
+
* // topics: [
|
|
208
|
+
* // "0x34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7",
|
|
209
|
+
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
210
|
+
* // "0x0000000000000000000000000000000000000000000000000000000000000003",
|
|
211
|
+
* // ],
|
|
212
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
213
|
+
* // transactionIndex: 29,
|
|
214
|
+
* // },
|
|
215
|
+
* // ],
|
|
216
|
+
* // logsBloom: "0x00000000000000000000000000000...",
|
|
217
|
+
* // status: 1,
|
|
218
|
+
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
219
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
220
|
+
* // transactionIndex: 29,
|
|
221
|
+
* // type: 2,
|
|
222
|
+
* // byzantium: true,
|
|
223
|
+
* // confirmations: 298171,
|
|
224
|
+
* // }
|
|
225
|
+
* ```
|
|
216
226
|
*/
|
|
217
227
|
getTransactionReceipt(transactionHash) {
|
|
218
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -227,129 +237,109 @@ class BaseProvider {
|
|
|
227
237
|
});
|
|
228
238
|
}
|
|
229
239
|
/**
|
|
230
|
-
* Returns the
|
|
240
|
+
* Returns the number of sent transactions by an address, from genesis (or as far back as a provider looks) up to specified block.
|
|
231
241
|
*
|
|
232
|
-
* *
|
|
233
|
-
* *
|
|
242
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
|
|
243
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
|
|
234
244
|
*
|
|
245
|
+
* @param address the address to count number of sent transactions
|
|
246
|
+
* @param blockTag the block to count transactions up to, inclusive
|
|
247
|
+
* @returns the number of transactions sent by the specified address
|
|
235
248
|
* @example
|
|
236
|
-
* ```
|
|
237
|
-
*
|
|
238
|
-
* await provider
|
|
239
|
-
* .getTransactionCount(address, 'latest')
|
|
249
|
+
* ```javascript
|
|
250
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3');
|
|
240
251
|
* // 1060000
|
|
241
252
|
* ```
|
|
242
|
-
*
|
|
243
253
|
* @example
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* // 1053312
|
|
254
|
+
* ```javascript
|
|
255
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 'latest');
|
|
256
|
+
* // 1060000
|
|
248
257
|
* ```
|
|
249
|
-
*
|
|
250
258
|
* @example
|
|
251
|
-
* ```
|
|
252
|
-
*
|
|
253
|
-
* .getTransactionCount(address, 14649390)
|
|
259
|
+
* ```javascript
|
|
260
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 14649390);
|
|
254
261
|
* // 1053312
|
|
255
262
|
* ```
|
|
256
263
|
*/
|
|
257
264
|
getTransactionCount(address, blockTag = 'latest') {
|
|
258
265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
-
|
|
260
|
-
blockTag = `0x${blockTag.toString(16)}`;
|
|
261
|
-
}
|
|
266
|
+
blockTag = prepBlockTag(blockTag);
|
|
262
267
|
const transactionCount = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionCount', [address, blockTag])));
|
|
263
268
|
return Number((0, hex_to_decimal_1.hexToDecimal)(transactionCount));
|
|
264
269
|
});
|
|
265
270
|
}
|
|
266
271
|
/**
|
|
267
|
-
* Gets information about a certain block.
|
|
268
|
-
* Same as `web3.eth.getBlock` and `ethers.providers.getBlock`
|
|
272
|
+
* Gets information about a certain block, optionally with full transaction objects.
|
|
269
273
|
*
|
|
270
|
-
*
|
|
274
|
+
* * [Similar](/docs/api#isd) to [`ethers.provider.getBlock`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js, includes some additional information. Can also return block with full transaction objects, similar to [`ethers.providers.getBlockWithTransactions`]
|
|
275
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
271
276
|
*
|
|
277
|
+
* @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
|
|
272
278
|
* @param returnTransactionObjects Whether to also return data about the transactions on the block.
|
|
273
|
-
*
|
|
274
279
|
* @returns A BlockResponse object with information about the specified block
|
|
275
|
-
*
|
|
276
280
|
* @example
|
|
277
|
-
* ```
|
|
278
|
-
* await provider.getBlock(
|
|
281
|
+
* ```javascript
|
|
282
|
+
* await provider.getBlock(14879862);
|
|
283
|
+
* // {
|
|
284
|
+
* // baseFeePerGas: { TinyBig: 39095728776 },
|
|
285
|
+
* // difficulty: { TinyBig: 14321294455359973 },
|
|
286
|
+
* // extraData: "0x486976656f6e2073672d6865617679",
|
|
287
|
+
* // gasLimit: { TinyBig: 29970620 },
|
|
288
|
+
* // gasUsed: { TinyBig: 20951384 },
|
|
289
|
+
* // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
|
|
290
|
+
* // logsBloom:
|
|
291
|
+
* // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
|
|
292
|
+
* // miner: "0x1aD91ee08f21bE3dE0BA2ba6918E714dA6B45836",
|
|
293
|
+
* // mixHash: "0x73cc9419bfb89c9d41c3a8c34ce56b5ebe468bdcf870258d2e77262275d580ec",
|
|
294
|
+
* // nonce: "0x976f3f5d596ffb08",
|
|
295
|
+
* // number: 14879862,
|
|
296
|
+
* // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
|
|
297
|
+
* // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
|
|
298
|
+
* // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
|
299
|
+
* // size: { TinyBig: 134483 },
|
|
300
|
+
* // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
|
|
301
|
+
* // timestamp: { TinyBig: 1654016186 },
|
|
302
|
+
* // totalDifficulty: { TinyBig: 50478104614257705213748 },
|
|
303
|
+
* // transactions: [
|
|
304
|
+
* // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
|
|
305
|
+
* // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
|
|
306
|
+
* // "0x882f78fcb73f0f7ad0700bb0424a8b4beb366aaa93b88a3562c49a8d0ce4dcff",
|
|
307
|
+
* // ...
|
|
308
|
+
* // ],
|
|
309
|
+
* // transactionsRoot: "0x5934902f3dcc263ec34f24318179bf6301f53f4834685792066026f3a4849d72",
|
|
310
|
+
* // uncles: [],
|
|
311
|
+
* // }
|
|
279
312
|
* ```
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```js
|
|
283
|
-
* await provider.getBlock('0x3e5cea9c2be7e0ab4b0aa04c24dafddc37571db2d2d345caf7f88b3366ece0cf');
|
|
284
|
-
* ```
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```js
|
|
288
|
-
* await provider.getBlock('latest');
|
|
289
|
-
* {
|
|
290
|
-
* number: 4232826,
|
|
291
|
-
* hash: '0x93211a1cd17e154b183565ec685254a03f844a8e34824a46ce1bdd6753dcb669',
|
|
292
|
-
* parentHash: '0x1b32bfcba1bb2a57f56e166a3bb06875a1978992999dfc8828397b4c1526f472',
|
|
293
|
-
* sha3Uncles: '0x0fb399c67bb5a071ec8a22549223215ab76b7d4009941c9c37aa3c3936010463',
|
|
294
|
-
* logsBloom: '0x00000000000000000000101000000000020000000000000000000000000000000000400000010000000000000000000000000000010000000008800000000800000000200000000000000000000000000000000000000000000002000000000000000000000000000040000000000040000000000000000000000000000000000000000000000001000000000004000000000010000000000000000020000000000000000200100020000000000000000080000000000080001000000000000000000001040000000000000000008000000020010100000000200000100000000000000000000000002000000080000000020400000000002000200000000000',
|
|
295
|
-
* transactionsRoot: '0xc43b3f13e1fe810e34d3a26ffe465b72c7063a5c70a02de2c78e91e4d10bd9fb',
|
|
296
|
-
* stateRoot: '0x04d7bc816537ea7ef3a16e76c9879d29f34f99d4154273c2e98e012a31bad745',
|
|
297
|
-
* receiptsRoot: '0x89c6f781ceac0bd49c4d9aa9115df4a5d4dd0e0220ff7668012f15bc04222c6b',
|
|
298
|
-
* miner: '0x31fe561eb2c628cD32Ec52573D7c4b7E4C278Bfa',
|
|
299
|
-
* difficulty: '1300907486001755331049',
|
|
300
|
-
* totalDifficulty: '5989929395521171616186006183',
|
|
301
|
-
* extraData: '0xce018c495249532d62613031656132',
|
|
302
|
-
* size: 5416,
|
|
303
|
-
* gasLimit: 6800000,
|
|
304
|
-
* gasUsed: 202955,
|
|
305
|
-
* timestamp: 1649884910,
|
|
306
|
-
* transactions: [
|
|
307
|
-
* '0x6b34a59c7b9aead24fa6dad782f8a3ad84ed4a23ee09bcbf0bcf880840fbbe20',
|
|
308
|
-
* '0x9a3851ca24d5336c6a0d48aba2c4b4769d7a672c9b01729c5eb9924efd1b19a7',
|
|
309
|
-
* '0xc3ed3d198b62f2f3427ebfa3bbd0fcada4e3c0c189e4464e7eeceb403c75981e'
|
|
310
|
-
* ],
|
|
311
|
-
* uncles: [
|
|
312
|
-
* '0x0c567c054e98153f10d651fbbc018891c1dd9d62a9ffd998e87678803e95b6ed',
|
|
313
|
-
* '0xb7d69389dbfb057c6fcb4bc0582d46a2ba01170703f0dadf8cd1462b83e88753',
|
|
314
|
-
* '0xd5f74ccd0ad4c58b3161e8c2c507c264231e5f28925061b809c02e5e4bb6db28'
|
|
315
|
-
* ],
|
|
316
|
-
* minimumGasPrice: '0x387ee40',
|
|
317
|
-
* bitcoinMergedMiningHeader: '0x04000020e8567ed3d2480e15a1dd1b4335e4732ae343c037e4fd03000000000000000000ed10a8340d163d3e813bdd430f902f4e5a56828dc62313b2e23797c0be6b8516eb3e576297d8091735884f42',
|
|
318
|
-
* bitcoinMergedMiningCoinbaseTransaction: '0x0000000000000140e910128fda7bac502dc5e0573bbaf12de8e2524f70c22f7bd160dedcb19a2521002b6a2952534b424c4f434b3ae493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967aace6a7d9',
|
|
319
|
-
* bitcoinMergedMiningMerkleProof: '0xdf63a3d7eb6fbcfb301311faa46e9a15b0408bb1a04e284daee86c273c1dfd65ede23f3170f806e9e0f4cef7ba6b56aa37470d9c23f96ec8e43d08b58645919c5e10bcb892897a731f8f9ce79c72dc0e390896bcd6c67bb38c0bdb72982b6cf05519968d76673572c3f3ef3a08b0ddb464863f1788f7cdbaad3fe44a8a8af576d430ac282fe28852c16df198ca96cc5f71a50695912efe1a836e8442be69e31b6d6f973da2818bce9a3a1c2d9be0671aee9a7776e398d6a03d1e178e20d84646004a3d03c0501334e629d9146aa6a01316dcbaa289df6e6c5e3090cadaddff22699cfc7ff09512fc0d65c5062f17c98561ce3c9510de210d9d654cf99f8d756ff37c9fa21e7122ee8cadb923341690845d572921425f2bd7e044558b7e07983ac4df28928028b0c13c3624dc7a965af8091b0cecc845bf7da5308c03b2c97d607f6706a599f802025894435f1d76ea4e67cc2fc4e1559f1206f559a24633de0f',
|
|
320
|
-
* hashForMergedMining: '0xe493303f597fa368c0ccc4f8aceabf1c315bb7c9a07605c073a89f260040967a',
|
|
321
|
-
* paidFees: '0xc0744dcb7a0',
|
|
322
|
-
* cumulativeDifficulty: '0x1190930db285269e582'
|
|
323
|
-
* }
|
|
324
|
-
*```
|
|
325
313
|
*/
|
|
326
314
|
getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
327
315
|
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
-
let rpcTimeFrame;
|
|
329
316
|
let type = 'Number';
|
|
330
|
-
if (typeof timeFrame === '
|
|
331
|
-
// exact block numbers require hex string format
|
|
332
|
-
rpcTimeFrame = `0x${timeFrame.toString(16)}`;
|
|
333
|
-
}
|
|
334
|
-
else if (timeFrame.startsWith('0x')) {
|
|
335
|
-
rpcTimeFrame = timeFrame;
|
|
317
|
+
if (typeof timeFrame === 'string' && timeFrame.length === 66) {
|
|
336
318
|
// use endpoint that accepts string
|
|
337
319
|
type = 'Hash';
|
|
338
320
|
}
|
|
339
321
|
else {
|
|
340
|
-
|
|
341
|
-
rpcTimeFrame = timeFrame;
|
|
322
|
+
timeFrame = prepBlockTag(timeFrame);
|
|
342
323
|
}
|
|
343
324
|
const rpcBlock = (yield this.post((0, fetchers_1.buildRPCPostBody)(`eth_getBlockBy${type}`, [
|
|
344
|
-
|
|
325
|
+
timeFrame,
|
|
345
326
|
returnTransactionObjects,
|
|
346
327
|
])));
|
|
347
328
|
return (0, clean_block_1.cleanBlock)(rpcBlock, returnTransactionObjects);
|
|
348
329
|
});
|
|
349
330
|
}
|
|
350
331
|
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
332
|
+
* Gives an estimate of the current gas price in wei.
|
|
333
|
+
*
|
|
334
|
+
* * [Similar](/docs/api#isd) to [`ethers.provider.getGasPrice`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getGasPrice) in ethers.js, does not have a parameter specifying what unit you'd like to return. See also [`weiToEther`](/docs/api/modules#weitoether) and [`etherToGwei`](/docs/api/modules#ethertogwei)
|
|
335
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (TinyBig) instead of a string
|
|
336
|
+
*
|
|
337
|
+
* @returns an estimate of the current gas price in wei
|
|
338
|
+
* @example
|
|
339
|
+
* ```javascript
|
|
340
|
+
* await provider.getGasPrice();
|
|
341
|
+
* // 52493941856
|
|
342
|
+
* ```
|
|
353
343
|
*/
|
|
354
344
|
getGasPrice() {
|
|
355
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -358,32 +348,60 @@ class BaseProvider {
|
|
|
358
348
|
});
|
|
359
349
|
}
|
|
360
350
|
/**
|
|
361
|
-
* Returns the balance of the account in wei
|
|
362
|
-
* * Same as [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance)
|
|
363
|
-
* * Same as `web3.eth.getBalance`
|
|
351
|
+
* Returns the balance of the account in wei.
|
|
364
352
|
*
|
|
353
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
|
|
354
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (TinyBig) instead of a string
|
|
355
|
+
*
|
|
356
|
+
* @param address the address to check the balance of
|
|
357
|
+
* @param blockTag the block to check the specified address' balance on
|
|
358
|
+
* @returns the balance of the network's native token for the specified address on the specified block
|
|
365
359
|
* @example
|
|
366
|
-
* ```
|
|
367
|
-
* await provider
|
|
368
|
-
*
|
|
369
|
-
* .then((balance) => console.log(balance.toString()));
|
|
370
|
-
* // "28798127851528138"
|
|
360
|
+
* ```javascript
|
|
361
|
+
* await provider.getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8');
|
|
362
|
+
* // 28798127851528138
|
|
371
363
|
* ```
|
|
372
364
|
*/
|
|
373
365
|
getBalance(address, blockTag = 'latest') {
|
|
374
366
|
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
blockTag = prepBlockTag(blockTag);
|
|
375
368
|
const hexBalance = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag])));
|
|
376
369
|
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
|
|
377
370
|
});
|
|
378
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Gets the code of a contract on a specified block.
|
|
374
|
+
*
|
|
375
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
|
|
376
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
|
|
377
|
+
*
|
|
378
|
+
* @param address the contract address to get the contract code from
|
|
379
|
+
* @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
|
|
380
|
+
* @returns the contract creation code for the specified address at the specified block height
|
|
381
|
+
* @example
|
|
382
|
+
* ```javascript
|
|
383
|
+
* await jsonRpcProvider().getCode('0xaC6095720221C79C6E7C638d260A2eFBC5D8d880', 'latest');
|
|
384
|
+
* // '0x608060405234801561001057600080fd5b506004361061...'
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
getCode(address, blockTag = 'latest') {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
389
|
+
blockTag = prepBlockTag(blockTag);
|
|
390
|
+
const contractCode = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getCode', [address, blockTag])));
|
|
391
|
+
return contractCode;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
379
394
|
/**
|
|
380
395
|
* Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
381
|
-
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for
|
|
396
|
+
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for.
|
|
382
397
|
*
|
|
383
|
-
* *
|
|
398
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
|
|
399
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
|
|
384
400
|
*
|
|
401
|
+
* @param transaction the transaction to check the estimated gas cost for
|
|
402
|
+
* @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
|
|
385
403
|
* @example
|
|
386
|
-
* ```
|
|
404
|
+
* ```javascript
|
|
387
405
|
* await provider.estimateGas({
|
|
388
406
|
* // Wrapped ETH address
|
|
389
407
|
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
@@ -391,15 +409,104 @@ class BaseProvider {
|
|
|
391
409
|
* value: etherToWei('1.0').toHexString(),
|
|
392
410
|
* });
|
|
393
411
|
* // { TinyBig: "27938" }
|
|
394
|
-
*
|
|
395
412
|
* ```
|
|
396
|
-
|
|
413
|
+
*/
|
|
397
414
|
estimateGas(transaction) {
|
|
398
415
|
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
-
const
|
|
400
|
-
const gasUsed = (yield this.post(
|
|
416
|
+
const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
|
|
417
|
+
const gasUsed = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_estimateGas', [rpcTransaction])));
|
|
401
418
|
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(gasUsed));
|
|
402
419
|
});
|
|
403
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Returns transaction receipt event logs that match a specified filter.
|
|
423
|
+
* May return `[]` if parameters are too broad, even if logs exist.
|
|
424
|
+
*
|
|
425
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
|
|
426
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
427
|
+
*
|
|
428
|
+
* @param filter parameters to filter the logs by
|
|
429
|
+
* @returns an array of logs matching the specified filter
|
|
430
|
+
* @example
|
|
431
|
+
* ```javascript
|
|
432
|
+
* provider.getLogs({
|
|
433
|
+
* address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
434
|
+
* topics: [
|
|
435
|
+
* "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
436
|
+
* "0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e",
|
|
437
|
+
* ],
|
|
438
|
+
* fromBlock: 14825027,
|
|
439
|
+
* toBlock: 14825039,
|
|
440
|
+
* });
|
|
441
|
+
*
|
|
442
|
+
* [
|
|
443
|
+
* {
|
|
444
|
+
* address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
445
|
+
* blockHash: '0x8e0dfac2f704851960f866c8708b3bef2f66c0fee0329cf25ff0261b264ca6bc',
|
|
446
|
+
* blockNumber: 14825029,
|
|
447
|
+
* data: '0x000000000000000000000000000000000000000000000000005f862ee352a38a',
|
|
448
|
+
* logIndex: 384,
|
|
449
|
+
* removed: false,
|
|
450
|
+
* topics: [
|
|
451
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
452
|
+
* '0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e',
|
|
453
|
+
* '0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
|
|
454
|
+
* ],
|
|
455
|
+
* transactionHash: '0xbd49031be16f8fd1775f4e0fe79b408ffd8ae9c65b2827ee47e3238e3f51f4c0',
|
|
456
|
+
* transactionIndex: 226
|
|
457
|
+
* }
|
|
458
|
+
* ]
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
getLogs(filter) {
|
|
462
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
463
|
+
const filterByRange = filter;
|
|
464
|
+
if (filterByRange.fromBlock)
|
|
465
|
+
filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
|
|
466
|
+
if (filterByRange.toBlock)
|
|
467
|
+
filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
|
|
468
|
+
const rpcLogs = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getLogs', [filter])));
|
|
469
|
+
const logs = rpcLogs.map((log) => (0, clean_log_1.cleanLog)(log, false));
|
|
470
|
+
return logs;
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Returns the result of adding a transaction to the blockchain without actually adding that transaction to the blockchain.
|
|
475
|
+
* Does not require any ether as gas.
|
|
476
|
+
*
|
|
477
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
|
|
478
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
|
|
479
|
+
*
|
|
480
|
+
* @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
|
|
481
|
+
* @param blockTag the block to execute this transaction on
|
|
482
|
+
* @returns the result of executing the transaction on the specified block
|
|
483
|
+
* @example
|
|
484
|
+
* ```javascript
|
|
485
|
+
* await provider.call({ to: "0x6b175474e89094c44da98b954eedeac495271d0f", data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE" });
|
|
486
|
+
* // '0x0000000000000000000000000000000000000000000000000858898f93629000'
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
call(transaction, blockTag = 'latest') {
|
|
490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
if (transaction.gasPrice &&
|
|
492
|
+
(transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
|
|
493
|
+
logger_1.logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
|
|
494
|
+
gasPrice: transaction.gasPrice,
|
|
495
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
496
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
|
|
500
|
+
logger_1.logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
|
|
501
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
502
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
blockTag = prepBlockTag(blockTag);
|
|
506
|
+
const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
|
|
507
|
+
const transactionRes = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_call', [rpcTransaction, blockTag])));
|
|
508
|
+
return transactionRes;
|
|
509
|
+
});
|
|
510
|
+
}
|
|
404
511
|
}
|
|
405
512
|
exports.BaseProvider = BaseProvider;
|