Skip to content

Commit

Permalink
make gas and price more predictable
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed Sep 27, 2024
1 parent 9e27ffb commit f4515d2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/utility/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { utils, Wallet, ContractFactory } from "ethers"
import { ethers } from "hardhat"
import { gasLimit, gasPrice } from "./constants"
import { utils, Wallet } from "ethers"

export const deploy = async <T>(contractName: string, ...args: any[]): Promise<T> => {
const Contract = await ethers.getContractFactory(contractName)
const Contract: ContractFactory = await ethers.getContractFactory(contractName)
console.log(`Deploying ${contractName}...`)
const unsignedTx = Contract.getDeployTransaction(...args)
const gasLimit = await ethers.provider.estimateGas(unsignedTx)
console.log(`Gas limit for ${contractName}: ${gasLimit}`)
const gasPrice = await ethers.provider.getGasPrice()
console.log(`Gas price: ${gasPrice.toString()}`)
const contract = await Contract.deploy(...args, { gasLimit, gasPrice })
console.log(`${contractName} deployed at: ${contract.address}`)
return contract.deployed() as Promise<T>
Expand Down

0 comments on commit f4515d2

Please sign in to comment.