import { HardhatContainer, StartedHardhatContainer } from 'hardhat-testcontainers';
import { createPublicClient, http, PublicClient } from 'viem';
import { hardhat } from 'viem/chains';
let container: StartedHardhatContainer;
beforeAll(async () => {
container = await new HardhatContainer().start();
});
afterAll(async () => {
await container.stop();
});
it('should rpc(eth_blockNumber) via viem', async () => {
const client = createPublicClient({ chain: hardhat, transport: http(container.getHostRpcEndpoint()) });
const blockNumber = await client.getBlockNumber();
expect(blockNumber).toStrictEqual(BigInt(0));
});
This library creates a Docker image that isolates the toolchain for Hardhat from the host system. This is particularly useful for language-agnostic development and parallelization of systems.
MPL-2.0