i have a smartcontract that expects constructor arguments. i would like to deploy the contract with arguments and also pass the options gasPrice and gasLimit.

this is my function for deploying:

const deploy=async() => {
    let tempProvider = new ethers.providers.Web3Provider(window.ethereum);
    let tempSigner = tempProvider.getSigner();
    const price = ethers.utils.formatUnits(await tempProvider.getGasPrice(), 'gwei')
    const options = {gasLimit: 100000, gasPrice: ethers.utils.parseUnits(price, 'gwei')}
    // Deploy the contract
    const factory = new ethers.ContractFactory(abi, bytecode, tempSigner)
    const contract = await factory.deploy(options)
    await contract.deployed()


i can pass the options, but how can i pass my constructor arguments next to it? from ethers docs i have this:

// If your contract constructor requires parameters, the ABI
// must include the constructor
const abi = [
  "constructor(address owner, uint256 initialValue)",
  "function value() view returns (uint)"

// The factory we use for deploying contracts
factory = new ContractFactory(abi, bytecode, signer)

// Deploy an instance of the contract
contract = await factory.deploy("ricmoo.eth", 42);

they just show how you can pass the arguments, but they dont show how to pass the options. I want to pass both, the options and the contructor values.

here is the definition of the ContractFactory

contractFactory.deploy( ...args [ , overrides ] ) ⇒ Promise< Contract >

  • i just removed the options argument and only passed my constructor values like in the docs of ethers and it worked. The options with gasLimit and gasPrice are not necessary anymore for me.. but maybe someone still can answer me how to pass both arguments.
    – Khan
    Jan 4, 2022 at 22:24

1 Answer 1


Ethers is aware how many arguments are expected for the constructor. If more arguments are passed to the deploy functions than expected for the constructor it will take the last parameters as the options.

Ethers code: https://github.com/ethers-io/ethers.js/blob/73a46efea32c3f9a4833ed77896a216e3d3752a0/packages/contracts/src.ts/index.ts#L1216-L1219

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.