KS
Killer-Skills

viem — how to use viem how to use viem, viem ethereum client, viem vs web3.js, viem install guide, viem setup tutorial, what is viem, viem alternative, viem type safety, viem contract interactions

v2.x
GitHub

About this Skill

Perfect for Blockchain Agents needing secure Ethereum smart contract interactions and type safety. Viem is a TypeScript interface for Ethereum, providing a modern approach to client setup, contract interactions, and type safety.

Features

Imports Ethereum clients via `createPublicClient` and `createWalletClient`
Supports HTTP requests using `http` from 'viem'
Utilizes `mainnet` from 'viem/chains' for chain configuration
Enables account management with `privateKeyToAccount` from 'viem/accounts'
Ensures type safety for contract interactions
Provides a quick reference guide for common use cases

# Core Topics

pelith pelith
[0]
[0]
Updated: 3/6/2026

Quality Score

Top 5%
44
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add pelith/Project-Remora-Frontend/viem

Agent Capability Analysis

The viem MCP Server by pelith is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use viem, viem ethereum client, viem vs web3.js.

Ideal Agent Persona

Perfect for Blockchain Agents needing secure Ethereum smart contract interactions and type safety.

Core Value

Empowers agents to securely interact with Ethereum smart contracts using the Viem TypeScript interface, ensuring correct patterns for contract interactions, client setup, and type safety with libraries like 'viem' and protocols such as HTTP.

Capabilities Granted for viem MCP Server

Automating Ethereum smart contract deployments
Generating secure client setups for mainnet and testnet interactions
Debugging type safety issues in Ethereum smart contract integrations

! Prerequisites & Limits

  • Requires TypeScript environment
  • Ethereum blockchain only
  • Private key management required for wallet client setup
Project
SKILL.md
4.1 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

Viem Skill

Version: Viem 2.x | Official Docs

Viem is the modern TypeScript interface for Ethereum. This skill ensures correct patterns for contract interactions, client setup, and type safety.

Quick Reference

typescript
1import { createPublicClient, createWalletClient, http } from 'viem' 2import { mainnet } from 'viem/chains' 3import { privateKeyToAccount } from 'viem/accounts'

Critical Patterns

1. Client Setup

Public Client (read-only operations):

typescript
1const publicClient = createPublicClient({ 2 chain: mainnet, 3 transport: http('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY'), 4})

Wallet Client (write operations):

typescript
1const account = privateKeyToAccount('0x...') 2const walletClient = createWalletClient({ 3 account, 4 chain: mainnet, 5 transport: http('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY'), 6})

2. ABI Type Safety (CRITICAL)

Always use as const for ABIs to get full type inference:

typescript
1// ✅ CORRECT - Full type safety 2const abi = [ 3 { 4 name: 'balanceOf', 5 type: 'function', 6 stateMutability: 'view', 7 inputs: [{ name: 'owner', type: 'address' }], 8 outputs: [{ name: '', type: 'uint256' }], 9 }, 10] as const 11 12// ❌ WRONG - No type inference 13const abi = [{ name: 'balanceOf', ... }] // Missing `as const`

3. Contract Read Pattern

typescript
1const balance = await publicClient.readContract({ 2 address: '0x...', // Contract address 3 abi, 4 functionName: 'balanceOf', 5 args: ['0x...'], // Args are fully typed when using `as const` 6})

4. Contract Write Pattern (Simulate First!)

Always simulate before writing to catch errors early:

typescript
1// Step 1: Simulate 2const { request } = await publicClient.simulateContract({ 3 account, 4 address: '0x...', 5 abi, 6 functionName: 'transfer', 7 args: ['0x...', 1000000n], // Use BigInt for uint256 8}) 9 10// Step 2: Execute 11const hash = await walletClient.writeContract(request) 12 13// Step 3: Wait for receipt 14const receipt = await publicClient.waitForTransactionReceipt({ hash })

5. Event Watching

typescript
1const unwatch = publicClient.watchContractEvent({ 2 address: '0x...', 3 abi, 4 eventName: 'Transfer', 5 onLogs: (logs) => { 6 for (const log of logs) { 7 console.log(log.args.from, log.args.to, log.args.value) 8 } 9 }, 10}) 11 12// Clean up 13unwatch()

6. Multicall for Batch Reads

typescript
1const results = await publicClient.multicall({ 2 contracts: [ 3 { address: '0x...', abi, functionName: 'balanceOf', args: ['0x...'] }, 4 { address: '0x...', abi, functionName: 'totalSupply' }, 5 ], 6}) 7// results[0].result, results[1].result

Common Mistakes

MistakeFix
Missing as const on ABIAdd as const for type inference
Using Number for amountsUse BigInt literals: 1000000n
Writing without simulateAlways simulateContract first
Hardcoding gasLet viem estimate, or use gas: await publicClient.estimateGas(...)
Not awaiting receiptsUse waitForTransactionReceipt for confirmation

Chain Configuration

typescript
1import { mainnet, polygon, arbitrum, optimism, base } from 'viem/chains' 2 3// Custom chain 4const customChain = { 5 id: 123, 6 name: 'My Chain', 7 nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 }, 8 rpcUrls: { 9 default: { http: ['https://rpc.mychain.com'] }, 10 }, 11}

Error Handling

typescript
1import { BaseError, ContractFunctionRevertedError } from 'viem' 2 3try { 4 await publicClient.simulateContract({ ... }) 5} catch (err) { 6 if (err instanceof BaseError) { 7 const revertError = err.walk(e => e instanceof ContractFunctionRevertedError) 8 if (revertError instanceof ContractFunctionRevertedError) { 9 const errorName = revertError.data?.errorName 10 // Handle specific revert reason 11 } 12 } 13}

References

For detailed patterns, see:

  • references/contract-patterns.md - Advanced contract interaction patterns
  • references/common-errors.md - Error handling and debugging guide
  • Viem Documentation - Official docs
  • Viem GitHub - Source and releases

Related Skills

Looking for an alternative to viem or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication