Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 6b04afc

Browse files
nikoulaispacesailor24
authored andcommitted
web3-common/core defaults documentation (#5198)
* Init commit with defaultAccount * Add some more properties * Add more properties * Refactor docs * Apply some changes from reviews
1 parent 34db13a commit 6b04afc

File tree

1 file changed

+123
-2
lines changed

1 file changed

+123
-2
lines changed

packages/web3-core/src/web3_config.ts

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,21 @@ export abstract class Web3Config
9494
Object.assign(this._config, options);
9595
}
9696

97+
/**
98+
* The `handleRevert` options property returns the revert reason string if enabled for the following methods:
99+
* - web3.eth.sendTransaction()
100+
* - web3.eth.call()
101+
* - myContract.methods.myMethod().call()
102+
* - myContract.methods.myMethod().send()
103+
* Default is `false`.
104+
*/
97105
public get handleRevert() {
98106
return this._config.handleRevert;
99107
}
100108

109+
/**
110+
* Will set the handleRevert
111+
*/
101112
public set handleRevert(val) {
102113
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
103114
name: 'handleRevert',
@@ -107,10 +118,19 @@ export abstract class Web3Config
107118
this._config.handleRevert = val;
108119
}
109120

121+
/**
122+
* This default address is used as the default `from` property, if no `from` property is specified in for the following methods:
123+
* - web3.eth.sendTransaction()
124+
* - web3.eth.call()
125+
* - myContract.methods.myMethod().call()
126+
* - myContract.methods.myMethod().send()
127+
*/
110128
public get defaultAccount() {
111129
return this._config.defaultAccount;
112130
}
113-
131+
/**
132+
* Will set the default account.
133+
*/
114134
public set defaultAccount(val) {
115135
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
116136
name: 'defaultAccount',
@@ -120,10 +140,30 @@ export abstract class Web3Config
120140
this._config.defaultAccount = val;
121141
}
122142

143+
/**
144+
* The default block is used for certain methods. You can override it by passing in the defaultBlock as last parameter. The default value is `"latest"`.
145+
* - web3.eth.getBalance()
146+
* - web3.eth.getCode()
147+
* - web3.eth.getTransactionCount()
148+
* - web3.eth.getStorageAt()
149+
* - web3.eth.call()
150+
* - myContract.methods.myMethod().call()
151+
*
152+
* @returns {BlockNumberOrTag}
153+
*/
123154
public get defaultBlock() {
124155
return this._config.defaultBlock;
125156
}
126157

158+
/**
159+
* Will set the default block.
160+
*
161+
* @param {BlockNumberOrTag} val
162+
* - A block number
163+
* - `"earliest"` - String: The genesis block
164+
* - `"latest"` - String: The latest block (current head of the blockchain)
165+
* - `"pending"` - String: The currently mined block (including pending transactions)
166+
*/
127167
public set defaultBlock(val) {
128168
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
129169
name: 'defaultBlock',
@@ -133,10 +173,17 @@ export abstract class Web3Config
133173
this._config.defaultBlock = val;
134174
}
135175

176+
/**
177+
* The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the first confirmation happens, otherwise the PromiEvent rejects with a timeout error.
178+
* Default is `50`.
179+
*/
136180
public get transactionBlockTimeout() {
137181
return this._config.transactionBlockTimeout;
138182
}
139183

184+
/**
185+
* Will set the transactionBlockTimeout.
186+
*/
140187
public set transactionBlockTimeout(val) {
141188
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
142189
name: 'transactionBlockTimeout',
@@ -146,10 +193,17 @@ export abstract class Web3Config
146193
this._config.transactionBlockTimeout = val;
147194
}
148195

196+
/**
197+
* This defines the number of blocks it requires until a transaction is considered confirmed.
198+
* Default is `24`.
199+
*/
149200
public get transactionConfirmationBlocks() {
150201
return this._config.transactionConfirmationBlocks;
151202
}
152203

204+
/**
205+
* Will set the transactionConfirmationBlocks.
206+
*/
153207
public set transactionConfirmationBlocks(val) {
154208
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
155209
name: 'transactionConfirmationBlocks',
@@ -160,10 +214,17 @@ export abstract class Web3Config
160214
this._config.transactionConfirmationBlocks = val;
161215
}
162216

