Skip to content

hre.viem.getPublicClient() fails without explicit transport parameter #6455

Open
@s-di-cola

Description

@s-di-cola

Version of Hardhat

2.22.19

What happened?

Bug: hre.viem.getPublicClient() fails without explicit transport parameter

Description

When using the hardhat-viem plugin, calling hre.viem.getPublicClient() without parameters fails, but works correctly when explicitly providing a transport with hre.viem.getPublicClient({transport: http()}).

Expected Behavior

hre.viem.getPublicClient() should work properly without requiring an explicit transport, as the plugin should configure the transport automatically when connecting to the Hardhat Network.

Actual Behavior

Without an explicit transport, the function fails. With {transport: http()}, it works correctly.

Workaround

Use either:

// Working solution with hardhat-viem
const publicClient = await hre.viem.getPublicClient({transport: http()})

// OR use viem directly
const publicClient = createPublicClient({
  chain: hardhat,
  transport: http()
});

### Minimal reproduction steps

### Steps to Reproduce
1. Set up a Hardhat project with the hardhat-viem plugin
2. Try to get a public client with: `const publicClient = await hre.viem.getPublicClient()`
3. Observe that this fails
4. Change to: `const publicClient = await hre.viem.getPublicClient({transport: http()})`
5. Observe that this works correctly

### Search terms

_No response_

Metadata

Metadata

Assignees

Labels

status:needs-more-infoThere's not enough information to start working on this issue

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions