Deploy WETH Contract – How to Deploy WETH Contract in Hardhat Test

contract-deploymenthardhathardhat-deploysolidity

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?

Best Answer

  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”);
  });
 });
Related Topic