Skip to content

Commit 2409659

Browse files
committed
Align client configuration with viem@2 standards for consistency
1 parent e4b1c07 commit 2409659

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

packages/hardhat-viem/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const contractA = await hre.viem.deployContract(
154154
"contractName",
155155
["arg1", 50, "arg3"],
156156
{
157-
walletClient: secondWalletClient,
157+
client: { wallet: secondWalletClient }
158158
gas: 1000000,
159159
value: parseEther("0.0001"),
160160
confirmations: 5, // 1 by default
@@ -185,7 +185,7 @@ const [_, secondWalletClient] = await hre.viem.getWalletClients();
185185
const contract = await hre.viem.getContractAt(
186186
"contractName",
187187
"0x1234567890123456789012345678901234567890",
188-
{ walletClient: secondWalletClient }
188+
{ client: { wallet: secondWalletClient } }
189189
);
190190
```
191191

@@ -210,7 +210,7 @@ const { contract: contractName, deploymentTransaction } =
210210
"contractName",
211211
["arg1", 50, "arg3"],
212212
{
213-
walletClient: secondWalletClient,
213+
client: { wallet: secondWalletClient },
214214
gas: 1000000,
215215
value: parseEther("0.0001"),
216216
}

packages/hardhat-viem/src/internal/contracts.ts

+8-19
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ export async function deployContract(
2727
constructorArgs: any[] = [],
2828
config: DeployContractConfig = {}
2929
): Promise<GetContractReturnType> {
30-
const {
31-
walletClient: configWalletClient,
32-
publicClient: configPublicClient,
33-
confirmations,
34-
...deployContractParameters
35-
} = config;
30+
const { client, confirmations, ...deployContractParameters } = config;
3631
const [publicClient, walletClient, contractArtifact] = await Promise.all([
37-
configPublicClient ?? getPublicClient(network.provider),
38-
configWalletClient ??
39-
getDefaultWalletClient(network.provider, network.name),
32+
client?.public ?? getPublicClient(network.provider),
33+
client?.wallet ?? getDefaultWalletClient(network.provider, network.name),
4034
artifacts.readArtifact(contractName),
4135
]);
4236

@@ -120,15 +114,10 @@ export async function sendDeploymentTransaction(
120114
contract: GetContractReturnType;
121115
deploymentTransaction: GetTransactionReturnType;
122116
}> {
123-
const {
124-
walletClient: configWalletClient,
125-
publicClient: configPublicClient,
126-
...deployContractParameters
127-
} = config;
117+
const { client, ...deployContractParameters } = config;
128118
const [publicClient, walletClient, contractArtifact] = await Promise.all([
129-
configPublicClient ?? getPublicClient(network.provider),
130-
configWalletClient ??
131-
getDefaultWalletClient(network.provider, network.name),
119+
client?.public ?? getPublicClient(network.provider),
120+
client?.wallet ?? getDefaultWalletClient(network.provider, network.name),
132121
artifacts.readArtifact(contractName),
133122
]);
134123

@@ -202,8 +191,8 @@ export async function getContractAt(
202191
config: GetContractAtConfig = {}
203192
): Promise<GetContractReturnType> {
204193
const [publicClient, walletClient, contractArtifact] = await Promise.all([
205-
config.publicClient ?? getPublicClient(network.provider),
206-
config.walletClient ??
194+
config.client?.public ?? getPublicClient(network.provider),
195+
config.client?.wallet ??
207196
getDefaultWalletClient(network.provider, network.name),
208197
artifacts.readArtifact(contractName),
209198
]);

packages/hardhat-viem/src/types.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ export type TestClient = viemT.TestClient<
1313
viemT.Chain
1414
>;
1515

16+
export type KeyedClient =
17+
| {
18+
public?: PublicClient;
19+
wallet: WalletClient;
20+
}
21+
| {
22+
public: PublicClient;
23+
wallet?: WalletClient;
24+
};
25+
1626
export type TestClientMode = Parameters<
1727
typeof viemT.createTestClient
1828
>[0]["mode"];
1929

2030
export interface SendTransactionConfig {
21-
walletClient?: WalletClient;
22-
publicClient?: PublicClient;
31+
client?: KeyedClient;
2332
gas?: bigint;
2433
gasPrice?: bigint;
2534
maxFeePerGas?: bigint;
@@ -34,20 +43,12 @@ export interface DeployContractConfig extends SendTransactionConfig {
3443
export type SendDeploymentTransactionConfig = SendTransactionConfig;
3544

3645
export interface GetContractAtConfig {
37-
walletClient?: WalletClient;
38-
publicClient?: PublicClient;
46+
client?: KeyedClient;
3947
}
4048

4149
export type GetContractReturnType<
4250
TAbi extends viemT.Abi | readonly unknown[] = viemT.Abi
43-
> = viemT.GetContractReturnType<
44-
TAbi,
45-
{
46-
public: PublicClient;
47-
wallet: WalletClient;
48-
},
49-
viemT.Address
50-
>;
51+
> = viemT.GetContractReturnType<TAbi, Required<KeyedClient>, viemT.Address>;
5152

5253
export type GetTransactionReturnType = viemT.GetTransactionReturnType<
5354
viemT.Chain,

packages/hardhat-viem/test/integration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe("Integration tests", function () {
141141
const contract = await this.hre.viem.deployContract(
142142
"WithoutConstructorArgs",
143143
[],
144-
{ walletClient: secondWalletClient }
144+
{ client: { wallet: secondWalletClient } }
145145
);
146146

147147
const owner = await contract.read.getOwner();

0 commit comments

Comments
 (0)