viem
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "viem":https://skillpi.com/zh/skills/deepskill-073e94e493da645aa88769bb916a8878d92b950bfc763df016fc6f683810e8e3。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
Viem 专家:Viem 是以太坊的 TypeScript 接口,提供与区块链交互的类型安全低级原语。用于构建 dApp、脚本和后端,帮助读取链上数据、发送交易、与智能合约交互并处理钱包连接;支持从 ABI 完全推断类型、可进行摇树优化的模块,并且除 noble 密码学外零依赖。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: viem
description: >-
You are an expert in Viem, the TypeScript interface for Ethereum that
provides low-level, type-safe primitives for interacting with the
blockchain. You help developers build dApps, scripts, and backends that read
blockchain data, send transactions, interact with smart contracts, and
handle wallet connections — with full type inference from ABIs,
tree-shakeable modules, and zero dependencies beyond noble cryptography.
license: Apache-2.0
compatibility: ''
metadata:
author: terminal-skills
version: 1.0.0
category: Blockchain & Web3
tags:
- ethereum
- typescript
- web3
- rpc
- smart-contracts
- type-safe
- wagmiViem — Type-Safe Ethereum Interactions for TypeScript
You are an expert in Viem, the TypeScript interface for Ethereum that provides low-level, type-safe primitives for interacting with the blockchain. You help developers build dApps, scripts, and backends that read blockchain data, send transactions, interact with smart contracts, and handle wallet connections — with full type inference from ABIs, tree-shakeable modules, and zero dependencies beyond noble cryptography.
Core Capabilities
Client Setup
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
import { mainnet, sepolia } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
// Public client: read blockchain data (no wallet needed)
const publicClient = createPublicClient({
chain: mainnet,
transport: http("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"),
});
// Wallet client: sign and send transactions
const account = privateKeyToAccount("0x...");
const walletClient = createWalletClient({
account,
chain: mainnet,
transport: http("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"),
});
Read Blockchain Data
// Get ETH balance
const balance = await publicClient.getBalance({
address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // vitalik.eth
});
console.log(`Balance: ${formatEther(balance)} ETH`);
// Get block
const block = await publicClient.getBlock({ blockTag: "latest" });
console.log(`Block #${block.number}: ${block.transactions.length} txs`);
// Read contract (type-safe from ABI)
const erc20Abi = [
{
name: "balanceOf",
type: "function",
stateMutability: "view",
inputs: [{ name: "account", type: "address" }],
outputs: [{ name: "balance", type: "uint256" }],
},
] as const;
const usdcBalance = await publicClient.readContract({
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
abi: erc20Abi,
functionName: "balanceOf", // Autocompleted from ABI
args: ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"],
});
// Return type automatically inferred as bigint
Write Transactions
// Send ETH
const hash = await walletClient.sendTransaction({
to: "0x...",
value: parseEther("0.1"),
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
// Write to contract
const hash = await walletClient.writeContract({
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
abi: erc20Abi,
functionName: "transfer",
args: ["0xrecipient...", 1000000n], // 1 USDC (6 decimals)
});
Event Watching
// Watch for ERC-20 Transfer events in real-time
const unwatch = publicClient.watchContractEvent({
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
abi: erc20Abi,
eventName: "Transfer",
onLogs: (logs) => {
for (const log of logs) {
console.log(`Transfer: ${log.args.from} → ${log.args.to}: ${log.args.value}`);
}
},
});
// Get historical events
const transferLogs = await publicClient.getContractEvents({
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
abi: erc20Abi,
eventName: "Transfer",
fromBlock: 18000000n,
toBlock: 18001000n,
});
ENS Resolution
// ENS name → address
const address = await publicClient.getEnsAddress({ name: "vitalik.eth" });
// Address → ENS name
const name = await publicClient.getEnsName({
address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
});
Installation
npm install viem
Best Practices
- ABI as const — Declare ABIs with
as constfor full type inference on function names, args, and return types - Separate clients — Use
publicClientfor reads (free),walletClientfor writes (costs gas) - waitForTransactionReceipt — Always wait for receipt after sending; don't assume success from hash alone
- parseEther/formatEther — Use viem's utilities for ETH conversions; never do manual decimal math with bigint
- Chain configuration — Import chains from
viem/chains; includes RPC URLs, block explorer, native currency - Error handling — Viem throws typed errors; catch
ContractFunctionRevertedErrorfor contract reverts - Batch requests — Use
multicallto batch multiple contract reads into one RPC call; reduces latency - Works with wagmi — Viem is the core of wagmi (React hooks for Ethereum); same patterns, same types
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Viem 类型安全以太坊交互的核心能力,解决区块链开发者高频刚需
- 覆盖 dApp 开发全流程:读取数据、发送交易、合约交互、钱包连接
- 明确的受众定位:TypeScript/JavaScript 区块链开发者
亮点
- 触发词精准完整:viem, typescript, ethereum, web3, smart-contracts, rpc, type-safe
- description 清晰界定 Skill 边界,不易与其他区块链工具混淆
亮点
- 结构清晰:Core Capabilities, Installation, Best Practices 章节完整
- 提供端到端代码示例,涵盖 Client Setup, Read/Write, Events, ENS 等核心场景
- frontmatter 完整,单文件长度适中
亮点
- 工具来源明确:viem 官方 npm 包
- 参数使用规范,覆盖主要异常处理建议
- 对不可逆操作(交易发送)提供确认机制指导
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 146 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- eth-mainnet.g.alchemy.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。