1

I have a WETH contract that I want to deploy on my hardhat test network. Source of the WETH contract can be found here.

When I run the following hardhat test:

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("testing", function () {
  it("Should work", async function () {
    const Weth = ethers.getContractFactory("WETH")
    const weth = await Weth.deploy()
    await weth.deployed()

    expect(true).to.equal(true);
  });
});

I receive the following error:

  testing
    1) Should work


  0 passing (725ms)
  1 failing

  1) testing
       Should work:
     TypeError: Weth.deploy is not a function
      at Context.<anonymous> (test/test.js:22:29)
      at processImmediate (internal/timers.js:439:21)

Why is it saying I can't deploy the contract? Is the solidity version so old Hardhat can't deploy it?

1 Answer 1

2
  1. You need to await the getContractFactory
  2. .deployed() is, iirc, only in web3js (you can remove it here)
  3. double check you contract name (« WETH », case sensitive) if it’s not solving it
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("testing", function () {
  it("Should work", async function () {
    const Weth = await ethers.getContractFactory("WETH")
    const weth = await Weth.deploy()

    expect(await weth.symbol()).to.equal(“WETH”);
  });
 });
2
  • Wow! Using await worked!! I wonder why we have to use await here. In other contracts I've used await without fail. Is it because await may succeed before the next line of code is read and would cause await to pass?
    – thank_you
    Nov 22, 2021 at 1:58
  • Yes that is true. You could maybe read about async and await in javascript to understand this better. Looks great so far! Jan 12, 2022 at 23:07

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.