Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Ethers.js Contract Factories

I'm trying to make a ContractFactory on ethers.js and deploy the smart contract on Polygon's testnet Mumbai through Alchemy.

I have a problem with the deploy function as in the docs it isn't clear how to format arguments.

As Alchemy docs I have to specify gasLimit and gasPrice, but I also want to specify custom arguments for my contract's constructor.

The errors that I get:

  • if I put in the deploy function just the parameters of the constructor it says that I didn't specified the gasLimit and gasPrice parameters
  • if I put in the deploy function the parameters of the constructor and gasLimit and gasPrice I have a problem with the smart contract's constructor because of the parameter's order.
  • If I put just gasLimit and gasPrice it deploys correctly but I don't have the custom smart contract that I want as there are the constructor's parameters missing;

this is the piece of code that deploys the smart contract:

const price_unit = "gwei";
const contractFile = await fs.readFileSync('artifacts/contracts/Midly.sol/NFTCollectible.json');
const contract = JSON.parse(contractFile.toString());

const provider = new ethers.providers.AlchemyProvider("maticmum", process.env.ALCHEMY_API_KEY);
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);
const price = ethers.utils.formatUnits(await provider.getGasPrice(), price_unit);

const factory = new ethers.ContractFactory(contract.abi, contract.bytecode, wallet);

const deployedContract = await factory.deploy({
  gasLimit: 2,
  gasPrice: ethers.utils.parseUnits(price, price_unit),
}, tokenURI, maxQuantity, cost)
.then(data => console.log(data))
.catch(error => console.log(error));

Thanks for your time :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to pass the constructor arguments first, and the overrides object last.

const deployedContract = await factory.deploy(tokenURI, maxQuantity, cost, {
  gasLimit: 2,
  gasPrice: ethers.utils.parseUnits(price, price_unit),
})

Docs: https://docs.ethers.io/v5/api/contract/contract-factory/#ContractFactory-deploy

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!