wighawag / hardhat-deploy-ethers

MIT License
70 stars 25 forks source link

ethers v6.x broke getContractAt() and probably other functions too #35

Closed br0wnD3v closed 1 year ago

br0wnD3v commented 1 year ago

After the recent update to ethers to v6.x some functions like getContractAt() throws an error ->

Error HH604: Error running JSON-RPC server: ERROR processing /deploy/00_deployMock.js:
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

My current code looks like this ->

module.exports = async ({ deployments, getNamedAccounts, ethers }) => {
  const { deploy } = deployments;
  const { deployer } = await getNamedAccounts();

  const Mock = await deploy("MockUSDC", {
    from: deployer,
    log: true,
  });

  const signer = await ethers.getNamedSigner("mul_wallet");
  const mock = await ethers.getContract("MockUSDC", Mock.address, signer);

  console.log(mock.address);
};

module.exports.tags = ["MockUSDC"];

The hardhat.config file is like

require("@nomicfoundation/hardhat-toolbox");
require("@nomiclabs/hardhat-ethers");
require("hardhat-deploy");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.17",
  networks: {
    hardhat: {
      chainId: 31337,
    },
  },
  namedAccounts: {
    deployer: {
      default: 0,
    },
    mul_wallet: {
      default: 1,
    },
  },
};

Now, when I degraded the version back to something like ethers@5.4.7 the above function doesn't generate any error and works as intended.

Might be an ethers issue in the first place. Thank you.

wighawag commented 1 year ago

I made a new release with latest hardhat-ethers support : v0.4.1

it is now an extension to hardhat-ethers

because of lack of support for loading external artfiact in hardhat it remove support for it. You can still load them manually though

Let me know if this does not fix your issue