[Ethereum] How to set a gasPrice with ethers deploy script

contract-deploymentethers.jsgas-price

I'd like to set a gasPrice in my deploy script, so I could deploy and let miners pick up my transaction when gas is low. Like deploy my contract over night while I'm sleeping to save money.

How can I specify the gas price in my ethers deploy script?

   const MyContract = await ethers.getContractFactory('MyContract', signer);
   const mycontract = await MyContract.deploy();
   await mycontract.deployed();
   console.log('Deployed to:', mycontract.address);

Best Answer

You can override the options property of a transaction by adding an object as the last parameter:

 const mycontract = await MyContract.deploy({gasPrice: 50000000000}); // 50gwei

You can also specify a global gas price in your hardhat config. Something like this:

mainnet: {
   url: `https://mainnet.infura.io/v3/${InfuraKey}`, 
   gasPrice: 50000000000
}
Related Topic