Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/viem-resolution-mode-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/hardhat-viem": patch
---

Added a `resolution-mode` import attribute to `viem`'s type-only imports, fixing a build failure against newer `viem` releases.
2 changes: 1 addition & 1 deletion packages/hardhat-viem/src/internal/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EthereumProvider } from "hardhat/types";
import type { Address } from "viem";
import type { Address } from "viem" with { "resolution-mode": "import" };

import memoize from "lodash.memoize";

Expand Down
6 changes: 4 additions & 2 deletions packages/hardhat-viem/src/internal/bytecode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as viemT from "viem";
import type * as viemT from "viem" with { "resolution-mode": "import" };
import type { Artifact } from "hardhat/types/artifacts";

import {
Expand All @@ -22,7 +22,9 @@ export async function linkBytecode(
artifact: Artifact,
libraries: Link[]
): Promise<viemT.Hex> {
const { isHex } = require("viem") as typeof import("viem");
const { isHex } = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
let bytecode = artifact.bytecode;

// TODO: measure performance impact
Expand Down
10 changes: 7 additions & 3 deletions packages/hardhat-viem/src/internal/chains.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { EthereumProvider } from "hardhat/types";
import type { Chain } from "viem";
import type { Chain } from "viem" with { "resolution-mode": "import" };
import type { TestClientMode } from "../types";

import memoize from "lodash.memoize";

import { UnknownDevelopmentNetworkError, NetworkNotFoundError } from "./errors";

export async function getChain(provider: EthereumProvider): Promise<Chain> {
const { extractChain } = require("viem") as typeof import("viem");
const chainsModule = require("viem/chains") as typeof import("viem/chains");
const { extractChain } = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const chainsModule = require("viem/chains") as typeof import("viem/chains", {
with: { "resolution-mode": "import" },
});
const chains = Object.values(chainsModule) as Chain[];
const chainId = await getChainId(provider);

Expand Down
14 changes: 10 additions & 4 deletions packages/hardhat-viem/src/internal/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
PublicClientConfig,
WalletClientConfig,
TestClientConfig,
} from "viem";
} from "viem" with { "resolution-mode": "import" };
import type {
PublicClient,
TestClient,
Expand Down Expand Up @@ -56,7 +56,9 @@ export async function innerGetPublicClient(
chain: Chain,
publicClientConfig?: Partial<PublicClientConfig>
): Promise<PublicClient> {
const viem = require("viem") as typeof import("viem");
const viem = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const { clientParameters, transportParameters } = await getParameters(
chain,
publicClientConfig
Expand Down Expand Up @@ -97,7 +99,9 @@ export async function innerGetWalletClients(
accounts: Address[],
walletClientConfig?: Partial<WalletClientConfig>
): Promise<WalletClient[]> {
const viem = require("viem") as typeof import("viem");
const viem = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const { clientParameters, transportParameters } = await getParameters(
chain,
walletClientConfig
Expand Down Expand Up @@ -161,7 +165,9 @@ export async function innerGetTestClient(
mode: TestClientMode,
testClientConfig?: Partial<TestClientConfig>
): Promise<TestClient> {
const viem = require("viem") as typeof import("viem");
const viem = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const { clientParameters, transportParameters } = await getParameters(
chain,
testClientConfig
Expand Down
12 changes: 9 additions & 3 deletions packages/hardhat-viem/src/internal/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type {
EthereumProvider,
HardhatRuntimeEnvironment,
} from "hardhat/types";
import type { Abi, Address, Hex } from "viem";
import type { Abi, Address, Hex } from "viem" with {
"resolution-mode": "import",
};
import type {
DeployContractConfig,
GetContractAtConfig,
Expand Down Expand Up @@ -191,7 +193,9 @@ async function innerSendDeploymentTransaction(
hash: deploymentTxHash,
});

const { getContractAddress } = require("viem") as typeof import("viem");
const { getContractAddress } = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const contractAddress = getContractAddress({
from: walletClient.account.address,
nonce: BigInt(deploymentTx.nonce),
Expand Down Expand Up @@ -234,7 +238,9 @@ async function innerGetContractAt(
contractAbi: Abi,
address: Address
): Promise<GetContractReturnType> {
const viem = require("viem") as typeof import("viem");
const viem = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});
const contract = viem.getContract({
address,
client: {
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-viem/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as viemT from "viem";
import type * as viemT from "viem" with { "resolution-mode": "import" };
import type { ArtifactsMap } from "hardhat/types/artifacts";
import type { Libraries } from "./internal/bytecode";

Expand Down
5 changes: 4 additions & 1 deletion packages/hardhat-viem/test/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { EthereumProvider } from "hardhat/types";

import { expect, assert } from "chai";
import sinon from "sinon";
import * as chains from "viem/chains";

import {
getChain,
Expand All @@ -11,6 +10,10 @@ import {
} from "../src/internal/chains";
import { EthereumMockedProvider } from "./mocks/provider";

const chains = require("viem/chains") as typeof import("viem/chains", {
with: { "resolution-mode": "import" },
});

describe("chains", () => {
describe("getChain", () => {
afterEach(sinon.restore);
Expand Down
5 changes: 4 additions & 1 deletion packages/hardhat-viem/test/clients.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { EthereumProvider } from "hardhat/types";

import { assert, expect } from "chai";
import * as chains from "viem/chains";

import {
innerGetPublicClient,
Expand All @@ -10,6 +9,10 @@ import {
} from "../src/internal/clients";
import { EthereumMockedProvider } from "./mocks/provider";

const chains = require("viem/chains") as typeof import("viem/chains", {
with: { "resolution-mode": "import" },
});

describe("clients", () => {
describe("innerGetPublicClient", () => {
it("should return a public client", async () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/hardhat-viem/test/integration.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { Hex, TransactionReceipt } from "viem";
import type { Hex, TransactionReceipt } from "viem" with {
"resolution-mode": "import",
};
import type { EthereumProvider } from "hardhat/types";

import path from "path";
import { assert, expect } from "chai";
import sinon from "sinon";
import { getAddress, parseEther } from "viem";

import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names";
import { deployContract, innerDeployContract } from "../src/internal/contracts";
import { EthereumMockedProvider } from "./mocks/provider";
import { assertSnapshotMatch, sleep, useEnvironment } from "./helpers";

const { getAddress, parseEther } = require("viem") as typeof import("viem", {
with: { "resolution-mode": "import" },
});

describe("Integration tests", function () {
afterEach(function () {
sinon.restore();
Expand Down