Agent skill
viem
Viem blockchain client patterns for Ethereum interactions, transactions, signing, encoding, and smart contract calls. Triggers on viem, publicClient, walletClient, chain, abi.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/viem
SKILL.md
<mcp_first> CRITICAL: Always fetch viem documentation before implementing.
MCPSearch({ query: "select:mcp__plugin_devtools_context7__query-docs" })
// Client patterns
mcp__context7__query_docs({
context7CompatibleLibraryID: "/wevm/viem",
topic: "createPublicClient createWalletClient"
})
// Contract interactions
mcp__context7__query_docs({
context7CompatibleLibraryID: "/wevm/viem",
topic: "readContract writeContract simulateContract"
})
// Signing
mcp__context7__query_docs({
context7CompatibleLibraryID: "/wevm/viem",
topic: "signMessage signTypedData EIP-712"
})
// Encoding
mcp__context7__query_docs({
context7CompatibleLibraryID: "/wevm/viem",
topic: "encodeFunctionData decodeFunctionResult encodeAbiParameters"
})
</mcp_first>
<quick_start> Create clients:
import { createPublicClient, createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const walletClient = createWalletClient({
chain: mainnet,
transport: http(),
account: privateKeyToAccount("0x..."),
});
Read contract:
const balance = await publicClient.readContract({
address: "0x...",
abi: erc20Abi,
functionName: "balanceOf",
args: [userAddress],
});
Write contract:
const hash = await walletClient.writeContract({
address: "0x...",
abi: erc20Abi,
functionName: "transfer",
args: [recipient, amount],
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
</quick_start>
<client_types>
| Client | Purpose | Example Use |
|---|---|---|
PublicClient |
Reading blockchain data | getBlockNumber(), readContract() |
WalletClient |
Transaction signing/sending | sendTransaction(), signMessage() |
TestClient |
Testing and simulation | mine(), setBalance() |
BundlerClient |
ERC-4337 User Operations | sendUserOperation() |
| </client_types> |
import { parseEther, formatEther, parseUnits, formatUnits } from "viem";
parseEther("1.5"); // 1500000000000000000n
formatEther(1500000000000000000n); // "1.5"
parseUnits("100", 6); // 100000000n (USDC)
formatUnits(100000000n, 6); // "100"
Address utilities:
import { getAddress, isAddress } from "viem";
getAddress("0xabc..."); // Checksummed address
isAddress("0x..."); // Validates format
Required:
- Lazy initialization for chain resolution
- Client caching by network name
- WebSocket cleanup on destroy/refresh
- Type-safe ABI interactions
<success_criteria>
- Context7 docs fetched for current API
- Uses lazy chain resolution
- Caches clients by network name
- Type-safe ABI interactions
- Proper error handling for blockchain ops </success_criteria>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?