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

Viem type inference does not work in ignition modules #771

Open
kotsmile opened this issue May 25, 2024 · 2 comments
Open

Viem type inference does not work in ignition modules #771

kotsmile opened this issue May 25, 2024 · 2 comments
Labels
status:needs-decision We need to make a decision about this

Comments

@kotsmile
Copy link

kotsmile commented May 25, 2024

Version of Hardhat

2.22.4

Docs reference

https://github.com/NomicFoundation/hardhat/blame/dfd91d254362a3f5a0a2c940398e8af7d677f876/docs/src/content/ignition/docs/guides/viem.md#L102

What happened?

Try to setup hardhat project with viem, typescript, ignition. When i compile the smart contract viem helpers work great, type inference for deploy and contract call, but for ignition it does not work. I just can put anything as arguments of deploy, and same with calls. But in document i can see that everything should work

Node: v20.13.1
NPM: v10.5.2

package.json

{
  "name": "hardhat-project",
  "devDependencies": {
    "@nomicfoundation/hardhat-ignition-viem": "^0.15.4",
    "@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
    "hardhat": "^2.22.4"
  }
}

hardhat.config.ts

import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";
import "@nomicfoundation/hardhat-ignition-viem"

const config: HardhatUserConfig = {
  solidity: "0.8.24",
};

export default config;

ignition/module/Lock.ts

import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { parseEther } from "viem";

const JAN_1ST_2030 = 1893456000;
const ONE_GWEI: bigint = parseEther("0.001");

const LockModule = buildModule("LockModule", (m) => {
  const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
  const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);

  const lock = m.contract("anything", [unlockTime], { // no errors and completion
    value: lockedAmount,
  });

  return { lock };
});

export default LockModule;

Minimal reproduction steps

  1. Initialize project with npx hardhat init
  2. Choose: "Create a TypeScript project (with Viem)"
  3. After run npx hardhat compile
  4. Go to ignition/modules/Lock.ts file
  5. No type inference for m.contract()
  6. Try to install @nomicfoundation/hardhat-ignition-viem
  7. Import @nomicfoundation/hardhat-ignition-viem in hardhat.config.ts
  8. Recomile contracts
  9. Go to ignition/modules/Lock.ts file
  10. No type inference for m.contract()

Search terms

viem type inference, ignition type inference

@kanej kanej added status:needs-decision We need to make a decision about this and removed status:triaging labels May 28, 2024
@kanej kanej transferred this issue from NomicFoundation/hardhat May 28, 2024
@kanej kanej moved this to Todo in Hardhat Ignition May 28, 2024
@kanej kanej removed this from Hardhat May 28, 2024
@AzzouQ
Copy link

AzzouQ commented Nov 3, 2024

Any update on this ? I am facing the same issue, having auto completion in Ignition modules would be a huge plus

@kanej
Copy link
Member

kanej commented Nov 14, 2024

This is a great feature suggestion. I think we want to support it but I can't give a timeline.

We are looking at enhancing the our viem type inference in Hardhat 3 generally, that might provide an opportunity to look at adding refined types within an Ignition module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-decision We need to make a decision about this
Projects
Status: Todo
Development

No branches or pull requests

4 participants