Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify the typed interface when deploying a contract with new ContractFactory? #4564

Open
gabrielstoica opened this issue Jan 29, 2024 · 3 comments
Assignees
Labels
documentation Documentation related issue. investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6

Comments

@gabrielstoica
Copy link

gabrielstoica commented Jan 29, 2024

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

@gabrielstoica gabrielstoica added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Jan 29, 2024
@gabrielstoica
Copy link
Author

Up @ricmoo

@ricmoo ricmoo added documentation Documentation related issue. on-deck This Enhancement or Bug is currently being worked on. labels Feb 5, 2024
@ricmoo
Copy link
Member

ricmoo commented Feb 5, 2024

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.

@gabrielstoica
Copy link
Author

Thanks, @ricmoo - looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation related issue. investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants