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

Commit 61d5070

Browse files
sirpynazarhussain
andauthored
add: custom transaction polling interval (#4584)
* add: custom transaction polling interval allow to set via options the interval which polls for TX status * add: transactionPollingInterval to contract * add: pass transactionPollingInterval to method * Update CHANGELOG.md * add: transactionPollingInterval docs Co-authored-by: Nazar Hussain <[email protected]>
1 parent 8783f4d commit 61d5070

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ Released with 1.0.0-beta.37 code base.
484484

485485
### Added
486486
- `maxPriorityFeePerGas` and `maxFeePerGas` added to `Transaction` and `TransactionConfig` interfaces (#4232) (#4585)
487-
487+
- `transactionPollingInterval` added to web3, contract and method constructor options. defaults to 1 second. (#4584)
488+
-
488489
### Fixed
489490
- Fix readthedoc's build for web3js documentation (#4425)
490491
- Fix response sorting for batch requests (#4250)

docs/web3-eth-contract.rst

+21
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,27 @@ Returns
380380

381381
------------------------------------------------------------------------------
382382

383+
.. _eth-contract-module-transactionpollinginterval:
384+
385+
transactionPollingInterval
386+
=====================
387+
388+
.. code-block:: javascript
389+
390+
web3.eth.Contract.transactionPollingInterval
391+
contract.transactionPollingInterval // on contract instance
392+
393+
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.
394+
395+
396+
-------
397+
Returns
398+
-------
399+
400+
``number``: The current value of transactionPollingInterval (default: 1000)
401+
402+
------------------------------------------------------------------------------
403+
383404
.. _eth-contract-module-handlerevert:
384405

385406
handleRevert

packages/web3-core-method/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var Method = function Method(options) {
5656
this.transactionBlockTimeout = options.transactionBlockTimeout || 50;
5757
this.transactionConfirmationBlocks = options.transactionConfirmationBlocks || 24;
5858
this.transactionPollingTimeout = options.transactionPollingTimeout || 750;
59+
this.transactionPollingInterval = options.transactionPollingInterval || 1000;
5960
this.blockHeaderTimeout = options.blockHeaderTimeout || 10; // 10 seconds
6061
this.defaultCommon = options.defaultCommon;
6162
this.defaultChain = options.defaultChain;
@@ -553,7 +554,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
553554
let blockHeaderArrived = false;
554555

555556
const startInterval = () => {
556-
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
557+
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), method.transactionPollingInterval);
557558
};
558559

559560
// If provider do not support event subscription use polling

packages/web3-eth-contract/src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ var Contract = function Contract(jsonInterface, address, options) {
234234
},
235235
enumerable: true
236236
});
237+
Object.defineProperty(this, 'transactionPollingInterval', {
238+
get: function () {
239+
if (_this.options.transactionPollingInterval === 0) {
240+
return _this.options.transactionPollingInterval;
241+
}
242+
243+
return _this.options.transactionPollingInterval || this.constructor.transactionPollingInterval;
244+
},
245+
set: function (val) {
246+
_this.options.transactionPollingInterval = val;
247+
},
248+
enumerable: true
249+
});
237250
Object.defineProperty(this, 'transactionConfirmationBlocks', {
238251
get: function () {
239252
if (_this.options.transactionConfirmationBlocks === 0) {
@@ -1045,6 +1058,7 @@ Contract.prototype._executeMethod = function _executeMethod(){
10451058
transactionBlockTimeout: _this._parent.transactionBlockTimeout,
10461059
transactionConfirmationBlocks: _this._parent.transactionConfirmationBlocks,
10471060
transactionPollingTimeout: _this._parent.transactionPollingTimeout,
1061+
transactionPollingInterval: _this._parent.transactionPollingInterval,
10481062
defaultCommon: _this._parent.defaultCommon,
10491063
defaultChain: _this._parent.defaultChain,
10501064
defaultHardfork: _this._parent.defaultHardfork,

0 commit comments

Comments
 (0)