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

Add publicClient property in hardhat-viem #6161

Open
kanej opened this issue Jan 20, 2025 · 0 comments
Open

Add publicClient property in hardhat-viem #6161

kanej opened this issue Jan 20, 2025 · 0 comments
Assignees
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Milestone

Comments

@kanej
Copy link
Member

kanej commented Jan 20, 2025

The Hardhat 3 version of hardhat-viem should have a publicClient property in addition to the getPublicClient getter. We didn't do that in v2 because viem clients are built asynchronously, and the HRE needed to be built synchronously. But in v3, the viem object is returned by the async network.connect method, so we can create and add a client.

The reason this is valuable is that it makes less verbose the very verbose viem usage:

// before
const { viem } = await network.connect()
const publicClient = await viem.getPublicClient();
console.log(await publicClient.getBlockNumber())

// after
const { viem } = await network.connect()
console.log(await viem.publicClient.getBlockNumber())

There's probably other things we could look into here. For example, maybe we could have a viem.client property, which only has public actions if there are no configured wallets, has test actions when connecting to a Hardhat network, etc. But I think we should keep it simple. The publicClient property is obvious and unlikely to be a bad call, and we can add other things later in a backwards compatible way.

@kanej kanej added the v-next A Hardhat v3 development task label Jan 20, 2025
@kanej kanej added this to the Public Alpha Feature Rollout milestone Jan 20, 2025
@kanej kanej added this to Hardhat Jan 20, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Jan 20, 2025
@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Jan 20, 2025
@kanej kanej moved this from Backlog to To-do in Hardhat Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Status: To-do
Development

No branches or pull requests

2 participants