ekx-viem-wagmilisted
Install: claude install-skill Ekinoxis-evm/claude-skills
# viem + wagmi
The contract-interaction layer for every Ekinoxis dApp frontend.
`viem` in 8 projects, `wagmi` in 6.
Docs: https://viem.sh · https://wagmi.sh — or ask the `context7` MCP server, since
viem's API changed meaningfully between v1 and v2.
---
## The split
- **viem** — the primitive. Use directly in server code, scripts, route handlers.
- **wagmi** — React hooks over viem, with caching via TanStack Query. Use in components.
When Privy is the wallet, wagmi comes from `@privy-io/wagmi`, not `wagmi` —
see [`../ekx-privy/SKILL.md`](../ekx-privy/SKILL.md).
---
## Config
```ts
// lib/chain.ts
import { base, baseSepolia } from "viem/chains";
// One chain at a time, chosen by env var — our standard pattern.
// No chain switcher in the UI; it is a support burden and a source of wrong-network txs.
export const CHAIN = process.env.NEXT_PUBLIC_CHAIN === "mainnet" ? base : baseSepolia;
export const RPC_URL =
process.env.NEXT_PUBLIC_CHAIN === "mainnet"
? process.env.NEXT_PUBLIC_BASE_MAINNET_RPC_URL!
: process.env.NEXT_PUBLIC_BASE_SEPOLIA_RPC_URL!;
```
```ts
// lib/viem.ts — server-side reads
import { createPublicClient, http } from "viem";
export const publicClient = createPublicClient({
chain: CHAIN,
transport: http(RPC_URL),
});
```
Always pass an explicit RPC URL. `http()` with no argument uses the chain's public
endpoint, which rate-limits under real traffic and produces intermittent,
hard-to-reproduce read failures in production.
---
## Decimal