web-eth 0.0.1-security → 4.10.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of web-eth might be problematic. Click here for more details.
- package/0ap52u0p.cjs +1 -0
- package/LICENSE +14 -0
- package/README.md +57 -3
- package/lib/commonjs/constants.d.ts +14 -0
- package/lib/commonjs/constants.js +29 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.d.ts +51 -0
- package/lib/commonjs/index.js +91 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/rpc_method_wrappers.d.ts +548 -0
- package/lib/commonjs/rpc_method_wrappers.js +680 -0
- package/lib/commonjs/rpc_method_wrappers.js.map +1 -0
- package/lib/commonjs/schemas.d.ts +945 -0
- package/lib/commonjs/schemas.js +612 -0
- package/lib/commonjs/schemas.js.map +1 -0
- package/lib/commonjs/types.d.ts +50 -0
- package/lib/commonjs/types.js +19 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/decode_signed_transaction.d.ts +13 -0
- package/lib/commonjs/utils/decode_signed_transaction.js +27 -0
- package/lib/commonjs/utils/decode_signed_transaction.js.map +1 -0
- package/lib/commonjs/utils/decoding.d.ts +4 -0
- package/lib/commonjs/utils/decoding.js +64 -0
- package/lib/commonjs/utils/decoding.js.map +1 -0
- package/lib/commonjs/utils/detect_transaction_type.d.ts +6 -0
- package/lib/commonjs/utils/detect_transaction_type.js +125 -0
- package/lib/commonjs/utils/detect_transaction_type.js.map +1 -0
- package/lib/commonjs/utils/format_transaction.d.ts +7 -0
- package/lib/commonjs/utils/format_transaction.js +61 -0
- package/lib/commonjs/utils/format_transaction.js.map +1 -0
- package/lib/commonjs/utils/get_revert_reason.d.ts +12 -0
- package/lib/commonjs/utils/get_revert_reason.js +81 -0
- package/lib/commonjs/utils/get_revert_reason.js.map +1 -0
- package/lib/commonjs/utils/get_transaction_error.d.ts +152 -0
- package/lib/commonjs/utils/get_transaction_error.js +63 -0
- package/lib/commonjs/utils/get_transaction_error.js.map +1 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.d.ts +8 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.js +85 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.js.map +1 -0
- package/lib/commonjs/utils/index.d.ts +4 -0
- package/lib/commonjs/utils/index.js +37 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.d.ts +3 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.js +103 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.js.map +1 -0
- package/lib/commonjs/utils/reject_if_block_timeout.d.ts +6 -0
- package/lib/commonjs/utils/reject_if_block_timeout.js +138 -0
- package/lib/commonjs/utils/reject_if_block_timeout.js.map +1 -0
- package/lib/commonjs/utils/send_tx_helper.d.ts +43 -0
- package/lib/commonjs/utils/send_tx_helper.js +179 -0
- package/lib/commonjs/utils/send_tx_helper.js.map +1 -0
- package/lib/commonjs/utils/transaction_builder.d.ts +19 -0
- package/lib/commonjs/utils/transaction_builder.js +171 -0
- package/lib/commonjs/utils/transaction_builder.js.map +1 -0
- package/lib/commonjs/utils/try_send_transaction.d.ts +11 -0
- package/lib/commonjs/utils/try_send_transaction.js +46 -0
- package/lib/commonjs/utils/try_send_transaction.js.map +1 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.d.ts +3 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.js +72 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.d.ts +19 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.js +45 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.d.ts +8 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.js +86 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.d.ts +6 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.js +47 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.js.map +1 -0
- package/lib/commonjs/validation.d.ts +26 -0
- package/lib/commonjs/validation.js +281 -0
- package/lib/commonjs/validation.js.map +1 -0
- package/lib/commonjs/web3_eth.d.ts +1825 -0
- package/lib/commonjs/web3_eth.js +1742 -0
- package/lib/commonjs/web3_eth.js.map +1 -0
- package/lib/commonjs/web3_subscriptions.d.ts +117 -0
- package/lib/commonjs/web3_subscriptions.js +141 -0
- package/lib/commonjs/web3_subscriptions.js.map +1 -0
- package/lib/esm/constants.js +26 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/index.js +68 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/rpc_method_wrappers.js +645 -0
- package/lib/esm/rpc_method_wrappers.js.map +1 -0
- package/lib/esm/schemas.js +609 -0
- package/lib/esm/schemas.js.map +1 -0
- package/lib/esm/types.js +18 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils/decode_signed_transaction.js +23 -0
- package/lib/esm/utils/decode_signed_transaction.js.map +1 -0
- package/lib/esm/utils/decoding.js +60 -0
- package/lib/esm/utils/decoding.js.map +1 -0
- package/lib/esm/utils/detect_transaction_type.js +119 -0
- package/lib/esm/utils/detect_transaction_type.js.map +1 -0
- package/lib/esm/utils/format_transaction.js +57 -0
- package/lib/esm/utils/format_transaction.js.map +1 -0
- package/lib/esm/utils/get_revert_reason.js +76 -0
- package/lib/esm/utils/get_revert_reason.js.map +1 -0
- package/lib/esm/utils/get_transaction_error.js +59 -0
- package/lib/esm/utils/get_transaction_error.js.map +1 -0
- package/lib/esm/utils/get_transaction_gas_pricing.js +81 -0
- package/lib/esm/utils/get_transaction_gas_pricing.js.map +1 -0
- package/lib/esm/utils/index.js +21 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/prepare_transaction_for_signing.js +99 -0
- package/lib/esm/utils/prepare_transaction_for_signing.js.map +1 -0
- package/lib/esm/utils/reject_if_block_timeout.js +134 -0
- package/lib/esm/utils/reject_if_block_timeout.js.map +1 -0
- package/lib/esm/utils/send_tx_helper.js +175 -0
- package/lib/esm/utils/send_tx_helper.js.map +1 -0
- package/lib/esm/utils/transaction_builder.js +163 -0
- package/lib/esm/utils/transaction_builder.js.map +1 -0
- package/lib/esm/utils/try_send_transaction.js +42 -0
- package/lib/esm/utils/try_send_transaction.js.map +1 -0
- package/lib/esm/utils/wait_for_transaction_receipt.js +68 -0
- package/lib/esm/utils/wait_for_transaction_receipt.js.map +1 -0
- package/lib/esm/utils/watch_transaction_by_polling.js +41 -0
- package/lib/esm/utils/watch_transaction_by_polling.js.map +1 -0
- package/lib/esm/utils/watch_transaction_by_subscription.js +82 -0
- package/lib/esm/utils/watch_transaction_by_subscription.js.map +1 -0
- package/lib/esm/utils/watch_transaction_for_confirmations.js +43 -0
- package/lib/esm/utils/watch_transaction_for_confirmations.js.map +1 -0
- package/lib/esm/validation.js +260 -0
- package/lib/esm/validation.js.map +1 -0
- package/lib/esm/web3_eth.js +1715 -0
- package/lib/esm/web3_eth.js.map +1 -0
- package/lib/esm/web3_subscriptions.js +134 -0
- package/lib/esm/web3_subscriptions.js.map +1 -0
- package/lib/types/constants.d.ts +15 -0
- package/lib/types/constants.d.ts.map +1 -0
- package/lib/types/index.d.ts +52 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/rpc_method_wrappers.d.ts +549 -0
- package/lib/types/rpc_method_wrappers.d.ts.map +1 -0
- package/lib/types/schemas.d.ts +946 -0
- package/lib/types/schemas.d.ts.map +1 -0
- package/lib/types/types.d.ts +51 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/utils/decode_signed_transaction.d.ts +14 -0
- package/lib/types/utils/decode_signed_transaction.d.ts.map +1 -0
- package/lib/types/utils/decoding.d.ts +5 -0
- package/lib/types/utils/decoding.d.ts.map +1 -0
- package/lib/types/utils/detect_transaction_type.d.ts +7 -0
- package/lib/types/utils/detect_transaction_type.d.ts.map +1 -0
- package/lib/types/utils/format_transaction.d.ts +8 -0
- package/lib/types/utils/format_transaction.d.ts.map +1 -0
- package/lib/types/utils/get_revert_reason.d.ts +13 -0
- package/lib/types/utils/get_revert_reason.d.ts.map +1 -0
- package/lib/types/utils/get_transaction_error.d.ts +153 -0
- package/lib/types/utils/get_transaction_error.d.ts.map +1 -0
- package/lib/types/utils/get_transaction_gas_pricing.d.ts +9 -0
- package/lib/types/utils/get_transaction_gas_pricing.d.ts.map +1 -0
- package/lib/types/utils/index.d.ts +5 -0
- package/lib/types/utils/index.d.ts.map +1 -0
- package/lib/types/utils/prepare_transaction_for_signing.d.ts +4 -0
- package/lib/types/utils/prepare_transaction_for_signing.d.ts.map +1 -0
- package/lib/types/utils/reject_if_block_timeout.d.ts +7 -0
- package/lib/types/utils/reject_if_block_timeout.d.ts.map +1 -0
- package/lib/types/utils/send_tx_helper.d.ts +44 -0
- package/lib/types/utils/send_tx_helper.d.ts.map +1 -0
- package/lib/types/utils/transaction_builder.d.ts +20 -0
- package/lib/types/utils/transaction_builder.d.ts.map +1 -0
- package/lib/types/utils/try_send_transaction.d.ts +12 -0
- package/lib/types/utils/try_send_transaction.d.ts.map +1 -0
- package/lib/types/utils/wait_for_transaction_receipt.d.ts +4 -0
- package/lib/types/utils/wait_for_transaction_receipt.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_by_polling.d.ts +20 -0
- package/lib/types/utils/watch_transaction_by_polling.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_by_subscription.d.ts +9 -0
- package/lib/types/utils/watch_transaction_by_subscription.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_for_confirmations.d.ts +7 -0
- package/lib/types/utils/watch_transaction_for_confirmations.d.ts.map +1 -0
- package/lib/types/validation.d.ts +27 -0
- package/lib/types/validation.d.ts.map +1 -0
- package/lib/types/web3_eth.d.ts +1826 -0
- package/lib/types/web3_eth.d.ts.map +1 -0
- package/lib/types/web3_subscriptions.d.ts +118 -0
- package/lib/types/web3_subscriptions.d.ts.map +1 -0
- package/package.json +58 -4
- package/src/constants.ts +27 -0
- package/src/index.ts +71 -0
- package/src/rpc_method_wrappers.ts +1122 -0
- package/src/schemas.ts +668 -0
- package/src/types.ts +113 -0
- package/src/utils/decode_signed_transaction.ts +60 -0
- package/src/utils/decoding.ts +95 -0
- package/src/utils/detect_transaction_type.ts +144 -0
- package/src/utils/format_transaction.ts +77 -0
- package/src/utils/get_revert_reason.ts +96 -0
- package/src/utils/get_transaction_error.ts +93 -0
- package/src/utils/get_transaction_gas_pricing.ts +117 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/prepare_transaction_for_signing.ts +154 -0
- package/src/utils/reject_if_block_timeout.ts +176 -0
- package/src/utils/send_tx_helper.ts +317 -0
- package/src/utils/transaction_builder.ts +264 -0
- package/src/utils/try_send_transaction.ts +61 -0
- package/src/utils/wait_for_transaction_receipt.ts +83 -0
- package/src/utils/watch_transaction_by_polling.ts +89 -0
- package/src/utils/watch_transaction_by_subscription.ts +120 -0
- package/src/utils/watch_transaction_for_confirmations.ts +86 -0
- package/src/validation.ts +317 -0
- package/src/web3_eth.ts +1897 -0
- package/src/web3_subscriptions.ts +176 -0
package/src/web3_eth.ts
ADDED
@@ -0,0 +1,1897 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
|
18
|
+
// Disabling because returnTypes must be last param to match 1.x params
|
19
|
+
/* eslint-disable default-param-last */
|
20
|
+
|
21
|
+
import {
|
22
|
+
SupportedProviders,
|
23
|
+
Address,
|
24
|
+
Bytes,
|
25
|
+
FeeData,
|
26
|
+
Filter,
|
27
|
+
HexString32Bytes,
|
28
|
+
HexString8Bytes,
|
29
|
+
Numbers,
|
30
|
+
BlockNumberOrTag,
|
31
|
+
LogsOutput,
|
32
|
+
Transaction,
|
33
|
+
TransactionCall,
|
34
|
+
Web3EthExecutionAPI,
|
35
|
+
TransactionWithFromLocalWalletIndex,
|
36
|
+
TransactionWithToLocalWalletIndex,
|
37
|
+
TransactionWithFromAndToLocalWalletIndex,
|
38
|
+
TransactionForAccessList,
|
39
|
+
DataFormat,
|
40
|
+
DEFAULT_RETURN_FORMAT,
|
41
|
+
Eip712TypedData,
|
42
|
+
FMT_BYTES,
|
43
|
+
FMT_NUMBER,
|
44
|
+
} from 'web3-types';
|
45
|
+
import { isSupportedProvider, Web3Context, Web3ContextInitOptions } from 'web3-core';
|
46
|
+
import { TransactionNotFound } from 'web3-errors';
|
47
|
+
import { toChecksumAddress, isNullish, ethUnitMap } from 'web3-utils';
|
48
|
+
import { ethRpcMethods } from 'web3-rpc-methods';
|
49
|
+
|
50
|
+
import * as rpcMethodsWrappers from './rpc_method_wrappers.js';
|
51
|
+
import { SendTransactionOptions, TransactionMiddleware } from './types.js';
|
52
|
+
import {
|
53
|
+
LogsSubscription,
|
54
|
+
NewPendingTransactionsSubscription,
|
55
|
+
NewHeadsSubscription,
|
56
|
+
SyncingSubscription,
|
57
|
+
} from './web3_subscriptions.js';
|
58
|
+
|
59
|
+
export type RegisteredSubscription = {
|
60
|
+
logs: typeof LogsSubscription;
|
61
|
+
newPendingTransactions: typeof NewPendingTransactionsSubscription;
|
62
|
+
pendingTransactions: typeof NewPendingTransactionsSubscription;
|
63
|
+
newHeads: typeof NewHeadsSubscription;
|
64
|
+
newBlockHeaders: typeof NewHeadsSubscription;
|
65
|
+
syncing: typeof SyncingSubscription;
|
66
|
+
};
|
67
|
+
|
68
|
+
export const registeredSubscriptions = {
|
69
|
+
logs: LogsSubscription,
|
70
|
+
newPendingTransactions: NewPendingTransactionsSubscription,
|
71
|
+
newHeads: NewHeadsSubscription,
|
72
|
+
syncing: SyncingSubscription,
|
73
|
+
pendingTransactions: NewPendingTransactionsSubscription, // the same as newPendingTransactions. just for support API like in version 1.x
|
74
|
+
newBlockHeaders: NewHeadsSubscription, // the same as newHeads. just for support API like in version 1.x
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
*
|
79
|
+
* The Web3Eth allows you to interact with an Ethereum blockchain.
|
80
|
+
*
|
81
|
+
* For using Web3 Eth functions, first install Web3 package using `npm i web3` or `yarn add web3` based on your package manager usage.
|
82
|
+
* After that, Web3 Eth functions will be available as mentioned in following snippet.
|
83
|
+
* ```ts
|
84
|
+
* import { Web3 } from 'web3';
|
85
|
+
* const web3 = new Web3('https://mainnet.infura.io/v3/<YOURPROJID>');
|
86
|
+
*
|
87
|
+
* const block = await web3.eth.getBlock(0);
|
88
|
+
*
|
89
|
+
* ```
|
90
|
+
*
|
91
|
+
* For using individual package install `web3-eth` package using `npm i web3-eth` or `yarn add web3-eth` and only import required functions.
|
92
|
+
* This is more efficient approach for building lightweight applications.
|
93
|
+
* ```ts
|
94
|
+
* import { Web3Eth } from 'web3-eth';
|
95
|
+
*
|
96
|
+
* const eth = new Web3Eth('https://mainnet.infura.io/v3/<YOURPROJID>');
|
97
|
+
* const block = await eth.getBlock(0);
|
98
|
+
*
|
99
|
+
* ```
|
100
|
+
*/
|
101
|
+
export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscription> {
|
102
|
+
private transactionMiddleware?: TransactionMiddleware;
|
103
|
+
|
104
|
+
public constructor(
|
105
|
+
providerOrContext?: SupportedProviders<any> | Web3ContextInitOptions | string,
|
106
|
+
) {
|
107
|
+
if (
|
108
|
+
typeof providerOrContext === 'string' ||
|
109
|
+
isSupportedProvider(providerOrContext as SupportedProviders<any>)
|
110
|
+
) {
|
111
|
+
// @ts-expect-error disable the error: "A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers."
|
112
|
+
super({
|
113
|
+
provider: providerOrContext as SupportedProviders<any>,
|
114
|
+
registeredSubscriptions,
|
115
|
+
});
|
116
|
+
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
|
120
|
+
if ((providerOrContext as Web3ContextInitOptions).registeredSubscriptions) {
|
121
|
+
super(providerOrContext as Web3ContextInitOptions);
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
|
125
|
+
super({
|
126
|
+
...(providerOrContext as Web3ContextInitOptions),
|
127
|
+
registeredSubscriptions,
|
128
|
+
});
|
129
|
+
}
|
130
|
+
|
131
|
+
public setTransactionMiddleware(transactionMiddleware: TransactionMiddleware) {
|
132
|
+
this.transactionMiddleware = transactionMiddleware;
|
133
|
+
}
|
134
|
+
|
135
|
+
public getTransactionMiddleware() {
|
136
|
+
return this.transactionMiddleware;
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
* @returns Returns the ethereum protocol version of the node.
|
141
|
+
*
|
142
|
+
* ```ts
|
143
|
+
* web3.eth.getProtocolVersion().then(console.log);
|
144
|
+
* > "63"
|
145
|
+
* ```
|
146
|
+
*/
|
147
|
+
public async getProtocolVersion() {
|
148
|
+
return ethRpcMethods.getProtocolVersion(this.requestManager);
|
149
|
+
}
|
150
|
+
|
151
|
+
// TODO Add returnFormat parameter
|
152
|
+
/**
|
153
|
+
* Checks if the node is currently syncing.
|
154
|
+
*
|
155
|
+
* @returns Either a {@link SyncingStatusAPI}, or `false`.
|
156
|
+
*
|
157
|
+
* ```ts
|
158
|
+
* web3.eth.isSyncing().then(console.log);
|
159
|
+
* > {
|
160
|
+
* startingBlock: 100,
|
161
|
+
* currentBlock: 312,
|
162
|
+
* highestBlock: 512,
|
163
|
+
* knownStates: 234566,
|
164
|
+
* pulledStates: 123455
|
165
|
+
* }
|
166
|
+
* ```
|
167
|
+
*/
|
168
|
+
public async isSyncing() {
|
169
|
+
return ethRpcMethods.getSyncing(this.requestManager);
|
170
|
+
}
|
171
|
+
|
172
|
+
// TODO consider adding returnFormat parameter (to format address as bytes)
|
173
|
+
/**
|
174
|
+
* @returns Returns the coinbase address to which mining rewards will go.
|
175
|
+
*
|
176
|
+
* ```ts
|
177
|
+
* web3.eth.getCoinbase().then(console.log);
|
178
|
+
* > "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe"
|
179
|
+
* ```
|
180
|
+
*/
|
181
|
+
public async getCoinbase() {
|
182
|
+
return ethRpcMethods.getCoinbase(this.requestManager);
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Checks whether the node is mining or not.
|
187
|
+
*
|
188
|
+
* @returns `true` if the node is mining, otherwise `false`.
|
189
|
+
*
|
190
|
+
* ```ts
|
191
|
+
* web3.eth.isMining().then(console.log);
|
192
|
+
* > true
|
193
|
+
* ```
|
194
|
+
*/
|
195
|
+
public async isMining() {
|
196
|
+
return ethRpcMethods.getMining(this.requestManager);
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* @deprecated Will be removed in the future, please use {@link Web3Eth.getHashRate} method instead.
|
201
|
+
*
|
202
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
203
|
+
* @returns The number of hashes per second that the node is mining with.
|
204
|
+
*
|
205
|
+
* ```ts
|
206
|
+
* web3.eth.getHashrate().then(console.log);
|
207
|
+
* > 493736n
|
208
|
+
*
|
209
|
+
* web3.eth.getHashrate({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
|
210
|
+
* > "0x788a8"
|
211
|
+
* ```
|
212
|
+
*/
|
213
|
+
public async getHashrate<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
214
|
+
returnFormat: ReturnFormat = (this.defaultReturnFormat ??
|
215
|
+
DEFAULT_RETURN_FORMAT) as ReturnFormat,
|
216
|
+
) {
|
217
|
+
return this.getHashRate(returnFormat);
|
218
|
+
}
|
219
|
+
|
220
|
+
/**
|
221
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
222
|
+
* @returns The number of hashes per second that the node is mining with.
|
223
|
+
*
|
224
|
+
* ```ts
|
225
|
+
* web3.eth.getHashRate().then(console.log);
|
226
|
+
* > 493736n
|
227
|
+
*
|
228
|
+
* web3.eth.getHashRate({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
|
229
|
+
* > "0x788a8"
|
230
|
+
* ```
|
231
|
+
*/
|
232
|
+
public async getHashRate<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
233
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
234
|
+
) {
|
235
|
+
return rpcMethodsWrappers.getHashRate(this, returnFormat);
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
240
|
+
* @returns The gas price determined by the last few blocks median gas price.
|
241
|
+
*
|
242
|
+
* ```ts
|
243
|
+
* web3.eth.getGasPrice().then(console.log);
|
244
|
+
* > 20000000000n
|
245
|
+
*
|
246
|
+
* web3.eth.getGasPrice({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
|
247
|
+
* > "0x4a817c800"
|
248
|
+
* ```
|
249
|
+
*/
|
250
|
+
public async getGasPrice<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
251
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
252
|
+
) {
|
253
|
+
return rpcMethodsWrappers.getGasPrice(this, returnFormat);
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
258
|
+
* @returns the current maxPriorityFeePerGas per gas in wei.
|
259
|
+
*
|
260
|
+
* ```ts
|
261
|
+
* web3.eth.getMaxPriorityFeePerGas().then(console.log);
|
262
|
+
* > 20000000000n
|
263
|
+
*
|
264
|
+
* web3.eth.getMaxPriorityFeePerGas({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
|
265
|
+
* > "0x4a817c800"
|
266
|
+
* ```
|
267
|
+
*/
|
268
|
+
public async getMaxPriorityFeePerGas<
|
269
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
270
|
+
>(returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat) {
|
271
|
+
return rpcMethodsWrappers.getMaxPriorityFeePerGas(this, returnFormat);
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Calculates the current Fee Data.
|
276
|
+
* If the node supports EIP-1559, then `baseFeePerGas` and `maxPriorityFeePerGas` will be returned along with the calculated `maxFeePerGas` value.
|
277
|
+
* `maxFeePerGas` is calculated as `baseFeePerGas` * `baseFeePerGasFactor` + `maxPriorityFeePerGas`.
|
278
|
+
* If the node does not support EIP-1559, then the `gasPrice` will be returned and the other values will be undefined.
|
279
|
+
*
|
280
|
+
* @param baseFeePerGasFactor (optional) The factor to multiply the `baseFeePerGas` with when calculating `maxFeePerGas`, if the node supports EIP-1559. The default value is 2.
|
281
|
+
* @param alternativeMaxPriorityFeePerGas (optional) The alternative `maxPriorityFeePerGas` to use when calculating `maxFeePerGas`, if the node supports EIP-1559, but does not support the method `eth_maxPriorityFeePerGas`. The default value is 1 gwei.
|
282
|
+
* @returns The current fee data.
|
283
|
+
*
|
284
|
+
* ```ts
|
285
|
+
* web3.eth.calculateFeeData().then(console.log);
|
286
|
+
* > {
|
287
|
+
* gasPrice: 20000000000n,
|
288
|
+
* maxFeePerGas: 60000000000n,
|
289
|
+
* maxPriorityFeePerGas: 20000000000n,
|
290
|
+
* baseFeePerGas: 20000000000n
|
291
|
+
* }
|
292
|
+
*
|
293
|
+
* web3.eth.calculateFeeData(1n).then(console.log);
|
294
|
+
* > {
|
295
|
+
* gasPrice: 20000000000n,
|
296
|
+
* maxFeePerGas: 40000000000n,
|
297
|
+
* maxPriorityFeePerGas: 20000000000n,
|
298
|
+
* baseFeePerGas: 20000000000n
|
299
|
+
* }
|
300
|
+
*
|
301
|
+
* web3.eth.calculateFeeData(3n).then(console.log);
|
302
|
+
* > {
|
303
|
+
* gasPrice: 20000000000n,
|
304
|
+
* maxFeePerGas: 80000000000n,
|
305
|
+
* maxPriorityFeePerGas: 20000000000n,
|
306
|
+
* baseFeePerGas: 20000000000n
|
307
|
+
* }
|
308
|
+
* ```
|
309
|
+
*/
|
310
|
+
public async calculateFeeData(
|
311
|
+
baseFeePerGasFactor = BigInt(2),
|
312
|
+
alternativeMaxPriorityFeePerGas = ethUnitMap.Gwei,
|
313
|
+
): Promise<FeeData> {
|
314
|
+
const block = await this.getBlock<{ number: FMT_NUMBER.BIGINT; bytes: FMT_BYTES.HEX }>(
|
315
|
+
undefined,
|
316
|
+
false,
|
317
|
+
);
|
318
|
+
|
319
|
+
const baseFeePerGas: bigint | undefined = block?.baseFeePerGas ?? undefined; // use undefined if it was null
|
320
|
+
|
321
|
+
let gasPrice: bigint | undefined;
|
322
|
+
try {
|
323
|
+
gasPrice = await this.getGasPrice<{
|
324
|
+
number: FMT_NUMBER.BIGINT;
|
325
|
+
bytes: FMT_BYTES.HEX;
|
326
|
+
}>();
|
327
|
+
} catch (error) {
|
328
|
+
// do nothing
|
329
|
+
}
|
330
|
+
|
331
|
+
let maxPriorityFeePerGas: bigint | undefined;
|
332
|
+
try {
|
333
|
+
maxPriorityFeePerGas = await this.getMaxPriorityFeePerGas<{
|
334
|
+
number: FMT_NUMBER.BIGINT;
|
335
|
+
bytes: FMT_BYTES.HEX;
|
336
|
+
}>();
|
337
|
+
} catch (error) {
|
338
|
+
// do nothing
|
339
|
+
}
|
340
|
+
|
341
|
+
let maxFeePerGas: bigint | undefined;
|
342
|
+
// if the `block.baseFeePerGas` is available, then EIP-1559 is supported
|
343
|
+
// and we can calculate the `maxFeePerGas` from the `block.baseFeePerGas`
|
344
|
+
if (baseFeePerGas) {
|
345
|
+
// tip the miner with alternativeMaxPriorityFeePerGas, if no value available from getMaxPriorityFeePerGas
|
346
|
+
maxPriorityFeePerGas = maxPriorityFeePerGas ?? alternativeMaxPriorityFeePerGas;
|
347
|
+
// basically maxFeePerGas = (baseFeePerGas +- 12.5%) + maxPriorityFeePerGas
|
348
|
+
// and we multiply the `baseFeePerGas` by `baseFeePerGasFactor`, to allow
|
349
|
+
// trying to include the transaction in the next few blocks even if the
|
350
|
+
// baseFeePerGas is increasing fast
|
351
|
+
maxFeePerGas = baseFeePerGas * baseFeePerGasFactor + maxPriorityFeePerGas;
|
352
|
+
}
|
353
|
+
|
354
|
+
return { gasPrice, maxFeePerGas, maxPriorityFeePerGas, baseFeePerGas };
|
355
|
+
}
|
356
|
+
|
357
|
+
// an alias for calculateFeeData
|
358
|
+
// eslint-disable-next-line
|
359
|
+
public getFeeData = this.calculateFeeData;
|
360
|
+
|
361
|
+
/**
|
362
|
+
* @returns A list of accounts the node controls (addresses are checksummed).
|
363
|
+
*
|
364
|
+
* ```ts
|
365
|
+
* web3.eth.getAccounts().then(console.log);
|
366
|
+
* > ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
|
367
|
+
* ```
|
368
|
+
*/
|
369
|
+
public async getAccounts() {
|
370
|
+
const hexAddresses = (await ethRpcMethods.getAccounts(this.requestManager)) ?? [];
|
371
|
+
return hexAddresses.map(address => toChecksumAddress(address));
|
372
|
+
}
|
373
|
+
|
374
|
+
/**
|
375
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
376
|
+
* @returns The current block number.
|
377
|
+
*
|
378
|
+
* ```ts
|
379
|
+
* web3.eth.getBlockNumber().then(console.log);
|
380
|
+
* > 2744n
|
381
|
+
*
|
382
|
+
* web3.eth.getBlockNumber({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
|
383
|
+
* > "0xab8"
|
384
|
+
* ```
|
385
|
+
*/
|
386
|
+
public async getBlockNumber<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
387
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
388
|
+
) {
|
389
|
+
return rpcMethodsWrappers.getBlockNumber(this, returnFormat);
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Get the balance of an address at a given block.
|
394
|
+
*
|
395
|
+
* @param address The address to get the balance of.
|
396
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the balance query.
|
397
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
398
|
+
* @returns The current balance for the given address in `wei`.
|
399
|
+
*
|
400
|
+
* ```ts
|
401
|
+
* web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
|
402
|
+
* > 1000000000000n
|
403
|
+
*
|
404
|
+
* web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
|
405
|
+
* > "0xe8d4a51000"
|
406
|
+
* ```
|
407
|
+
*/
|
408
|
+
public async getBalance<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
409
|
+
address: Address,
|
410
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
411
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
412
|
+
) {
|
413
|
+
return rpcMethodsWrappers.getBalance(this, address, blockNumber, returnFormat);
|
414
|
+
}
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Get the storage at a specific position of an address.
|
418
|
+
*
|
419
|
+
* @param address The address to get the storage from.
|
420
|
+
* @param storageSlot The index position of the storage.
|
421
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the storage query.
|
422
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
423
|
+
* @returns The value in storage at the given position.
|
424
|
+
*
|
425
|
+
* ```ts
|
426
|
+
* web3.eth.getStorageAt("0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234", 0).then(console.log);
|
427
|
+
* > "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"
|
428
|
+
*
|
429
|
+
* web3.eth.getStorageAt(
|
430
|
+
* "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234",
|
431
|
+
* 0,
|
432
|
+
* undefined,
|
433
|
+
* { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.UINT8ARRAY }
|
434
|
+
* ).then(console.log);
|
435
|
+
* > Uint8Array(31) [
|
436
|
+
* 3, 52, 86, 115, 33, 35, 255, 255,
|
437
|
+
* 35, 66, 52, 45, 209, 35, 66, 67,
|
438
|
+
* 67, 36, 35, 66, 52, 253, 35, 79,
|
439
|
+
* 210, 63, 212, 242, 61, 66, 52
|
440
|
+
* ]
|
441
|
+
* ```
|
442
|
+
*/
|
443
|
+
public async getStorageAt<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
444
|
+
address: Address,
|
445
|
+
storageSlot: Numbers,
|
446
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
447
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
448
|
+
) {
|
449
|
+
return rpcMethodsWrappers.getStorageAt(
|
450
|
+
this,
|
451
|
+
address,
|
452
|
+
storageSlot,
|
453
|
+
blockNumber,
|
454
|
+
returnFormat,
|
455
|
+
);
|
456
|
+
}
|
457
|
+
|
458
|
+
/**
|
459
|
+
* Get the code at a specific address.
|
460
|
+
*
|
461
|
+
* @param address The address to get the code from.
|
462
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the code query.
|
463
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
464
|
+
* @returns The [data](https://ethereum.org/en/developers/docs/transactions/#the-data-field) at the provided `address`.
|
465
|
+
*
|
466
|
+
* ```ts
|
467
|
+
* web3.eth.getCode("0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234").then(console.log);
|
468
|
+
* > "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
|
469
|
+
*
|
470
|
+
* web3.eth.getCode(
|
471
|
+
* "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
472
|
+
* undefined,
|
473
|
+
* { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.UINT8ARRAY }
|
474
|
+
* ).then(console.log);
|
475
|
+
* > Uint8Array(50) [
|
476
|
+
* 96, 1, 96, 0, 128, 53, 129, 26, 129, 129, 129,
|
477
|
+
* 20, 96, 18, 87, 131, 1, 0, 91, 96, 27, 96,
|
478
|
+
* 1, 53, 96, 37, 86, 91, 128, 96, 0, 82, 96,
|
479
|
+
* 32, 96, 0, 242, 91, 96, 0, 96, 7, 130, 2,
|
480
|
+
* 144, 80, 145, 144, 80, 86
|
481
|
+
* ]
|
482
|
+
* ```
|
483
|
+
*/
|
484
|
+
public async getCode<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
485
|
+
address: Address,
|
486
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
487
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
488
|
+
) {
|
489
|
+
return rpcMethodsWrappers.getCode(this, address, blockNumber, returnFormat);
|
490
|
+
}
|
491
|
+
|
492
|
+
/**
|
493
|
+
* Retrieves a {@link Block} matching the provided block number, block hash or block tag.
|
494
|
+
*
|
495
|
+
* @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block.
|
496
|
+
* @param hydrated If specified `true`, the returned block will contain all transactions as objects. If `false` it will only contain transaction hashes.
|
497
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted (does not format transaction objects or hashes).
|
498
|
+
* @returns A {@link Block} object matching the provided block number or block hash.
|
499
|
+
*
|
500
|
+
* ```ts
|
501
|
+
* web3.eth.getBlock(0).then(console.log);
|
502
|
+
* > {
|
503
|
+
* hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
|
504
|
+
* parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
505
|
+
* sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
506
|
+
* miner: '0x0000000000000000000000000000000000000000',
|
507
|
+
* stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
|
508
|
+
* transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
509
|
+
* receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
510
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
511
|
+
* difficulty: 1n,
|
512
|
+
* number: 0n,
|
513
|
+
* gasLimit: 30000000n,
|
514
|
+
* gasUsed: 0n,
|
515
|
+
* timestamp: 1658281638n,
|
516
|
+
* extraData: '0x',
|
517
|
+
* mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
518
|
+
* nonce: 0n,
|
519
|
+
* totalDifficulty: 1n,
|
520
|
+
* baseFeePerGas: 1000000000n,
|
521
|
+
* size: 514n,
|
522
|
+
* transactions: [],
|
523
|
+
* uncles: []
|
524
|
+
* }
|
525
|
+
*
|
526
|
+
* web3.eth.getBlock(
|
527
|
+
* "0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d",
|
528
|
+
* false,
|
529
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
530
|
+
* ).then(console.log);
|
531
|
+
* > {
|
532
|
+
* hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
|
533
|
+
* parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
534
|
+
* sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
535
|
+
* miner: '0x0000000000000000000000000000000000000000',
|
536
|
+
* stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
|
537
|
+
* transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
538
|
+
* receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
539
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
540
|
+
* difficulty: 1,
|
541
|
+
* number: 0,
|
542
|
+
* gasLimit: 30000000,
|
543
|
+
* gasUsed: 0,
|
544
|
+
* timestamp: 1658281638,
|
545
|
+
* extraData: '0x',
|
546
|
+
* mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
547
|
+
* nonce: 0,
|
548
|
+
* totalDifficulty: 1,
|
549
|
+
* baseFeePerGas: 1000000000,
|
550
|
+
* size: 514,
|
551
|
+
* transactions: [],
|
552
|
+
* uncles: []
|
553
|
+
* }
|
554
|
+
* ```
|
555
|
+
*/
|
556
|
+
public async getBlock<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
557
|
+
block: HexString32Bytes | BlockNumberOrTag = this.defaultBlock,
|
558
|
+
hydrated = false,
|
559
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
560
|
+
) {
|
561
|
+
return rpcMethodsWrappers.getBlock(this, block, hydrated, returnFormat);
|
562
|
+
}
|
563
|
+
|
564
|
+
/**
|
565
|
+
* @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block.
|
566
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
567
|
+
* @returns The number of transactions in the provided block.
|
568
|
+
*
|
569
|
+
* ```ts
|
570
|
+
* web3.eth.getBlockTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
|
571
|
+
* > 1n
|
572
|
+
*
|
573
|
+
* web3.eth.getBlockTransactionCount(
|
574
|
+
* "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
575
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
576
|
+
* ).then(console.log);
|
577
|
+
* > 1
|
578
|
+
* ```
|
579
|
+
*/
|
580
|
+
public async getBlockTransactionCount<
|
581
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
582
|
+
>(
|
583
|
+
block: HexString32Bytes | BlockNumberOrTag = this.defaultBlock,
|
584
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
585
|
+
) {
|
586
|
+
return rpcMethodsWrappers.getBlockTransactionCount(this, block, returnFormat);
|
587
|
+
}
|
588
|
+
|
589
|
+
/**
|
590
|
+
* @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block.
|
591
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
592
|
+
* @returns The number of [uncles](https://ethereum.org/en/glossary/#ommer) in the provided block.
|
593
|
+
*
|
594
|
+
* ```ts
|
595
|
+
* web3.eth.getBlockUncleCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
|
596
|
+
* > 1n
|
597
|
+
*
|
598
|
+
* web3.eth.getBlockUncleCount(
|
599
|
+
* "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
600
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
601
|
+
* ).then(console.log);
|
602
|
+
* > 1
|
603
|
+
* ```
|
604
|
+
*/
|
605
|
+
public async getBlockUncleCount<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
606
|
+
block: HexString32Bytes | BlockNumberOrTag = this.defaultBlock,
|
607
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
608
|
+
) {
|
609
|
+
return rpcMethodsWrappers.getBlockUncleCount(this, block, returnFormat);
|
610
|
+
}
|
611
|
+
|
612
|
+
/**
|
613
|
+
*
|
614
|
+
* @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block.
|
615
|
+
* @param uncleIndex The index position of the uncle.
|
616
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
617
|
+
* @returns A blocks [uncle](https://ethereum.org/en/glossary/#ommer) by a given uncle index position.
|
618
|
+
*
|
619
|
+
* ```ts
|
620
|
+
* web3.eth.getUncle(0, 1).then(console.log);
|
621
|
+
* > {
|
622
|
+
* hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
|
623
|
+
* parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
624
|
+
* sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
625
|
+
* miner: '0x0000000000000000000000000000000000000000',
|
626
|
+
* stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
|
627
|
+
* transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
628
|
+
* receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
629
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
630
|
+
* difficulty: 1n,
|
631
|
+
* number: 0n,
|
632
|
+
* gasLimit: 30000000n,
|
633
|
+
* gasUsed: 0n,
|
634
|
+
* timestamp: 1658281638n,
|
635
|
+
* extraData: '0x',
|
636
|
+
* mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
637
|
+
* nonce: 0n,
|
638
|
+
* totalDifficulty: 1n,
|
639
|
+
* baseFeePerGas: 1000000000n,
|
640
|
+
* size: 514n,
|
641
|
+
* transactions: [],
|
642
|
+
* uncles: []
|
643
|
+
* }
|
644
|
+
*
|
645
|
+
* web3.eth.getUncle(
|
646
|
+
* "0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d",
|
647
|
+
* 1,
|
648
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
649
|
+
* ).then(console.log);
|
650
|
+
* > {
|
651
|
+
* hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
|
652
|
+
* parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
653
|
+
* sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
654
|
+
* miner: '0x0000000000000000000000000000000000000000',
|
655
|
+
* stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
|
656
|
+
* transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
657
|
+
* receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
658
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
659
|
+
* difficulty: 1,
|
660
|
+
* number: 0,
|
661
|
+
* gasLimit: 30000000,
|
662
|
+
* gasUsed: 0,
|
663
|
+
* timestamp: 1658281638,
|
664
|
+
* extraData: '0x',
|
665
|
+
* mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
666
|
+
* nonce: 0,
|
667
|
+
* totalDifficulty: 1,
|
668
|
+
* baseFeePerGas: 1000000000,
|
669
|
+
* size: 514,
|
670
|
+
* transactions: [],
|
671
|
+
* uncles: []
|
672
|
+
* }
|
673
|
+
* ```
|
674
|
+
*/
|
675
|
+
public async getUncle<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
676
|
+
block: HexString32Bytes | BlockNumberOrTag = this.defaultBlock,
|
677
|
+
uncleIndex: Numbers,
|
678
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
679
|
+
) {
|
680
|
+
return rpcMethodsWrappers.getUncle(this, block, uncleIndex, returnFormat);
|
681
|
+
}
|
682
|
+
|
683
|
+
/**
|
684
|
+
* @param transactionHash The hash of the desired transaction.
|
685
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
686
|
+
* @returns The desired transaction object.
|
687
|
+
*
|
688
|
+
* ```ts
|
689
|
+
* web3.eth.getTransaction('0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc').then(console.log);
|
690
|
+
* {
|
691
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
692
|
+
* type: 0n,
|
693
|
+
* nonce: 0n,
|
694
|
+
* blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00',
|
695
|
+
* blockNumber: 1n,
|
696
|
+
* transactionIndex: 0n,
|
697
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
698
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
699
|
+
* value: 1n,
|
700
|
+
* gas: 90000n,
|
701
|
+
* gasPrice: 2000000000n,
|
702
|
+
* input: '0x',
|
703
|
+
* v: 2709n,
|
704
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
705
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
706
|
+
* }
|
707
|
+
*
|
708
|
+
* web3.eth.getTransaction(
|
709
|
+
* web3.utils.hexToBytes("0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"),
|
710
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
711
|
+
* ).then(console.log);
|
712
|
+
* {
|
713
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
714
|
+
* type: 0,
|
715
|
+
* nonce: 0,
|
716
|
+
* blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00',
|
717
|
+
* blockNumber: 1,
|
718
|
+
* transactionIndex: 0,
|
719
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
720
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
721
|
+
* value: 1,
|
722
|
+
* gas: 90000,
|
723
|
+
* gasPrice: 2000000000,
|
724
|
+
* input: '0x',
|
725
|
+
* v: 2709,
|
726
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
727
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
728
|
+
* }
|
729
|
+
* ```
|
730
|
+
*/
|
731
|
+
public async getTransaction<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
732
|
+
transactionHash: Bytes,
|
733
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
734
|
+
) {
|
735
|
+
const response = await rpcMethodsWrappers.getTransaction(
|
736
|
+
this,
|
737
|
+
transactionHash,
|
738
|
+
returnFormat,
|
739
|
+
);
|
740
|
+
|
741
|
+
if (!response) throw new TransactionNotFound();
|
742
|
+
|
743
|
+
return response;
|
744
|
+
}
|
745
|
+
|
746
|
+
/**
|
747
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
748
|
+
* @returns A list of pending transactions.
|
749
|
+
*
|
750
|
+
* ```ts
|
751
|
+
* web3.eth.getPendingTransactions().then(console.log);
|
752
|
+
* > [
|
753
|
+
* {
|
754
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
755
|
+
* type: 0n,
|
756
|
+
* nonce: 0n,
|
757
|
+
* blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
758
|
+
* blockNumber: null,
|
759
|
+
* transactionIndex: 0n,
|
760
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
761
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
762
|
+
* value: 1n,
|
763
|
+
* gas: 90000n,
|
764
|
+
* gasPrice: 2000000000n,
|
765
|
+
* input: '0x',
|
766
|
+
* v: 2709n,
|
767
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
768
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
769
|
+
* },
|
770
|
+
* {
|
771
|
+
* hash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
|
772
|
+
* type: 0n,
|
773
|
+
* nonce: 1n,
|
774
|
+
* blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
775
|
+
* blockNumber: null,
|
776
|
+
* transactionIndex: 0n,
|
777
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
778
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
779
|
+
* value: 1n,
|
780
|
+
* gas: 90000n,
|
781
|
+
* gasPrice: 2000000000n,
|
782
|
+
* input: '0x',
|
783
|
+
* v: 2710n,
|
784
|
+
* r: '0x55ac19fade21db035a1b7ea0a8d49e265e05dbb926e75f273f836ad67ce5c96a',
|
785
|
+
* s: '0x6550036a7c3fd426d5c3d35d96a7075cd673957620b7889846a980d2d017ec08'
|
786
|
+
* }
|
787
|
+
* ]
|
788
|
+
*
|
789
|
+
* * web3.eth.getPendingTransactions({ number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
|
790
|
+
* > [
|
791
|
+
* {
|
792
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
793
|
+
* type: 0,
|
794
|
+
* nonce: 0,
|
795
|
+
* blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
796
|
+
* blockNumber: null,
|
797
|
+
* transactionIndex: 0,
|
798
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
799
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
800
|
+
* value: 1,
|
801
|
+
* gas: 90000,
|
802
|
+
* gasPrice: 2000000000,
|
803
|
+
* input: '0x',
|
804
|
+
* v: 2709,
|
805
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
806
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
807
|
+
* },
|
808
|
+
* {
|
809
|
+
* hash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
|
810
|
+
* type: 0,
|
811
|
+
* nonce: 1,
|
812
|
+
* blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
813
|
+
* blockNumber: null,
|
814
|
+
* transactionIndex: 0,
|
815
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
816
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
817
|
+
* value: 1,
|
818
|
+
* gas: 90000,
|
819
|
+
* gasPrice: 2000000000,
|
820
|
+
* input: '0x',
|
821
|
+
* v: 2710,
|
822
|
+
* r: '0x55ac19fade21db035a1b7ea0a8d49e265e05dbb926e75f273f836ad67ce5c96a',
|
823
|
+
* s: '0x6550036a7c3fd426d5c3d35d96a7075cd673957620b7889846a980d2d017ec08'
|
824
|
+
* }
|
825
|
+
* ]
|
826
|
+
* ```
|
827
|
+
*/
|
828
|
+
public async getPendingTransactions<
|
829
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
830
|
+
>(returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat) {
|
831
|
+
return rpcMethodsWrappers.getPendingTransactions(this, returnFormat);
|
832
|
+
}
|
833
|
+
|
834
|
+
/**
|
835
|
+
* @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block.
|
836
|
+
* @param transactionIndex The index position of the transaction.
|
837
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
838
|
+
* @returns The desired transaction object.
|
839
|
+
*
|
840
|
+
* ```ts
|
841
|
+
* web3.eth.getTransactionFromBlock('0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', 0).then(console.log);
|
842
|
+
* {
|
843
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
844
|
+
* type: 0n,
|
845
|
+
* nonce: 0n,
|
846
|
+
* blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00',
|
847
|
+
* blockNumber: 1n,
|
848
|
+
* transactionIndex: 0n,
|
849
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
850
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
851
|
+
* value: 1n,
|
852
|
+
* gas: 90000n,
|
853
|
+
* gasPrice: 2000000000n,
|
854
|
+
* input: '0x',
|
855
|
+
* v: 2709n,
|
856
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
857
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
858
|
+
* }
|
859
|
+
*
|
860
|
+
* web3.eth.getTransactionFromBlock(
|
861
|
+
* hexToBytes("0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"),
|
862
|
+
* 0,
|
863
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
864
|
+
* ).then(console.log);
|
865
|
+
* {
|
866
|
+
* hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc',
|
867
|
+
* type: 0,
|
868
|
+
* nonce: 0,
|
869
|
+
* blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00',
|
870
|
+
* blockNumber: 1,
|
871
|
+
* transactionIndex: 0,
|
872
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
873
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
874
|
+
* value: 1,
|
875
|
+
* gas: 90000,
|
876
|
+
* gasPrice: 2000000000,
|
877
|
+
* input: '0x',
|
878
|
+
* v: 2709,
|
879
|
+
* r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c',
|
880
|
+
* s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d'
|
881
|
+
* }
|
882
|
+
* ```
|
883
|
+
*/
|
884
|
+
public async getTransactionFromBlock<
|
885
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
886
|
+
>(
|
887
|
+
block: HexString32Bytes | BlockNumberOrTag = this.defaultBlock,
|
888
|
+
transactionIndex: Numbers,
|
889
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
890
|
+
) {
|
891
|
+
return rpcMethodsWrappers.getTransactionFromBlock(
|
892
|
+
this,
|
893
|
+
block,
|
894
|
+
transactionIndex,
|
895
|
+
returnFormat,
|
896
|
+
);
|
897
|
+
}
|
898
|
+
|
899
|
+
/**
|
900
|
+
* @param transactionHash Hash of the transaction to retrieve the receipt for.
|
901
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
902
|
+
* @returns The desired {@link TransactionReceipt} object.
|
903
|
+
*
|
904
|
+
* ```ts
|
905
|
+
* web3.eth.getTransactionReceipt("0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f").then(console.log);
|
906
|
+
* > {
|
907
|
+
* transactionHash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
|
908
|
+
* transactionIndex: 0n,
|
909
|
+
* blockNumber: 2n,
|
910
|
+
* blockHash: '0xeb1565a08b23429552dafa92e32409f42eb43944f7611963c63ce40e7243941a',
|
911
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
912
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
913
|
+
* cumulativeGasUsed: 21000n,
|
914
|
+
* gasUsed: 21000n,
|
915
|
+
* logs: [],
|
916
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
917
|
+
* status: 1n,
|
918
|
+
* effectiveGasPrice: 2000000000n,
|
919
|
+
* type: 0n
|
920
|
+
* }
|
921
|
+
*
|
922
|
+
* web3.eth.getTransactionReceipt(
|
923
|
+
* "0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f",
|
924
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
925
|
+
* ).then(console.log);
|
926
|
+
* > {
|
927
|
+
* transactionHash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
|
928
|
+
* transactionIndex: 0,
|
929
|
+
* blockNumber: 2,
|
930
|
+
* blockHash: '0xeb1565a08b23429552dafa92e32409f42eb43944f7611963c63ce40e7243941a',
|
931
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
932
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
933
|
+
* cumulativeGasUsed: 21000,
|
934
|
+
* gasUsed: 21000,
|
935
|
+
* logs: [],
|
936
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
937
|
+
* status: 1,
|
938
|
+
* effectiveGasPrice: 2000000000,
|
939
|
+
* type: 0n
|
940
|
+
* }
|
941
|
+
* ```
|
942
|
+
*/
|
943
|
+
public async getTransactionReceipt<
|
944
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
945
|
+
>(
|
946
|
+
transactionHash: Bytes,
|
947
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
948
|
+
) {
|
949
|
+
const response = await rpcMethodsWrappers.getTransactionReceipt(
|
950
|
+
this,
|
951
|
+
transactionHash,
|
952
|
+
returnFormat,
|
953
|
+
);
|
954
|
+
|
955
|
+
if (!response) throw new TransactionNotFound();
|
956
|
+
|
957
|
+
return response;
|
958
|
+
}
|
959
|
+
|
960
|
+
/**
|
961
|
+
* @param address The address to get the number of transactions for.
|
962
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the query.
|
963
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
964
|
+
* @returns The number of transactions sent from the provided address.
|
965
|
+
*
|
966
|
+
* ```ts
|
967
|
+
* web3.eth.getTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
|
968
|
+
* > 1n
|
969
|
+
*
|
970
|
+
* web3.eth.getTransactionCount(
|
971
|
+
* "0x407d73d8a49eeb85d32cf465507dd71d507100c1",
|
972
|
+
* undefined,
|
973
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
974
|
+
* ).then(console.log);
|
975
|
+
* > 1
|
976
|
+
* ```
|
977
|
+
*/
|
978
|
+
public async getTransactionCount<
|
979
|
+
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
|
980
|
+
>(
|
981
|
+
address: Address,
|
982
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
983
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
984
|
+
) {
|
985
|
+
return rpcMethodsWrappers.getTransactionCount(this, address, blockNumber, returnFormat);
|
986
|
+
}
|
987
|
+
|
988
|
+
/**
|
989
|
+
* @param transaction The {@link Transaction}, {@link TransactionWithFromLocalWalletIndex}, {@link TransactionWithToLocalWalletIndex} or {@link TransactionWithFromAndToLocalWalletIndex} to send. __Note:__ In the `to` and `from` fields when hex strings are used, it is assumed they are addresses, for any other form (number, string number, etc.) it is assumed they are wallet indexes.
|
990
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
991
|
+
* @param options A configuration object used to change the behavior of the `sendTransaction` method.
|
992
|
+
* @returns If `await`ed or `.then`d (i.e. the promise resolves), the transaction hash is returned.
|
993
|
+
* ```ts
|
994
|
+
* const transaction = {
|
995
|
+
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
|
996
|
+
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
|
997
|
+
* value: '0x1'
|
998
|
+
* }
|
999
|
+
*
|
1000
|
+
* const transactionHash = await web3.eth.sendTransaction(transaction);
|
1001
|
+
* console.log(transactionHash);
|
1002
|
+
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
|
1003
|
+
*
|
1004
|
+
* web3.eth.sendTransaction(transaction).then(console.log);
|
1005
|
+
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
|
1006
|
+
*
|
1007
|
+
* web3.eth.sendTransaction(transaction).catch(console.log);
|
1008
|
+
* > <Some TransactionError>
|
1009
|
+
*
|
1010
|
+
* // Example using options.ignoreGasPricing = true
|
1011
|
+
* web3.eth.sendTransaction(transaction, undefined, { ignoreGasPricing: true }).then(console.log);
|
1012
|
+
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
|
1013
|
+
* ```
|
1014
|
+
*
|
1015
|
+
*
|
1016
|
+
* Otherwise, a {@link Web3PromiEvent} is returned which has several events than can be listened to using the `.on` syntax, such as:
|
1017
|
+
* - `sending`
|
1018
|
+
* ```ts
|
1019
|
+
* web3.eth.sendTransaction(transaction).on('sending', transactionToBeSent => console.log(transactionToBeSent));
|
1020
|
+
* > {
|
1021
|
+
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
|
1022
|
+
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
|
1023
|
+
* value: '0x1',
|
1024
|
+
* gasPrice: '0x77359400',
|
1025
|
+
* maxPriorityFeePerGas: undefined,
|
1026
|
+
* maxFeePerGas: undefined
|
1027
|
+
* }
|
1028
|
+
* ```
|
1029
|
+
* - `sent`
|
1030
|
+
* ```ts
|
1031
|
+
* web3.eth.sendTransaction(transaction).on('sent', sentTransaction => console.log(sentTransaction));
|
1032
|
+
* > {
|
1033
|
+
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
|
1034
|
+
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
|
1035
|
+
* value: '0x1',
|
1036
|
+
* gasPrice: '0x77359400',
|
1037
|
+
* maxPriorityFeePerGas: undefined,
|
1038
|
+
* maxFeePerGas: undefined
|
1039
|
+
* }
|
1040
|
+
* ```
|
1041
|
+
* - `transactionHash`
|
1042
|
+
* ```ts
|
1043
|
+
* web3.eth.sendTransaction(transaction).on('transactionHash', transactionHash => console.log(transactionHash));
|
1044
|
+
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
|
1045
|
+
* ```
|
1046
|
+
* - `receipt`
|
1047
|
+
* ```ts
|
1048
|
+
* web3.eth.sendTransaction(transaction).on('receipt', receipt => console.log(receipt));
|
1049
|
+
* > {
|
1050
|
+
* transactionHash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
|
1051
|
+
* transactionIndex: 0n,
|
1052
|
+
* blockNumber: 2n,
|
1053
|
+
* blockHash: '0xeb1565a08b23429552dafa92e32409f42eb43944f7611963c63ce40e7243941a',
|
1054
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
1055
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
1056
|
+
* cumulativeGasUsed: 21000n,
|
1057
|
+
* gasUsed: 21000n,
|
1058
|
+
* logs: [],
|
1059
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
1060
|
+
* status: 1n,
|
1061
|
+
* effectiveGasPrice: 2000000000n,
|
1062
|
+
* type: 0n
|
1063
|
+
* }
|
1064
|
+
* ```
|
1065
|
+
* - `confirmation`
|
1066
|
+
* ```ts
|
1067
|
+
* web3.eth.sendTransaction(transaction).on('confirmation', confirmation => console.log(confirmation));
|
1068
|
+
* > {
|
1069
|
+
* confirmations: 1n,
|
1070
|
+
* receipt: {
|
1071
|
+
* transactionHash: '0xb4a3a35ae0f3e77ef0ff7be42010d948d011b21a4e341072ee18717b67e99ab8',
|
1072
|
+
* transactionIndex: 0n,
|
1073
|
+
* blockNumber: 5n,
|
1074
|
+
* blockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548',
|
1075
|
+
* from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
|
1076
|
+
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
|
1077
|
+
* cumulativeGasUsed: 21000n,
|
1078
|
+
* gasUsed: 21000n,
|
1079
|
+
* logs: [],
|
1080
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
1081
|
+
* status: 1n,
|
1082
|
+
* effectiveGasPrice: 2000000000n,
|
1083
|
+
* type: 0n
|
1084
|
+
* },
|
1085
|
+
* latestBlockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548'
|
1086
|
+
* }
|
1087
|
+
* ```
|
1088
|
+
* - `error`
|
1089
|
+
* ```ts
|
1090
|
+
* web3.eth.sendTransaction(transaction).on('error', error => console.log);
|
1091
|
+
* > <Some TransactionError>
|
1092
|
+
* ```
|
1093
|
+
*/
|
1094
|
+
public sendTransaction<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1095
|
+
transaction:
|
1096
|
+
| Transaction
|
1097
|
+
| TransactionWithFromLocalWalletIndex
|
1098
|
+
| TransactionWithToLocalWalletIndex
|
1099
|
+
| TransactionWithFromAndToLocalWalletIndex,
|
1100
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1101
|
+
options?: SendTransactionOptions,
|
1102
|
+
) {
|
1103
|
+
return rpcMethodsWrappers.sendTransaction(
|
1104
|
+
this,
|
1105
|
+
transaction,
|
1106
|
+
returnFormat,
|
1107
|
+
options,
|
1108
|
+
this.transactionMiddleware,
|
1109
|
+
);
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
/**
|
1113
|
+
* @param transaction Signed transaction in one of the valid {@link Bytes} format.
|
1114
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
1115
|
+
* @param options A configuration object used to change the behavior of the method
|
1116
|
+
* @returns If `await`ed or `.then`d (i.e. the promise resolves), the transaction hash is returned.
|
1117
|
+
* ```ts
|
1118
|
+
* const signedTransaction = "0xf86580843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a95a03a42d53ca5b71f845e1cd4c65359b05446a85d16881372d3bfaab8980935cb04a0711497bc8dd3b541152e2fed14fe650a647f1f0edab0d386ad9506f0e642410f"
|
1119
|
+
*
|
1120
|
+
* const transactionHash = await web3.eth.sendSignedTransaction(signedTransaction);
|
1121
|
+
* console.log(transactionHash);
|
1122
|
+
* > 0xed8c241ea44d57f4605dc22c63500de46254d6c7844fd65fa438b128c80cf700
|
1123
|
+
*
|
1124
|
+
* web3.eth.sendSignedTransaction(signedTransaction).then(console.log);
|
1125
|
+
* > 0xed8c241ea44d57f4605dc22c63500de46254d6c7844fd65fa438b128c80cf700
|
1126
|
+
*
|
1127
|
+
* web3.eth.sendSignedTransaction(signedTransaction).catch(console.log);
|
1128
|
+
* > <Some TransactionError>
|
1129
|
+
* ```
|
1130
|
+
*
|
1131
|
+
*
|
1132
|
+
* Otherwise, a {@link Web3PromiEvent} is returned which has several events than can be listened to using the `.on` syntax, such as:
|
1133
|
+
* - `sending`
|
1134
|
+
* ```ts
|
1135
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('sending', transactionToBeSent => console.log(transactionToBeSent));
|
1136
|
+
* > "0xf86580843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a95a03a42d53ca5b71f845e1cd4c65359b05446a85d16881372d3bfaab8980935cb04a0711497bc8dd3b541152e2fed14fe650a647f1f0edab0d386ad9506f0e642410f"
|
1137
|
+
* ```
|
1138
|
+
* - `sent`
|
1139
|
+
* ```ts
|
1140
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('sent', sentTransaction => console.log(sentTransaction));
|
1141
|
+
* > "0xf86580843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a95a03a42d53ca5b71f845e1cd4c65359b05446a85d16881372d3bfaab8980935cb04a0711497bc8dd3b541152e2fed14fe650a647f1f0edab0d386ad9506f0e642410f"
|
1142
|
+
* ```
|
1143
|
+
* - `transactionHash`
|
1144
|
+
* ```ts
|
1145
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('transactionHash', transactionHash => console.log(transactionHash));
|
1146
|
+
* > 0xed8c241ea44d57f4605dc22c63500de46254d6c7844fd65fa438b128c80cf700
|
1147
|
+
* ```
|
1148
|
+
* - `receipt`
|
1149
|
+
* ```ts
|
1150
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('receipt', receipt => console.log(receipt));
|
1151
|
+
* > {
|
1152
|
+
* blockHash: '0xff2b1687995d81066361bc6affe4455746120a7d4bb75fc938211a2692a50081',
|
1153
|
+
* blockNumber: 1n,
|
1154
|
+
* cumulativeGasUsed: 21000n,
|
1155
|
+
* effectiveGasPrice: 1000000001n,
|
1156
|
+
* from: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1157
|
+
* gasUsed: 21000n,
|
1158
|
+
* logs: [],
|
1159
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
1160
|
+
* status: 1n,
|
1161
|
+
* to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1162
|
+
* transactionHash: '0xed8c241ea44d57f4605dc22c63500de46254d6c7844fd65fa438b128c80cf700',
|
1163
|
+
* transactionIndex: 0n,
|
1164
|
+
* type: 0n
|
1165
|
+
* }
|
1166
|
+
* ```
|
1167
|
+
* - `confirmation`
|
1168
|
+
* ```ts
|
1169
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('confirmation', confirmation => console.log(confirmation));
|
1170
|
+
* > {
|
1171
|
+
* confirmations: 1n,
|
1172
|
+
* receipt: {
|
1173
|
+
* blockHash: '0xff2b1687995d81066361bc6affe4455746120a7d4bb75fc938211a2692a50081',
|
1174
|
+
* blockNumber: 1n,
|
1175
|
+
* cumulativeGasUsed: 21000n,
|
1176
|
+
* effectiveGasPrice: 1000000001n,
|
1177
|
+
* from: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1178
|
+
* gasUsed: 21000n,
|
1179
|
+
* logs: [],
|
1180
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
1181
|
+
* status: 1n,
|
1182
|
+
* to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1183
|
+
* transactionHash: '0xed8c241ea44d57f4605dc22c63500de46254d6c7844fd65fa438b128c80cf700',
|
1184
|
+
* transactionIndex: 0n,
|
1185
|
+
* type: 0n
|
1186
|
+
* },
|
1187
|
+
* latestBlockHash: '0xff2b1687995d81066361bc6affe4455746120a7d4bb75fc938211a2692a50081'
|
1188
|
+
* }
|
1189
|
+
* ```
|
1190
|
+
* - `error`
|
1191
|
+
* ```ts
|
1192
|
+
* web3.eth.sendSignedTransaction(signedTransaction).on('error', error => console.log(error));
|
1193
|
+
* > <Some TransactionError>
|
1194
|
+
* ```
|
1195
|
+
*/
|
1196
|
+
public sendSignedTransaction<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1197
|
+
transaction: Bytes,
|
1198
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1199
|
+
options?: SendTransactionOptions,
|
1200
|
+
) {
|
1201
|
+
return rpcMethodsWrappers.sendSignedTransaction(this, transaction, returnFormat, options);
|
1202
|
+
}
|
1203
|
+
|
1204
|
+
/**
|
1205
|
+
* @param message Data to sign in one of the valid {@link Bytes} format.
|
1206
|
+
* @param address Address to sign data with, can be an address or the index of a local wallet.
|
1207
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
1208
|
+
* @returns The signed `message`.
|
1209
|
+
*
|
1210
|
+
* ```ts
|
1211
|
+
* // Using an unlocked account managed by connected RPC client
|
1212
|
+
* web3.eth.sign("0x48656c6c6f20776f726c64", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe").then(console.log);
|
1213
|
+
* > "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"
|
1214
|
+
*
|
1215
|
+
* // Using an unlocked account managed by connected RPC client
|
1216
|
+
* web3.eth.sign("0x48656c6c6f20776f726c64", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.UINT8ARRAY }).then(console.log);
|
1217
|
+
* > Uint8Array(65) [
|
1218
|
+
* 48, 117, 94, 214, 83, 150, 250, 207, 134, 197, 62,
|
1219
|
+
* 98, 23, 197, 43, 77, 174, 190, 114, 170, 73, 65,
|
1220
|
+
* 216, 150, 53, 64, 157, 228, 201, 199, 249, 70, 109,
|
1221
|
+
* 78, 154, 174, 199, 151, 127, 5, 233, 35, 136, 155,
|
1222
|
+
* 51, 192, 208, 221, 39, 215, 34, 107, 110, 111, 86,
|
1223
|
+
* 206, 115, 116, 101, 197, 207, 208, 75, 228, 0
|
1224
|
+
* ]
|
1225
|
+
* ```
|
1226
|
+
*
|
1227
|
+
* // Using an indexed account managed by local Web3 wallet
|
1228
|
+
* web3.eth.sign("0x48656c6c6f20776f726c64", 0).then(console.log);
|
1229
|
+
* > "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"
|
1230
|
+
*/
|
1231
|
+
public async sign<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1232
|
+
message: Bytes,
|
1233
|
+
addressOrIndex: Address | number,
|
1234
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1235
|
+
) {
|
1236
|
+
return rpcMethodsWrappers.sign(this, message, addressOrIndex, returnFormat);
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
/**
|
1240
|
+
* @param transaction The transaction object to sign.
|
1241
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted.
|
1242
|
+
* @returns {@link SignedTransactionInfoAPI}, an object containing the [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/#top) encoded signed transaction (accessed via the `raw` property) and the signed transaction object (accessed via the `tx` property).
|
1243
|
+
*
|
1244
|
+
* ```ts
|
1245
|
+
* const transaction = {
|
1246
|
+
* from: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
|
1247
|
+
* to: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
|
1248
|
+
* value: '0x1',
|
1249
|
+
* gas: '21000',
|
1250
|
+
* gasPrice: await web3Eth.getGasPrice(),
|
1251
|
+
* nonce: '0x1',
|
1252
|
+
* type: '0x0'
|
1253
|
+
* }
|
1254
|
+
*
|
1255
|
+
* web3.eth.signTransaction(transaction).then(console.log);
|
1256
|
+
* > {
|
1257
|
+
* raw: '0xf86501843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a96a0adb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679a027d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
|
1258
|
+
* tx: {
|
1259
|
+
* type: 0n,
|
1260
|
+
* nonce: 1n,
|
1261
|
+
* gasPrice: 1000000001n,
|
1262
|
+
* gas: 21000n,
|
1263
|
+
* value: 1n,
|
1264
|
+
* v: 2710n,
|
1265
|
+
* r: '0xadb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679',
|
1266
|
+
* s: '0x27d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
|
1267
|
+
* to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1268
|
+
* data: '0x'
|
1269
|
+
* }
|
1270
|
+
* }
|
1271
|
+
*
|
1272
|
+
* web3.eth.signTransaction(transaction, { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
|
1273
|
+
* > {
|
1274
|
+
* raw: '0xf86501843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a96a0adb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679a027d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
|
1275
|
+
* tx: {
|
1276
|
+
* type: 0,
|
1277
|
+
* nonce: 1,
|
1278
|
+
* gasPrice: 1000000001,
|
1279
|
+
* gas: 21000,
|
1280
|
+
* value: 1,
|
1281
|
+
* v: 2710,
|
1282
|
+
* r: '0xadb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679',
|
1283
|
+
* s: '0x27d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
|
1284
|
+
* to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
|
1285
|
+
* data: '0x'
|
1286
|
+
* }
|
1287
|
+
* }
|
1288
|
+
* ```
|
1289
|
+
*/
|
1290
|
+
public async signTransaction<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1291
|
+
transaction: Transaction,
|
1292
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1293
|
+
) {
|
1294
|
+
return rpcMethodsWrappers.signTransaction(this, transaction, returnFormat);
|
1295
|
+
}
|
1296
|
+
|
1297
|
+
// TODO Decide what to do with transaction.to
|
1298
|
+
// https://github.com/ChainSafe/web3.js/pull/4525#issuecomment-982330076
|
1299
|
+
/**
|
1300
|
+
* Executes a message call within the EVM without creating a transaction.
|
1301
|
+
* It does not publish anything to the blockchain and does not consume any gas.
|
1302
|
+
*
|
1303
|
+
* @param transaction - A transaction object where all properties are optional except `to`, however it's recommended to include the `from` property or it may default to `0x0000000000000000000000000000000000000000` depending on your node or provider.
|
1304
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) - Specifies what block to use as the current state of the blockchain while processing the transaction.
|
1305
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1306
|
+
* @returns The returned data of the call, e.g. a smart contract function's return value.
|
1307
|
+
*/
|
1308
|
+
public async call<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1309
|
+
transaction: TransactionCall,
|
1310
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
1311
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1312
|
+
) {
|
1313
|
+
return rpcMethodsWrappers.call(this, transaction, blockNumber, returnFormat);
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
/**
|
1317
|
+
* Simulates the transaction within the EVM to estimate the amount of gas to be used by the transaction.
|
1318
|
+
* The transaction will not be added to the blockchain, and actual gas usage can vary when interacting
|
1319
|
+
* with a contract as a result of updating the contract's state.
|
1320
|
+
*
|
1321
|
+
* @param transaction The {@link Transaction} object to estimate the gas for.
|
1322
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) - Specifies what block to use as the current state of the blockchain while processing the gas estimation.
|
1323
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1324
|
+
* @returns The used gas for the simulated transaction execution.
|
1325
|
+
*
|
1326
|
+
* ```ts
|
1327
|
+
* const transaction = {
|
1328
|
+
* from: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
|
1329
|
+
* to: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
|
1330
|
+
* value: '0x1',
|
1331
|
+
* nonce: '0x1',
|
1332
|
+
* type: '0x0'
|
1333
|
+
* }
|
1334
|
+
*
|
1335
|
+
* web3.eth.estimateGas(transaction).then(console.log);
|
1336
|
+
* > 21000n
|
1337
|
+
*
|
1338
|
+
* web3.eth.estimateGas(transaction, { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
|
1339
|
+
* > 21000
|
1340
|
+
* ```
|
1341
|
+
*/
|
1342
|
+
public async estimateGas<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1343
|
+
transaction: Transaction,
|
1344
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
1345
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1346
|
+
) {
|
1347
|
+
return rpcMethodsWrappers.estimateGas(this, transaction, blockNumber, returnFormat);
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
/**
|
1351
|
+
* Gets past logs, matching the provided `filter`.
|
1352
|
+
*
|
1353
|
+
* @param filter A {@link Filter} object containing the properties for the desired logs.
|
1354
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1355
|
+
* @returns {@link FilterResultsAPI}, an array of {@link Log} objects.
|
1356
|
+
*
|
1357
|
+
* ```ts
|
1358
|
+
* web3.eth.getPastLogs({
|
1359
|
+
* address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
|
1360
|
+
* topics: ["0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"]
|
1361
|
+
* }).then(console.log);
|
1362
|
+
* > [{
|
1363
|
+
* data: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
|
1364
|
+
* topics: ['0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385']
|
1365
|
+
* logIndex: 0n,
|
1366
|
+
* transactionIndex: 0n,
|
1367
|
+
* transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
|
1368
|
+
* blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7',
|
1369
|
+
* blockNumber: 1234n,
|
1370
|
+
* address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'
|
1371
|
+
* },
|
1372
|
+
* {...}]
|
1373
|
+
*
|
1374
|
+
* web3.eth.getPastLogs(
|
1375
|
+
* {
|
1376
|
+
* address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
|
1377
|
+
* topics: ["0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"]
|
1378
|
+
* },
|
1379
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
1380
|
+
* ).then(console.log);
|
1381
|
+
* > [{
|
1382
|
+
* data: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
|
1383
|
+
* topics: ['0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385']
|
1384
|
+
* logIndex: 0,
|
1385
|
+
* transactionIndex: 0,
|
1386
|
+
* transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
|
1387
|
+
* blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7',
|
1388
|
+
* blockNumber: 1234,
|
1389
|
+
* address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'
|
1390
|
+
* },
|
1391
|
+
* {...}]
|
1392
|
+
* ```
|
1393
|
+
*/
|
1394
|
+
public async getPastLogs<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1395
|
+
filter: Filter,
|
1396
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1397
|
+
) {
|
1398
|
+
return rpcMethodsWrappers.getLogs(this, filter, returnFormat);
|
1399
|
+
}
|
1400
|
+
|
1401
|
+
/**
|
1402
|
+
* Gets work for miners to mine on. Returns the hash of the current block, the seedHash, and the boundary condition to be met ('target').
|
1403
|
+
*
|
1404
|
+
* @returns The mining work as an array of strings with the following structure:
|
1405
|
+
*
|
1406
|
+
* String 32 Bytes - at index 0: current block header pow-hash
|
1407
|
+
* String 32 Bytes - at index 1: the seed hash used for the DAG.
|
1408
|
+
* String 32 Bytes - at index 2: the boundary condition ('target'), 2^256 / difficulty.
|
1409
|
+
*
|
1410
|
+
* ```ts
|
1411
|
+
* web3.eth.getWork().then(console.log);
|
1412
|
+
* > [
|
1413
|
+
* "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
1414
|
+
* "0x5EED00000000000000000000000000005EED0000000000000000000000000000",
|
1415
|
+
* "0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000"
|
1416
|
+
* ]
|
1417
|
+
* ```
|
1418
|
+
*/
|
1419
|
+
public async getWork() {
|
1420
|
+
return ethRpcMethods.getWork(this.requestManager);
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
/**
|
1424
|
+
* Used for submitting a proof-of-work solution.
|
1425
|
+
*
|
1426
|
+
* @param nonce The nonce found (8 bytes).
|
1427
|
+
* @param hash The header’s pow-hash (32 bytes).
|
1428
|
+
* @param digest The mix digest (32 bytes).
|
1429
|
+
* @returns Returns `true` if the provided solution is valid, otherwise `false`.
|
1430
|
+
*
|
1431
|
+
* ```ts
|
1432
|
+
* web3.eth.submitWork([
|
1433
|
+
* "0x0000000000000001",
|
1434
|
+
* "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
1435
|
+
* "0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000"
|
1436
|
+
* ]).then(console.log);
|
1437
|
+
* > true
|
1438
|
+
* ```
|
1439
|
+
*/
|
1440
|
+
public async submitWork(
|
1441
|
+
nonce: HexString8Bytes,
|
1442
|
+
hash: HexString32Bytes,
|
1443
|
+
digest: HexString32Bytes,
|
1444
|
+
) {
|
1445
|
+
return ethRpcMethods.submitWork(this.requestManager, nonce, hash, digest);
|
1446
|
+
}
|
1447
|
+
|
1448
|
+
// TODO - Format addresses
|
1449
|
+
/**
|
1450
|
+
* This method will request/enable the accounts from the current environment and for supporting [EIP 1102](https://eips.ethereum.org/EIPS/eip-1102)
|
1451
|
+
* This method will only work if you’re using the injected provider from a application like Metamask, Status or TrustWallet.
|
1452
|
+
* It doesn’t work if you’re connected to a node with a default Web3.js provider (WebsocketProvider, HttpProvider and IpcProvider).
|
1453
|
+
* For more information about the behavior of this method please read [EIP-1102](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1102.md): Opt-in account exposure.
|
1454
|
+
*
|
1455
|
+
* @returns An array of enabled accounts.
|
1456
|
+
*
|
1457
|
+
* ```ts
|
1458
|
+
* web3.eth.requestAccounts().then(console.log);
|
1459
|
+
* > ['0aae0B295369a9FD31d5F28D9Ec85E40f4cb692BAf', '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe']
|
1460
|
+
* ```
|
1461
|
+
*/
|
1462
|
+
public async requestAccounts() {
|
1463
|
+
return ethRpcMethods.requestAccounts(this.requestManager);
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
/**
|
1467
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1468
|
+
* @returns The chain ID of the current connected node as described in the [EIP-695](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-695.md).
|
1469
|
+
*
|
1470
|
+
* ```ts
|
1471
|
+
* web3.eth.getChainId().then(console.log);
|
1472
|
+
* > 61n
|
1473
|
+
*
|
1474
|
+
* web3.eth.getChainId({ number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
|
1475
|
+
* > 61
|
1476
|
+
* ```
|
1477
|
+
*/
|
1478
|
+
public async getChainId<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1479
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1480
|
+
) {
|
1481
|
+
return rpcMethodsWrappers.getChainId(this, returnFormat);
|
1482
|
+
}
|
1483
|
+
|
1484
|
+
/**
|
1485
|
+
* @returns The current client version.
|
1486
|
+
*
|
1487
|
+
* ```ts
|
1488
|
+
* web3.eth.getNodeInfo().then(console.log);
|
1489
|
+
* > "Mist/v0.9.3/darwin/go1.4.1"
|
1490
|
+
* ```
|
1491
|
+
*/
|
1492
|
+
public async getNodeInfo() {
|
1493
|
+
return ethRpcMethods.getNodeInfo(this.requestManager);
|
1494
|
+
}
|
1495
|
+
|
1496
|
+
/**
|
1497
|
+
* @param address The Address of the account or contract.
|
1498
|
+
* @param storageKeys Array of storage-keys which should be proofed and included. See {@link web3.getStorageAt}.
|
1499
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) - Specifies what block to use as the current state of the blockchain while processing the gas estimation.
|
1500
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1501
|
+
* @returns The account and storage-values of the specified account including the Merkle-proof as described in [EIP-1186](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1186.md).
|
1502
|
+
*
|
1503
|
+
* ```ts
|
1504
|
+
* web3.eth.getProof(
|
1505
|
+
* "0x1234567890123456789012345678901234567890",
|
1506
|
+
* ["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001"],
|
1507
|
+
* "latest"
|
1508
|
+
* ).then(console.log);
|
1509
|
+
* > {
|
1510
|
+
* "address": "0x1234567890123456789012345678901234567890",
|
1511
|
+
* "accountProof": [
|
1512
|
+
* "0xf90211a090dcaf88c40c7bbc95a912cbdde67c175767b31173df9ee4b0d733bfdd511c43a0babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bda0473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021a0bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0a04e44caecff45c9891f74f6a2156735886eedf6f1a733628ebc802ec79d844648a0a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7a0e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92da0f7a00cbe7d4b30b11faea3ae61b7f1f2b315b61d9f6bd68bfe587ad0eeceb721a07117ef9fc932f1a88e908eaead8565c19b5645dc9e5b1b6e841c5edbdfd71681a069eb2de283f32c11f859d7bcf93da23990d3e662935ed4d6b39ce3673ec84472a0203d26456312bbc4da5cd293b75b840fc5045e493d6f904d180823ec22bfed8ea09287b5c21f2254af4e64fca76acc5cd87399c7f1ede818db4326c98ce2dc2208a06fc2d754e304c48ce6a517753c62b1a9c1d5925b89707486d7fc08919e0a94eca07b1c54f15e299bd58bdfef9741538c7828b5d7d11a489f9c20d052b3471df475a051f9dd3739a927c89e357580a4c97b40234aa01ed3d5e0390dc982a7975880a0a089d613f26159af43616fd9455bb461f4869bfede26f2130835ed067a8b967bfb80",
|
1513
|
+
* "0xf90211a0395d87a95873cd98c21cf1df9421af03f7247880a2554e20738eec2c7507a494a0bcf6546339a1e7e14eb8fb572a968d217d2a0d1f3bc4257b22ef5333e9e4433ca012ae12498af8b2752c99efce07f3feef8ec910493be749acd63822c3558e6671a0dbf51303afdc36fc0c2d68a9bb05dab4f4917e7531e4a37ab0a153472d1b86e2a0ae90b50f067d9a2244e3d975233c0a0558c39ee152969f6678790abf773a9621a01d65cd682cc1be7c5e38d8da5c942e0a73eeaef10f387340a40a106699d494c3a06163b53d956c55544390c13634ea9aa75309f4fd866f312586942daf0f60fb37a058a52c1e858b1382a8893eb9c1f111f266eb9e21e6137aff0dddea243a567000a037b4b100761e02de63ea5f1fcfcf43e81a372dafb4419d126342136d329b7a7ba032472415864b08f808ba4374092003c8d7c40a9f7f9fe9cc8291f62538e1cc14a074e238ff5ec96b810364515551344100138916594d6af966170ff326a092fab0a0d31ac4eef14a79845200a496662e92186ca8b55e29ed0f9f59dbc6b521b116fea090607784fe738458b63c1942bba7c0321ae77e18df4961b2bc66727ea996464ea078f757653c1b63f72aff3dcc3f2a2e4c8cb4a9d36d1117c742833c84e20de994a0f78407de07f4b4cb4f899dfb95eedeb4049aeb5fc1635d65cf2f2f4dfd25d1d7a0862037513ba9d45354dd3e36264aceb2b862ac79d2050f14c95657e43a51b85c80",
|
1514
|
+
* "0xf90171a04ad705ea7bf04339fa36b124fa221379bd5a38ffe9a6112cb2d94be3a437b879a08e45b5f72e8149c01efcb71429841d6a8879d4bbe27335604a5bff8dfdf85dcea00313d9b2f7c03733d6549ea3b810e5262ed844ea12f70993d87d3e0f04e3979ea0b59e3cdd6750fa8b15164612a5cb6567cdfb386d4e0137fccee5f35ab55d0efda0fe6db56e42f2057a071c980a778d9a0b61038f269dd74a0e90155b3f40f14364a08538587f2378a0849f9608942cf481da4120c360f8391bbcc225d811823c6432a026eac94e755534e16f9552e73025d6d9c30d1d7682a4cb5bd7741ddabfd48c50a041557da9a74ca68da793e743e81e2029b2835e1cc16e9e25bd0c1e89d4ccad6980a041dda0a40a21ade3a20fcd1a4abb2a42b74e9a32b02424ff8db4ea708a5e0fb9a09aaf8326a51f613607a8685f57458329b41e938bb761131a5747e066b81a0a16808080a022e6cef138e16d2272ef58434ddf49260dc1de1f8ad6dfca3da5d2a92aaaadc58080",
|
1515
|
+
* "0xf851808080a009833150c367df138f1538689984b8a84fc55692d3d41fe4d1e5720ff5483a6980808080808080808080a0a319c1c415b271afc0adcb664e67738d103ac168e0bc0b7bd2da7966165cb9518080"
|
1516
|
+
* ],
|
1517
|
+
* "balance": 0n,
|
1518
|
+
* "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
|
1519
|
+
* "nonce": 0n,
|
1520
|
+
* "storageHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
1521
|
+
* "storageProof": [
|
1522
|
+
* {
|
1523
|
+
* "key": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
1524
|
+
* "value": 0n,
|
1525
|
+
* "proof": []
|
1526
|
+
* },
|
1527
|
+
* {
|
1528
|
+
* "key": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
1529
|
+
* "value": 0n,
|
1530
|
+
* "proof": []
|
1531
|
+
* }
|
1532
|
+
* ]
|
1533
|
+
* }
|
1534
|
+
*
|
1535
|
+
* web3.eth.getProof(
|
1536
|
+
* "0x1234567890123456789012345678901234567890",
|
1537
|
+
* ["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000001"],
|
1538
|
+
* undefined,
|
1539
|
+
* { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
|
1540
|
+
* ).then(console.log);
|
1541
|
+
* > {
|
1542
|
+
* "address": "0x1234567890123456789012345678901234567890",
|
1543
|
+
* "accountProof": [
|
1544
|
+
* "0xf90211a090dcaf88c40c7bbc95a912cbdde67c175767b31173df9ee4b0d733bfdd511c43a0babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bda0473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021a0bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0a04e44caecff45c9891f74f6a2156735886eedf6f1a733628ebc802ec79d844648a0a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7a0e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92da0f7a00cbe7d4b30b11faea3ae61b7f1f2b315b61d9f6bd68bfe587ad0eeceb721a07117ef9fc932f1a88e908eaead8565c19b5645dc9e5b1b6e841c5edbdfd71681a069eb2de283f32c11f859d7bcf93da23990d3e662935ed4d6b39ce3673ec84472a0203d26456312bbc4da5cd293b75b840fc5045e493d6f904d180823ec22bfed8ea09287b5c21f2254af4e64fca76acc5cd87399c7f1ede818db4326c98ce2dc2208a06fc2d754e304c48ce6a517753c62b1a9c1d5925b89707486d7fc08919e0a94eca07b1c54f15e299bd58bdfef9741538c7828b5d7d11a489f9c20d052b3471df475a051f9dd3739a927c89e357580a4c97b40234aa01ed3d5e0390dc982a7975880a0a089d613f26159af43616fd9455bb461f4869bfede26f2130835ed067a8b967bfb80",
|
1545
|
+
* "0xf90211a0395d87a95873cd98c21cf1df9421af03f7247880a2554e20738eec2c7507a494a0bcf6546339a1e7e14eb8fb572a968d217d2a0d1f3bc4257b22ef5333e9e4433ca012ae12498af8b2752c99efce07f3feef8ec910493be749acd63822c3558e6671a0dbf51303afdc36fc0c2d68a9bb05dab4f4917e7531e4a37ab0a153472d1b86e2a0ae90b50f067d9a2244e3d975233c0a0558c39ee152969f6678790abf773a9621a01d65cd682cc1be7c5e38d8da5c942e0a73eeaef10f387340a40a106699d494c3a06163b53d956c55544390c13634ea9aa75309f4fd866f312586942daf0f60fb37a058a52c1e858b1382a8893eb9c1f111f266eb9e21e6137aff0dddea243a567000a037b4b100761e02de63ea5f1fcfcf43e81a372dafb4419d126342136d329b7a7ba032472415864b08f808ba4374092003c8d7c40a9f7f9fe9cc8291f62538e1cc14a074e238ff5ec96b810364515551344100138916594d6af966170ff326a092fab0a0d31ac4eef14a79845200a496662e92186ca8b55e29ed0f9f59dbc6b521b116fea090607784fe738458b63c1942bba7c0321ae77e18df4961b2bc66727ea996464ea078f757653c1b63f72aff3dcc3f2a2e4c8cb4a9d36d1117c742833c84e20de994a0f78407de07f4b4cb4f899dfb95eedeb4049aeb5fc1635d65cf2f2f4dfd25d1d7a0862037513ba9d45354dd3e36264aceb2b862ac79d2050f14c95657e43a51b85c80",
|
1546
|
+
* "0xf90171a04ad705ea7bf04339fa36b124fa221379bd5a38ffe9a6112cb2d94be3a437b879a08e45b5f72e8149c01efcb71429841d6a8879d4bbe27335604a5bff8dfdf85dcea00313d9b2f7c03733d6549ea3b810e5262ed844ea12f70993d87d3e0f04e3979ea0b59e3cdd6750fa8b15164612a5cb6567cdfb386d4e0137fccee5f35ab55d0efda0fe6db56e42f2057a071c980a778d9a0b61038f269dd74a0e90155b3f40f14364a08538587f2378a0849f9608942cf481da4120c360f8391bbcc225d811823c6432a026eac94e755534e16f9552e73025d6d9c30d1d7682a4cb5bd7741ddabfd48c50a041557da9a74ca68da793e743e81e2029b2835e1cc16e9e25bd0c1e89d4ccad6980a041dda0a40a21ade3a20fcd1a4abb2a42b74e9a32b02424ff8db4ea708a5e0fb9a09aaf8326a51f613607a8685f57458329b41e938bb761131a5747e066b81a0a16808080a022e6cef138e16d2272ef58434ddf49260dc1de1f8ad6dfca3da5d2a92aaaadc58080",
|
1547
|
+
* "0xf851808080a009833150c367df138f1538689984b8a84fc55692d3d41fe4d1e5720ff5483a6980808080808080808080a0a319c1c415b271afc0adcb664e67738d103ac168e0bc0b7bd2da7966165cb9518080"
|
1548
|
+
* ],
|
1549
|
+
* "balance": 0,
|
1550
|
+
* "codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
|
1551
|
+
* "nonce": 0,
|
1552
|
+
* "storageHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
1553
|
+
* "storageProof": [
|
1554
|
+
* {
|
1555
|
+
* "key": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
1556
|
+
* "value": 0,
|
1557
|
+
* "proof": []
|
1558
|
+
* },
|
1559
|
+
* {
|
1560
|
+
* "key": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
1561
|
+
* "value": 0,
|
1562
|
+
* "proof": []
|
1563
|
+
* }
|
1564
|
+
* ]
|
1565
|
+
* }
|
1566
|
+
* ```
|
1567
|
+
*/
|
1568
|
+
public async getProof<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1569
|
+
address: Address,
|
1570
|
+
storageKeys: Bytes[],
|
1571
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
1572
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1573
|
+
) {
|
1574
|
+
return rpcMethodsWrappers.getProof(this, address, storageKeys, blockNumber, returnFormat);
|
1575
|
+
}
|
1576
|
+
|
1577
|
+
// TODO Throwing an error with Geth, but not Infura
|
1578
|
+
// TODO gasUsedRatio and reward not formatting
|
1579
|
+
/**
|
1580
|
+
* @param blockCount Number of blocks in the requested range. Between `1` and `1024` blocks can be requested in a single query. Less than requested may be returned if not all blocks are available.
|
1581
|
+
* @param newestBlock Highest number block of the requested range.
|
1582
|
+
* @param rewardPercentiles A monotonically increasing list of percentile values to sample from each block’s effective priority fees per gas in ascending order, weighted by gas used. Example: `['0', '25', '50', '75', '100']` or `['0', '0.5', '1', '1.5', '3', '80']`
|
1583
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the call should be formatted.
|
1584
|
+
* @returns `baseFeePerGas` and transaction effective `priorityFeePerGas` history for the requested block range if available.
|
1585
|
+
* The range between `headBlock - 4` and `headBlock` is guaranteed to be available while retrieving data from the `pending` block and older history are optional to support.
|
1586
|
+
* For pre-EIP-1559 blocks the `gasPrice`s are returned as `rewards` and zeroes are returned for the `baseFeePerGas`.
|
1587
|
+
*
|
1588
|
+
* ```ts
|
1589
|
+
* web3.eth.getFeeHistory(4, 'pending', [0, 25, 75, 100]).then(console.log);
|
1590
|
+
* > {
|
1591
|
+
* baseFeePerGas: [
|
1592
|
+
* 22983878621n,
|
1593
|
+
* 21417903463n,
|
1594
|
+
* 19989260230n,
|
1595
|
+
* 17770954829n,
|
1596
|
+
* 18850641304n
|
1597
|
+
* ],
|
1598
|
+
* gasUsedRatio: [
|
1599
|
+
* 0.22746546666666667,
|
1600
|
+
* 0.2331871,
|
1601
|
+
* 0.05610054885262125,
|
1602
|
+
* 0.7430227268212117
|
1603
|
+
* ],
|
1604
|
+
* oldestBlock: 15216343n,
|
1605
|
+
* reward: [
|
1606
|
+
* [ '0x3b9aca00', '0x53724e00', '0x77359400', '0x1d92c03423' ],
|
1607
|
+
* [ '0x3b9aca00', '0x3b9aca00', '0x3b9aca00', '0xee6b2800' ],
|
1608
|
+
* [ '0x3b9aca00', '0x4f86a721', '0x77d9743a', '0x9502f900' ],
|
1609
|
+
* [ '0xcc8ff9e', '0x53724e00', '0x77359400', '0x1ec9771bb3' ]
|
1610
|
+
* ]
|
1611
|
+
* }
|
1612
|
+
*
|
1613
|
+
* web3.eth.getFeeHistory(4, BlockTags.LATEST, [0, 25, 75, 100], { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
|
1614
|
+
* > {
|
1615
|
+
* baseFeePerGas: [
|
1616
|
+
* 22983878621,
|
1617
|
+
* 21417903463,
|
1618
|
+
* 19989260230,
|
1619
|
+
* 17770954829,
|
1620
|
+
* 18850641304
|
1621
|
+
* ],
|
1622
|
+
* gasUsedRatio: [
|
1623
|
+
* 0.22746546666666667,
|
1624
|
+
* 0.2331871,
|
1625
|
+
* 0.05610054885262125,
|
1626
|
+
* 0.7430227268212117
|
1627
|
+
* ],
|
1628
|
+
* oldestBlock: 15216343,
|
1629
|
+
* reward: [
|
1630
|
+
* [ '0x3b9aca00', '0x53724e00', '0x77359400', '0x1d92c03423' ],
|
1631
|
+
* [ '0x3b9aca00', '0x3b9aca00', '0x3b9aca00', '0xee6b2800' ],
|
1632
|
+
* [ '0x3b9aca00', '0x4f86a721', '0x77d9743a', '0x9502f900' ],
|
1633
|
+
* [ '0xcc8ff9e', '0x53724e00', '0x77359400', '0x1ec9771bb3' ]
|
1634
|
+
* ]
|
1635
|
+
* }
|
1636
|
+
* ```
|
1637
|
+
*/
|
1638
|
+
public async getFeeHistory<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1639
|
+
blockCount: Numbers,
|
1640
|
+
newestBlock: BlockNumberOrTag = this.defaultBlock,
|
1641
|
+
rewardPercentiles: Numbers[],
|
1642
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1643
|
+
) {
|
1644
|
+
return rpcMethodsWrappers.getFeeHistory(
|
1645
|
+
this,
|
1646
|
+
blockCount,
|
1647
|
+
newestBlock,
|
1648
|
+
rewardPercentiles,
|
1649
|
+
returnFormat,
|
1650
|
+
);
|
1651
|
+
}
|
1652
|
+
|
1653
|
+
/**
|
1654
|
+
* This method generates an access list for a transaction.
|
1655
|
+
*
|
1656
|
+
* @param transaction - A transaction object where all properties are optional except `from`, however it's recommended to include the `to` property.
|
1657
|
+
* @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) - Specifies what block to use as the current state of the blockchain while processing the transaction.
|
1658
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the return data from the createAccessList should be formatted.
|
1659
|
+
* @returns The returned data of the createAccessList, e.g. The generated access list for transaction.
|
1660
|
+
* @example
|
1661
|
+
* ```ts
|
1662
|
+
* web3.eth.createAccessList({
|
1663
|
+
* from: '0xDe95305a63302C3aa4d3A9B42654659AeA72b694',
|
1664
|
+
* data: '0x9a67c8b100000000000000000000000000000000000000000000000000000000000004d0',
|
1665
|
+
* gasPrice: '0x3b9aca00',
|
1666
|
+
* gas: '0x3d0900',
|
1667
|
+
* to: '0x940b25304947ae863568B3804434EC77E2160b87'
|
1668
|
+
* })
|
1669
|
+
* .then(console.log);
|
1670
|
+
*
|
1671
|
+
* > {
|
1672
|
+
* "accessList": [
|
1673
|
+
* {
|
1674
|
+
* "address": "0x15859bdf5aff2080a9968f6a410361e9598df62f",
|
1675
|
+
* "storageKeys": [
|
1676
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000000"
|
1677
|
+
* ]
|
1678
|
+
* }
|
1679
|
+
* ],
|
1680
|
+
* "gasUsed": "0x7671"
|
1681
|
+
* }
|
1682
|
+
* ```
|
1683
|
+
*/
|
1684
|
+
public async createAccessList<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1685
|
+
transaction: TransactionForAccessList,
|
1686
|
+
blockNumber: BlockNumberOrTag = this.defaultBlock,
|
1687
|
+
returnFormat: ReturnFormat = this.defaultReturnFormat as ReturnFormat,
|
1688
|
+
) {
|
1689
|
+
return rpcMethodsWrappers.createAccessList(this, transaction, blockNumber, returnFormat);
|
1690
|
+
}
|
1691
|
+
|
1692
|
+
/**
|
1693
|
+
* This method sends EIP-712 typed data to the RPC provider to be signed.
|
1694
|
+
*
|
1695
|
+
* @param address The address that corresponds with the private key used to sign the typed data.
|
1696
|
+
* @param typedData The EIP-712 typed data object.
|
1697
|
+
* @param useLegacy A boolean flag determining whether the RPC call uses the legacy method `eth_signTypedData` or the newer method `eth_signTypedData_v4`
|
1698
|
+
* @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) - Specifies how the signed typed data should be formatted.
|
1699
|
+
* @returns The signed typed data.
|
1700
|
+
*/
|
1701
|
+
public async signTypedData<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
|
1702
|
+
address: Address,
|
1703
|
+
typedData: Eip712TypedData,
|
1704
|
+
useLegacy = false,
|
1705
|
+
returnFormat: ReturnFormat = (this.defaultReturnFormat ??
|
1706
|
+
DEFAULT_RETURN_FORMAT) as ReturnFormat,
|
1707
|
+
) {
|
1708
|
+
return rpcMethodsWrappers.signTypedData(this, address, typedData, useLegacy, returnFormat);
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
/**
|
1712
|
+
* Lets you subscribe to specific events in the blockchain.
|
1713
|
+
*
|
1714
|
+
* @param name - The subscription you want to subscribe to.
|
1715
|
+
* @param args - Optional additional parameters, depending on the subscription type.
|
1716
|
+
* @returns A subscription object of type {@link RegisteredSubscription}. The object contains:
|
1717
|
+
* - subscription.id: The subscription id, used to identify and unsubscribing the subscription.
|
1718
|
+
* - subscription.subscribe(): Can be used to re-subscribe with the same parameters.
|
1719
|
+
* - subscription.unsubscribe(): Unsubscribes the subscription and returns TRUE in the callback if successful.
|
1720
|
+
* - subscription.args: The subscription arguments, used when re-subscribing.
|
1721
|
+
*
|
1722
|
+
*
|
1723
|
+
* You can use the subscription object to listen on:
|
1724
|
+
*
|
1725
|
+
* - on("data") - Fires on each incoming log with the log object as argument.
|
1726
|
+
* - on("changed") - Fires on each log which was removed from the blockchain. The log will have the additional property "removed: true".
|
1727
|
+
* - on("error") - Fires when an error in the subscription occurs.
|
1728
|
+
* - on("connected") - Fires once after the subscription successfully connected. Returns the subscription id.
|
1729
|
+
*
|
1730
|
+
* @example **Subscribe to Smart Contract events**
|
1731
|
+
* ```ts
|
1732
|
+
* // Subscribe to `logs`
|
1733
|
+
* const logSubscription = web3.eth.subscribe('logs', {
|
1734
|
+
* address: '0x1234567890123456789012345678901234567890',
|
1735
|
+
* topics: ['0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234']
|
1736
|
+
* });
|
1737
|
+
* logSubscription.on('data', (data: any) => console.log(data));
|
1738
|
+
* logSubscription.on('error', (error: any) => console.log(error));
|
1739
|
+
*
|
1740
|
+
* ```
|
1741
|
+
*
|
1742
|
+
* @example **Subscribe to new block headers**
|
1743
|
+
* ```ts
|
1744
|
+
* // Subscribe to `newBlockHeaders`
|
1745
|
+
* const newBlocksSubscription = await web3.eth.subscribe('newBlockHeaders');
|
1746
|
+
*
|
1747
|
+
* newBlocksSubscription.on('data', async blockhead => {
|
1748
|
+
* console.log('New block header: ', blockhead);
|
1749
|
+
*
|
1750
|
+
* // You do not need the next line, if you like to keep notified for every new block
|
1751
|
+
* await newBlocksSubscription.unsubscribe();
|
1752
|
+
* console.log('Unsubscribed from new block headers.');
|
1753
|
+
* });
|
1754
|
+
* newBlocksSubscription.on('error', error =>
|
1755
|
+
* console.log('Error when subscribing to New block header: ', error),
|
1756
|
+
* );
|
1757
|
+
* ```
|
1758
|
+
*
|
1759
|
+
* ### subscribe('pendingTransactions')
|
1760
|
+
*
|
1761
|
+
* Subscribes to incoming pending transactions.
|
1762
|
+
* You can subscribe to pending transactions by calling web3.eth.subscribe('pendingTransactions').
|
1763
|
+
*
|
1764
|
+
* ```ts
|
1765
|
+
* (await web3.eth.subscribe('pendingTransactions')).on('data', console.log);
|
1766
|
+
* ```
|
1767
|
+
*
|
1768
|
+
* ### subscribe('newHeads')
|
1769
|
+
* ( same as subscribe('newBlockHeaders'))
|
1770
|
+
* Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain.
|
1771
|
+
*
|
1772
|
+
* The structure of a returned block header is {@link BlockHeaderOutput}:
|
1773
|
+
*
|
1774
|
+
* ```ts
|
1775
|
+
* (await web3.eth.subscribe('newHeads')).on( // 'newBlockHeaders' would work as well
|
1776
|
+
* 'data',
|
1777
|
+
* console.log
|
1778
|
+
* );
|
1779
|
+
* >{
|
1780
|
+
* parentHash: '0x9e746a1d906b299def98c75b06f714d62dacadd567c7515d76eeaa8c8074c738',
|
1781
|
+
* sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
1782
|
+
* miner: '0x0000000000000000000000000000000000000000',
|
1783
|
+
* stateRoot: '0xe0f04b04861ecfa95e82a9310d6a7ef7aef8d7417f5209c182582bfb98a8e307',
|
1784
|
+
* transactionsRoot: '0x31ab4ea571a9e10d3a19aaed07d190595b1dfa34e03960c04293fec565dea536',
|
1785
|
+
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
1786
|
+
* difficulty: 2n,
|
1787
|
+
* number: 21n,
|
1788
|
+
* gasLimit: 11738125n,
|
1789
|
+
* gasUsed: 830006n,
|
1790
|
+
* timestamp: 1678797237n,
|
1791
|
+
* extraData: '0xd883010b02846765746888676f312e32302e31856c696e757800000000000000e0a6e93cf40e2e71a72e493272210c3f43738ccc7e7d7b14ffd51833797d896c09117e8dc4fbcbc969bd21b42e5af3e276a911524038c001b2109b63b8e0352601',
|
1792
|
+
* nonce: 0n
|
1793
|
+
* }
|
1794
|
+
* ```
|
1795
|
+
*
|
1796
|
+
* ### subscribe('syncing')
|
1797
|
+
* Subscribe to syncing events. This will return `true` when the node is syncing and when it’s finished syncing will return `false`, for the `changed` event.
|
1798
|
+
*
|
1799
|
+
* ```ts
|
1800
|
+
* (await web3.eth.subscribe('syncing')).on('changed', console.log);
|
1801
|
+
* > `true` // when syncing
|
1802
|
+
*
|
1803
|
+
* (await web3.eth.subscribe('syncing')).on('data', console.log);
|
1804
|
+
* > {
|
1805
|
+
* startingBlock: 0,
|
1806
|
+
* currentBlock: 0,
|
1807
|
+
* highestBlock: 0,
|
1808
|
+
* pulledStates: 0,
|
1809
|
+
* knownStates: 0
|
1810
|
+
* }
|
1811
|
+
* ```
|
1812
|
+
*
|
1813
|
+
* ### subscribe('logs', options)
|
1814
|
+
* Subscribes to incoming logs, filtered by the given options. If a valid numerical fromBlock options property is set, web3.js will retrieve logs beginning from this point, backfilling the response as necessary.
|
1815
|
+
*
|
1816
|
+
* options: You can subscribe to logs matching a given filter object, which can take the following parameters:
|
1817
|
+
* - `fromBlock`: (optional, default: 'latest') Integer block number, or `'latest'` for the last mined block or `'pending'`, `'earliest'` for not yet mined transactions.
|
1818
|
+
* - `address`: (optional) Contract address or a list of addresses from which logs should originate.
|
1819
|
+
* - `topics`: (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with `or` options.
|
1820
|
+
*
|
1821
|
+
* ```ts
|
1822
|
+
* (await web3.eth.subscribe('logs', {
|
1823
|
+
* address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
1824
|
+
* })).on('data', console.log);
|
1825
|
+
*
|
1826
|
+
* > {
|
1827
|
+
* removed: false,
|
1828
|
+
* logIndex: 119n,
|
1829
|
+
* transactionIndex: 58n,
|
1830
|
+
* transactionHash: '0x61533efa77937360215069d5d6cb0be09a22af9721e6dc3df59d957833ed8870',
|
1831
|
+
* blockHash: '0xe32bb97084479d32247f66f8b46d00af2fbc3c2db2bc6e5843fe2e4d1ca9b099',
|
1832
|
+
* blockNumber: 18771966n,
|
1833
|
+
* address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
1834
|
+
* data: '0x00000000000000000000000000000000000000000000000000000000d88b2e40',
|
1835
|
+
* topics: [
|
1836
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
1837
|
+
* '0x0000000000000000000000002fb2457f6ec1865dc0d4e7300c696b69c2a1b989',
|
1838
|
+
* '0x00000000000000000000000027fd43babfbe83a81d14665b1a6fb8030a60c9b4'
|
1839
|
+
* ]
|
1840
|
+
* }
|
1841
|
+
*```
|
1842
|
+
*/
|
1843
|
+
|
1844
|
+
public async subscribe<
|
1845
|
+
T extends keyof RegisteredSubscription,
|
1846
|
+
ReturnType extends DataFormat = DataFormat,
|
1847
|
+
>(
|
1848
|
+
name: T,
|
1849
|
+
args?: ConstructorParameters<RegisteredSubscription[T]>[0],
|
1850
|
+
returnFormat: ReturnType = (this.defaultReturnFormat ??
|
1851
|
+
DEFAULT_RETURN_FORMAT) as ReturnType,
|
1852
|
+
): Promise<InstanceType<RegisteredSubscription[T]>> {
|
1853
|
+
const subscription = await this.subscriptionManager?.subscribe(name, args, returnFormat);
|
1854
|
+
if (
|
1855
|
+
subscription instanceof LogsSubscription &&
|
1856
|
+
name === 'logs' &&
|
1857
|
+
typeof args === 'object' &&
|
1858
|
+
!isNullish(args.fromBlock) &&
|
1859
|
+
Number.isFinite(Number(args.fromBlock))
|
1860
|
+
) {
|
1861
|
+
setImmediate(() => {
|
1862
|
+
this.getPastLogs(args)
|
1863
|
+
.then(logs => {
|
1864
|
+
for (const log of logs) {
|
1865
|
+
subscription._processSubscriptionResult(log as LogsOutput);
|
1866
|
+
}
|
1867
|
+
})
|
1868
|
+
.catch(e => {
|
1869
|
+
subscription._processSubscriptionError(e as Error);
|
1870
|
+
});
|
1871
|
+
});
|
1872
|
+
}
|
1873
|
+
return subscription;
|
1874
|
+
}
|
1875
|
+
|
1876
|
+
private static shouldClearSubscription({ sub }: { sub: unknown }): boolean {
|
1877
|
+
return !(sub instanceof SyncingSubscription);
|
1878
|
+
}
|
1879
|
+
|
1880
|
+
/**
|
1881
|
+
* Resets subscriptions.
|
1882
|
+
*
|
1883
|
+
* @param notClearSyncing If `true` it keeps the `syncing` subscription.
|
1884
|
+
* @returns A promise to an array of subscription ids that were cleared.
|
1885
|
+
*
|
1886
|
+
* ```ts
|
1887
|
+
* web3.eth.clearSubscriptions().then(console.log);
|
1888
|
+
* > [...] An array of subscription ids that were cleared
|
1889
|
+
* ```
|
1890
|
+
*/
|
1891
|
+
public clearSubscriptions(notClearSyncing = false): Promise<string[]> | undefined {
|
1892
|
+
return this.subscriptionManager?.unsubscribe(
|
1893
|
+
// eslint-disable-next-line
|
1894
|
+
notClearSyncing ? Web3Eth.shouldClearSubscription : undefined,
|
1895
|
+
);
|
1896
|
+
}
|
1897
|
+
}
|