diff --git a/packages/hardhat-viem/README.md b/packages/hardhat-viem/README.md index f2bfc30d51..f1959f1542 100644 --- a/packages/hardhat-viem/README.md +++ b/packages/hardhat-viem/README.md @@ -154,7 +154,7 @@ const contractA = await hre.viem.deployContract( "contractName", ["arg1", 50, "arg3"], { - walletClient: secondWalletClient, + client: { wallet: secondWalletClient } gas: 1000000, value: parseEther("0.0001"), confirmations: 5, // 1 by default @@ -185,7 +185,7 @@ const [_, secondWalletClient] = await hre.viem.getWalletClients(); const contract = await hre.viem.getContractAt( "contractName", "0x1234567890123456789012345678901234567890", - { walletClient: secondWalletClient } + { client: { wallet: secondWalletClient } } ); ``` @@ -210,7 +210,7 @@ const { contract: contractName, deploymentTransaction } = "contractName", ["arg1", 50, "arg3"], { - walletClient: secondWalletClient, + client: { wallet: secondWalletClient }, gas: 1000000, value: parseEther("0.0001"), } diff --git a/packages/hardhat-viem/src/internal/contracts.ts b/packages/hardhat-viem/src/internal/contracts.ts index 8d253162e7..24e7f0668a 100644 --- a/packages/hardhat-viem/src/internal/contracts.ts +++ b/packages/hardhat-viem/src/internal/contracts.ts @@ -27,16 +27,10 @@ export async function deployContract( constructorArgs: any[] = [], config: DeployContractConfig = {} ): Promise { - const { - walletClient: configWalletClient, - publicClient: configPublicClient, - confirmations, - ...deployContractParameters - } = config; + const { client, confirmations, ...deployContractParameters } = config; const [publicClient, walletClient, contractArtifact] = await Promise.all([ - configPublicClient ?? getPublicClient(network.provider), - configWalletClient ?? - getDefaultWalletClient(network.provider, network.name), + client?.public ?? getPublicClient(network.provider), + client?.wallet ?? getDefaultWalletClient(network.provider, network.name), artifacts.readArtifact(contractName), ]); @@ -120,15 +114,10 @@ export async function sendDeploymentTransaction( contract: GetContractReturnType; deploymentTransaction: GetTransactionReturnType; }> { - const { - walletClient: configWalletClient, - publicClient: configPublicClient, - ...deployContractParameters - } = config; + const { client, ...deployContractParameters } = config; const [publicClient, walletClient, contractArtifact] = await Promise.all([ - configPublicClient ?? getPublicClient(network.provider), - configWalletClient ?? - getDefaultWalletClient(network.provider, network.name), + client?.public ?? getPublicClient(network.provider), + client?.wallet ?? getDefaultWalletClient(network.provider, network.name), artifacts.readArtifact(contractName), ]); @@ -202,8 +191,8 @@ export async function getContractAt( config: GetContractAtConfig = {} ): Promise { const [publicClient, walletClient, contractArtifact] = await Promise.all([ - config.publicClient ?? getPublicClient(network.provider), - config.walletClient ?? + config.client?.public ?? getPublicClient(network.provider), + config.client?.wallet ?? getDefaultWalletClient(network.provider, network.name), artifacts.readArtifact(contractName), ]); diff --git a/packages/hardhat-viem/src/types.ts b/packages/hardhat-viem/src/types.ts index 42890070d8..8820d8cebf 100644 --- a/packages/hardhat-viem/src/types.ts +++ b/packages/hardhat-viem/src/types.ts @@ -13,13 +13,22 @@ export type TestClient = viemT.TestClient< viemT.Chain >; +export type KeyedClient = + | { + public?: PublicClient; + wallet: WalletClient; + } + | { + public: PublicClient; + wallet?: WalletClient; + }; + export type TestClientMode = Parameters< typeof viemT.createTestClient >[0]["mode"]; export interface SendTransactionConfig { - walletClient?: WalletClient; - publicClient?: PublicClient; + client?: KeyedClient; gas?: bigint; gasPrice?: bigint; maxFeePerGas?: bigint; @@ -34,20 +43,12 @@ export interface DeployContractConfig extends SendTransactionConfig { export type SendDeploymentTransactionConfig = SendTransactionConfig; export interface GetContractAtConfig { - walletClient?: WalletClient; - publicClient?: PublicClient; + client?: KeyedClient; } export type GetContractReturnType< TAbi extends viemT.Abi | readonly unknown[] = viemT.Abi -> = viemT.GetContractReturnType< - TAbi, - { - public: PublicClient; - wallet: WalletClient; - }, - viemT.Address ->; +> = viemT.GetContractReturnType, viemT.Address>; export type GetTransactionReturnType = viemT.GetTransactionReturnType< viemT.Chain, diff --git a/packages/hardhat-viem/test/integration.ts b/packages/hardhat-viem/test/integration.ts index d62ac2d030..c8ae64d8ff 100644 --- a/packages/hardhat-viem/test/integration.ts +++ b/packages/hardhat-viem/test/integration.ts @@ -141,7 +141,7 @@ describe("Integration tests", function () { const contract = await this.hre.viem.deployContract( "WithoutConstructorArgs", [], - { walletClient: secondWalletClient } + { client: { wallet: secondWalletClient } } ); const owner = await contract.read.getOwner();