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

Incompatible Typescript types between contracts #6419

Open
Amxx opened this issue Feb 26, 2025 · 1 comment
Open

Incompatible Typescript types between contracts #6419

Amxx opened this issue Feb 26, 2025 · 1 comment
Assignees
Labels
hardhat-3-alpha Feedback about the Hardhat 3 Alpha status:triaging

Comments

@Amxx
Copy link
Contributor

Amxx commented Feb 26, 2025

Feedback

Disclaimer: I'm new to viem (comming from ethers.js), and that is my first type working with the viem typescript types.

I am trying to build functions that operate on "contracts object" that implement interfaces. I'm then calling these functions with "contract objects" that are actual implementation of the interfaces.

For example, lets consider the following solidity code

interface MyInterface {
    function executeMessage(string calldata input) external payable returns (bytes4);
}
contract MyContract is MyInterface {
    function executeMessage(string calldata input) external payable returns (bytes4) { return MyInterface.executeMessage.selector; }
}

and the test code

import { network } from "hardhat";
import { it } from "node:test";

import type { ContractReturnType } from "@nomicfoundation/hardhat-viem/types";

async function execute(instance: ContractReturnType<"MyInterface">) {
    console.log(await instance.simulate.executeMessage([ 'hello' ]));
}

it("sandbox", async function () {
    const client = await network.connect();
    const c = await client.viem.deployContract("MyContract", []);
    await execute(c);
});

Everything works fine, except I have a solidity warning Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.

So I decide to update my solidity code to

contract MyContract is MyInterface {
-    function executeMessage(string calldata input) external payable returns (bytes4) { return MyInterface.executeMessage.selector; }
+    function executeMessage(string calldata) external payable returns (bytes4) { return MyInterface.executeMessage.selector; }
}

And that is when things start to break!

All of the sudden, I get a typescript error telling me that the types are incompatible. I guess that is because the ABI is not the same for the executeMessage function. In one case it has a named input, and in the other case it doesn't.

I'm getting errors about "legacy" and "eip7702" types being different. Not sure what tx envelops have to do with this, but it really isn't great.

In practice, compatible ABI are often implemented with minor changes to in args name. That doesn't break compatibility, and it should honestly no affect type resolution here.

@Amxx Amxx added the hardhat-3-alpha Feedback about the Hardhat 3 Alpha label Feb 26, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Feb 26, 2025
@Amxx
Copy link
Contributor Author

Amxx commented Feb 26, 2025

Note: I'm not sure weither that is a Hardhat-viem issue (comming from how the ABI are extracted from artefacts) or a viem issue (comming from how contracts are typed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hardhat-3-alpha Feedback about the Hardhat 3 Alpha status:triaging
Projects
Status: Backlog
Development

No branches or pull requests

2 participants