viem
Installation
SKILL.md
viem
TypeScript interface for Ethereum and EVM-compatible chains. Provides low-level primitives for blockchain interaction with end-to-end type safety, minimal abstraction overhead, and tree-shakeable modules. The default client library for wagmi.
What You Probably Got Wrong
AI agents trained before 2024 confuse viem with ethers.js patterns. These are the critical differences.
- viem uses native
bigint, notBigNumber-- There is noBigNumberclass. All wei values arebigint. Use100nliteral syntax orBigInt("100"). Never useethers.BigNumber.from(). Addresstype is`0x${string}`, not plainstring-- viem enforces checksummed0x-prefixed addresses at the type level. UsegetAddress()to normalize.- Clients are not providers -- viem has
PublicClient(reads),WalletClient(writes), andTestClient(anvil). There is noProviderorSignerconcept. - Transports replace connection URLs -- You pass
http(),webSocket(), orcustom()transports to clients, not raw RPC URLs as strings. - ABIs must be
as const-- For type inference to work, ABI arrays must useas constassertion. Without it, you lose all parameter/return type safety. simulateContractbeforewriteContract-- viem separates simulation from execution. Always simulate first to catch reverts before sending a transaction.- No default chain -- Every client requires an explicit
chainparameter. There is no implicit mainnet default. parseEtherreturnsbigint, not a wrapper --parseEther("1.0")returns1000000000000000000n, a rawbigint.