hardhat-ignition icon indicating copy to clipboard operation
hardhat-ignition copied to clipboard

Viem type inference does not work in ignition modules

Open kotsmile opened this issue 8 months ago • 0 comments

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

kotsmile avatar May 25 '24 23:05 kotsmile