Voting interval of the Ethers.js service provider in Hardhat
When you use your ETER.JS supplier with your Hardhat project, it is possible to face problems with high -sided network connections or high voting intervals that can affect the performance and efficiency of Ethereum intelligent contracts. In this article, we will examine how to change the predefined interval of Eters.js in Hardhat.
Why is the voting interval too high?
The predefined questionnaire of the provider Eters.js is generally 4000 ms (4000 ms), which can be fine for most networks. However, if the delay in the network is high or a congested network is used, this time it may not be appropriate.
What happens when we change the voting interval?
When we make changes to the voting interval, we must update the object “eetter.Config ‘to reflect the new value. Here is an example of how the default survey can be changed:
`Javascript
Import {ether} ‘ether’;
Const Hardhat = Requirement (‘Hardhat’);
Async Main () {function
Wait Eters.GetProvider (). Is (‘network’, (info) => {
If (info.name === ‘represent’) {
// Change the default setting on 1000 ms (1 second)
Ethers.config.polling interval = 1000;
}
});
}
Principal ().
`
Editeetters.config
To change the voting interval, it is necessary to update the object Ethere.config
. The configuration file is generally found in the `or
orhardhat.config.js file.
Here is an example of how the default survey can be changed:
Json
// .env (or hardhat.config.js)
Pollinginerval = 1000 // 1 second
`
Alternatively, you can update the hard set with a subscription to the application -in built:
Javascript
Const {Ethterit} = requirement (‘Hardhat’);
Async Main () {function
Const Network = ‘Mainnet’;
Wait Eters.GetProvider (). Is (‘network’, async (info) => {
If (info.name === Network) {
// Update the default demand to 1000 ms (1 second)
Ethers.config.polling interval = 1000;
// Update the EEPTER.JS service provider with the integrated Hardhat application subscription
Wait Eters.GetProvider (). Setconfig ({
Pollinginerval: 1000,
});
}
});
}
Principal ().
`
Test changes
Once you have made changes to the voting tool, you can use the service providerEthers.js’ with your smart contracts and make sure they work correctly.
In this example, we updated the default settings to 1000 ms (1 second). We also include a case of hardhat tests to show how to update the voting interval:
`Javascript
// Main.js
Import {ether} ‘ether’;
Async Main () {function
Wait Eters.GetProvider (). Is (‘network’, async (info) => {
If (info.name === ‘represent’) {
// Update the default demand to 1000 ms (1 second)
Ethers.config.polling interval = 1000;
// Create a new contract at updated survey time interval
Const Contractinnce = Waitthers.GetContratCTFactory (‘Mychat’);
CONSION APENTD = Wait for the contract.deploy ();
// test his functionality contract by expression
}
});
}
Principal ().
``
By following these steps, you can easily change the predefined interval of the ETERS.JS in Hardhat service provider and optimize the performance of the intelligent contract.