datahaven/test/utils/viem.ts
Facundo Farall 4c7a64fc39
fix: 🚨 Add error in TS for missing awaits (#81)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Documentation**
- Added detailed IDE configuration recommendations for Rust, Solidity,
and TypeScript in the README to enhance developer experience.

- **Chores**
- Updated Biome configuration files and package dependencies to the
latest schema and version.
- Refined code formatting, linting, and import organization settings for
consistency across the project.

- **Refactor**
- Reordered import statements in multiple files for improved
readability.
- Simplified function signatures and ensured proper async handling in
utility scripts.

- **Bug Fixes**
- Ensured proper completion of asynchronous operations in shell utility
functions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
2025-05-19 22:28:43 +00:00

43 lines
1.3 KiB
TypeScript

import { ANVIL_FUNDED_ACCOUNTS, CHAIN_ID, getRPCUrl, getWSUrl } from "utils";
import { createWalletClient, defineChain, http, publicActions } from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import type { Prettify } from "./types";
export const createChainConfig = async () =>
defineChain({
id: CHAIN_ID,
name: "Kurtosis",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH"
},
rpcUrls: {
default: {
http: [await getRPCUrl()],
webSocket: [await getWSUrl()]
}
},
blockExplorers: {
default: { name: "Blockscout", url: "http://127.0.0.1:3000" }
}
// Example of how we can preload contracts into the API, useful for AVS
// contracts: {
// multicall3: {
// address: '0xcA11bde05977b3631167028862bE2a173976CA11',
// blockCreated: 5882,
// },
// },
});
export const createDefaultClient = async () =>
createWalletClient({
account: privateKeyToAccount(ANVIL_FUNDED_ACCOUNTS[0].privateKey),
chain: await createChainConfig(),
transport: http()
}).extend(publicActions);
export type ViemClientInterface = Prettify<Awaited<ReturnType<typeof createDefaultClient>>>;
export const generateRandomAccount = () => privateKeyToAccount(generatePrivateKey());