Loading...
Previously we discussed about different transaction retrieval methods by web3 in this Smartbook. There are other parameters like timeout, block confirmation etc. which can help user interaction better if used in any dapp. We will look at those methods today.
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.
Syntax : web3.eth.transactionBlockTimeout
Returns : [ Number ] The current value of transactionBlockTimeout (default: 50)
Example :
const web3 = require('web3');
// Get timeout
var time = web3.eth.transactionBlockTimeout;
console.log(time);
// Set Timeout
web3.eth.transactionBlockTimeout = 100;
console.log(web3.eth.transactionBlockTimeout)
Output :
> 50 // output 1
> 100 // output 2
This defines the number of blocks it requires until a transaction is considered confirmed.
Syntax : web3.eth.transactionConfirmationBlocks
Returns : [ Number ] The current value of transactionConfirmationBlocks (default: 24)
Example :
// Get timeout
var blocks = web3.eth.transactionConfirmationBlocks;
console.log(blocks);
// Set Timeout
web3.eth.transactionConfirmationBlocks = 50;
console.log(web3.eth.transactionConfirmationBlocks);
Output :
> 24 // output 1
> 50 // output 2
The transactionPollingTimeout is used over HTTP connections and it is quite different from transactionBlockTimeout. It defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. Note that If this method times out, the transaction may still be pending.
Syntax : web3.eth.transactionPollingTimeout
Returns : [ Number ] The current value of transactionPollingTimeout (default: 750)
Example :
// Get timeout
var timeout= web3.eth.transactionPollingTimeout;
console.log(timeout);
// Set Timeout
web3.eth.transactionPollingTimeout = 1000;
console.log(web3.eth.transactionPollingTimeout);
Output :
> 750 // output 1
> 1000 // output 2