ethers.js
ethers.js copied to clipboard
How to specify the typed interface when deploying a contract with new ContractFactory?
Ethers Version
6.10.0
Search Terms
abi, type
Describe the Problem
Having the following code snippet, when trying to deploy a custom Box contract, I'm getting the following type error: Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties from type 'Box': UPGRADE_INTERFACE_VERSION, foo, initialize, owner, and 5 more.
How should one specify the contract type when deploying using new ContractFactory() so all the Box-specific methods should be included and therefore suggested? (e.g. box.owner(), box.version())
Code Snippet
import { Box, Box__factory } from "typechain-types";
import { upgrades } from "hardhat";
import { expect } from "chai";
describe("Box", function () {
let box: Box;
before(async function () {
const boxFactory = new ContractFactory(Box__factory.abi, Box__factory.bytecode);
box = await upgrades.deployProxy(boxFactory, [], { // error Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties
kind: "uups",
initializer: "initialize",
});
});
it("should set the correct owner", async function () {
expect(await box.owner()).to.eq(signers.deployer.address); // box is casted
});
it("should retrieve the current version", async function () {
expect(await box.version()).to.eq("1.0.0");
});
});
Contract ABI
No response
Errors
Type 'BaseContract & Omit<ContractInterface, keyof BaseContract>' is missing the following properties from type 'Box': UPGRADE_INTERFACE_VERSION, foo, initialize, owner, and 5 more.
Environment
Hardhat
Environment (Other)
No response
Up @ricmoo
I’ll get some docs up soon on typing in Ethers.
I’m also working on a version of Contracts based on AbiType that can automatically generate types from the ABI.
Thanks, @ricmoo - looking forward to it!
Any update on this one, or can you provide an example of how we should address this @ricmoo ? Thanks!
Also looking forward to seeing some examples. Especially since downgrading to 5.7.2 reports using a highly vulnerable version of the ws dependency.