217+
/**
218+
* Used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network.
219+
* Default is `1000` ms.
220+
*/
163221
public get transactionPollingInterval() {
164222
return this._config.transactionPollingInterval;
165223
}
166224

225+
/**
226+
* Will set the transactionPollingInterval.
227+
*/
167228
public set transactionPollingInterval(val) {
168229
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
169230
name: 'transactionPollingInterval',
@@ -176,21 +237,34 @@ export abstract class Web3Config
176237
this.transactionReceiptPollingInterval = val;
177238
this.transactionConfirmationPollingInterval = val;
178239
}
179-
240+
/**
241+
* Used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. Note: If this method times out, the transaction may still be pending.
242+
* Default is `750` ms.
243+
*/
180244
public get transactionPollingTimeout() {
181245
return this._config.transactionPollingTimeout;
182246
}
183247

248+
/**
249+
* Will set the transactionPollingTimeout.
250+
*/
184251
public set transactionPollingTimeout(val) {
185252
this._triggerConfigChange('transactionPollingTimeout', val);
186253

187254
this._config.transactionPollingTimeout = val;
188255
}
189256

257+
/**
258+
* The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network.
259+
* Default is `undefined`
260+
*/
190261
public get transactionReceiptPollingInterval() {
191262
return this._config.transactionReceiptPollingInterval;
192263
}
193264

265+
/**
266+
* Will set the transactionReceiptPollingInterval
267+
*/
194268
public set transactionReceiptPollingInterval(val) {
195269
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
196270
name: 'transactionReceiptPollingInterval',
@@ -215,10 +289,17 @@ export abstract class Web3Config
215289
this._config.transactionConfirmationPollingInterval = val;
216290
}
217291

292+
/**
293+
* The blockHeaderTimeout is used over socket-based connections. This option defines the amount seconds it should wait for “newBlockHeaders” event before falling back to polling to fetch transaction receipt.
294+
* Default is `10` seconds.
295+
*/
218296
public get blockHeaderTimeout() {
219297
return this._config.blockHeaderTimeout;
220298
}
221299

300+
/**
301+
* Will set the blockHeaderTimeout
302+
*/
222303
public set blockHeaderTimeout(val) {
223304
this._triggerConfigChange('blockHeaderTimeout', val);
224305

@@ -255,20 +336,60 @@ export abstract class Web3Config
255336
this._config.defaultChain = val;
256337
}
257338

339+
/**
340+
* Will return the default hardfork. Default is `london`
341+
* The default hardfork property can be one of the following:
342+
* - `chainstart`
343+
* - `homestead`
344+
* - `dao`
345+
* - `tangerineWhistle`
346+
* - `spuriousDragon`
347+
* - `byzantium`
348+
* - `constantinople`
349+
* - `petersburg`
350+
* - `istanbul`
351+
* - `berlin`
352+
* - `london`
353+
* - 'arrowGlacier',
354+
* - 'tangerineWhistle',
355+
* - 'muirGlacier'
356+
*
357+
*/
258358
public get defaultHardfork() {
259359
return this._config.defaultHardfork;
260360
}
261361

362+
/**
363+
* Will set the default hardfork.
364+
*
365+
*/
262366
public set defaultHardfork(val) {
263367
this._triggerConfigChange('defaultHardfork', val);
264368

265369
this._config.defaultHardfork = val;
266370
}
267371

372+
/**
373+
*
374+
* Will get the default common property
375+
* The default common property does contain the following Common object:
376+
* - `customChain` - `Object`: The custom chain properties
377+
* - `name` - `string`: (optional) The name of the chain
378+
* - `networkId` - `number`: Network ID of the custom chain
379+
* - `chainId` - `number`: Chain ID of the custom chain
380+
* - `baseChain` - `string`: (optional) mainnet, goerli, kovan, rinkeby, or ropsten
381+
* - `hardfork` - `string`: (optional) chainstart, homestead, dao, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, or london
382+
* Default is `undefined`.
383+
*
384+
*/
268385
public get defaultCommon() {
269386
return this._config.defaultCommon;
270387
}
271388

389+
/**
390+
* Will set the default common property
391+
*
392+
*/
272393
public set defaultCommon(val) {
273394
this._triggerConfigChange('defaultCommon', val);
274395

0 commit comments

Comments
 (0)