Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: custom transaction polling interval #4584

Merged
merged 8 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions docs/web3-eth-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/web3-eth-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1045,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,
Expand Down