From 23d1021611aebe95473a7d70bb891ee846b66774 Mon Sep 17 00:00:00 2001 From: sirpy Date: Mon, 29 Nov 2021 08:41:12 +0200 Subject: [PATCH 1/5] add: custom transaction polling interval allow to set via options the interval which polls for TX status --- packages/web3-core-method/src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index afffc8560a1..e50a286b06e 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -56,6 +56,7 @@ var Method = function Method(options) { this.transactionBlockTimeout = options.transactionBlockTimeout || 50; this.transactionConfirmationBlocks = options.transactionConfirmationBlocks || 24; this.transactionPollingTimeout = options.transactionPollingTimeout || 750; + this.transactionPollingInterval = options.transactionPollingInterval || 1000; this.blockHeaderTimeout = options.blockHeaderTimeout || 10; // 10 seconds this.defaultCommon = options.defaultCommon; this.defaultChain = options.defaultChain; @@ -553,7 +554,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { let blockHeaderArrived = false; const startInterval = () => { - intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000); + intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), method.transactionPollingInterval); }; // If provider do not support event subscription use polling From 39d3520161f9a45b887eb85229516bb8de7fa71f Mon Sep 17 00:00:00 2001 From: sirpy Date: Sun, 12 Dec 2021 11:08:30 +0200 Subject: [PATCH 2/5] add: transactionPollingInterval to contract --- packages/web3-eth-contract/src/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 65c028379e5..82d20adec8b 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -234,6 +234,19 @@ var Contract = function Contract(jsonInterface, address, options) { }, enumerable: true }); + Object.defineProperty(this, 'transactionPollingInterval', { + get: function () { + if (_this.options.transactionPollingInterval === 0) { + return _this.options.transactionPollingInterval; + } + + return _this.options.transactionPollingInterval || this.constructor.transactionPollingInterval; + }, + set: function (val) { + _this.options.transactionPollingInterval = val; + }, + enumerable: true + }); Object.defineProperty(this, 'transactionConfirmationBlocks', { get: function () { if (_this.options.transactionConfirmationBlocks === 0) { From 854bb5ca64f4eabc16b606a06da236ad237a62fa Mon Sep 17 00:00:00 2001 From: sirpy Date: Sun, 12 Dec 2021 11:09:30 +0200 Subject: [PATCH 3/5] add: pass transactionPollingInterval to method --- packages/web3-eth-contract/src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 82d20adec8b..c04758d22ea 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -1058,6 +1058,7 @@ Contract.prototype._executeMethod = function _executeMethod(){ transactionBlockTimeout: _this._parent.transactionBlockTimeout, transactionConfirmationBlocks: _this._parent.transactionConfirmationBlocks, transactionPollingTimeout: _this._parent.transactionPollingTimeout, + transactionPollingInterval: _this._parent.transactionPollingInterval, defaultCommon: _this._parent.defaultCommon, defaultChain: _this._parent.defaultChain, defaultHardfork: _this._parent.defaultHardfork, From b2ca929380b65bf7e32b851459e5719258dd9f28 Mon Sep 17 00:00:00 2001 From: sirpy Date: Sun, 12 Dec 2021 11:30:25 +0200 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c3d4c13f9..1edf690b476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -484,7 +484,8 @@ Released with 1.0.0-beta.37 code base. ### Added - `maxPriorityFeePerGas` and `maxFeePerGas` added to `Transaction` and `TransactionConfig` interfaces (#4232) (#4585) - +- `transactionPollingInterval` added to web3, contract and method constructor options. defaults to 1 second. (#4584) +- ### Fixed - Fix readthedoc's build for web3js documentation (#4425) - Fix response sorting for batch requests (#4250) From e5abe2113b7ca0197ccc54549b1c2a46437ef920 Mon Sep 17 00:00:00 2001 From: sirpy Date: Sun, 12 Dec 2021 11:33:37 +0200 Subject: [PATCH 5/5] add: transactionPollingInterval docs --- docs/web3-eth-contract.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/web3-eth-contract.rst b/docs/web3-eth-contract.rst index 47a4c225f62..bca5991fe14 100644 --- a/docs/web3-eth-contract.rst +++ b/docs/web3-eth-contract.rst @@ -380,6 +380,27 @@ Returns ------------------------------------------------------------------------------ +.. _eth-contract-module-transactionpollinginterval: + +transactionPollingInterval +===================== + +.. code-block:: javascript + + web3.eth.Contract.transactionPollingInterval + contract.transactionPollingInterval // on contract instance + +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. + + +------- +Returns +------- + +``number``: The current value of transactionPollingInterval (default: 1000) + +------------------------------------------------------------------------------ + .. _eth-contract-module-handlerevert: handleRevert