一键导入
viem
Use viem for Celo development. Includes fee currency support, transaction signing, and Celo-specific configurations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use viem for Celo development. Includes fee currency support, transaction signing, and Celo-specific configurations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
ERC-8004 Agent Trust Protocol for AI agent identity, reputation, and validation on Celo. Use when building AI agents that need identity registration, reputation tracking, or trust verification across organizational boundaries.
Bridge assets to and from Celo. Use when transferring tokens between Celo and other chains like Ethereum.
Scaffold Celo dApps with Celo Composer. Use when starting new Celo projects, creating MiniPay apps, or setting up development environments.
Integrate DeFi protocols on Celo. Use when building swaps, lending, or liquidity applications with Uniswap, Aave, Ubeswap, or other DeFi protocols.
Interact with Celo blockchain via RPC endpoints. Use when reading balances, transactions, blocks, and interacting with Celo via viem or cast.
Working with Celo's stablecoin ecosystem. Use when building with USDm, EURm, USDC, USDT, or regional Mento stablecoins on Celo.
基于 SOC 职业分类
| name | viem |
| description | Use viem for Celo development. Includes fee currency support, transaction signing, and Celo-specific configurations. |
| license | Apache-2.0 |
| metadata | {"author":"celo-org","version":"1.0.0"} |
Viem is a lightweight TypeScript library with first-class Celo support. It powers wagmi and RainbowKit.
Source: https://viem.sh/docs/chains/celo
npm install viem
Source: https://github.com/wevm/viem (chain definitions)
import { celo } from "viem/chains";
// Chain ID: 42220
// RPC: https://forno.celo.org
// Explorer: https://celoscan.io
import { celoSepolia } from "viem/chains";
// Chain ID: 11142220
// RPC: https://forno.celo-sepolia.celo-testnet.org
// Explorer: https://celo-sepolia.blockscout.com
import { defineChain } from "viem";
import { chainConfig } from "viem/celo";
export const customCeloChain = defineChain({
...chainConfig,
id: 42220,
name: "Custom Celo",
// ...
});
import { createPublicClient, http } from "viem";
import { celo } from "viem/chains";
const publicClient = createPublicClient({
chain: celo,
transport: http(),
});
// Read contract state
const balance = await publicClient.getBalance({
address: "0x...",
});
import { createWalletClient, custom } from "viem";
import { celo } from "viem/chains";
const walletClient = createWalletClient({
chain: celo,
transport: custom(window.ethereum),
});
const [address] = await walletClient.getAddresses();
Celo allows paying gas fees in tokens other than CELO. Use whitelisted fee currency adapters.
Source: https://viem.sh/docs/chains/celo
| Token | Adapter Address |
|---|---|
| USDC | 0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B |
| USDT | 0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72 |
| Token | Adapter Address |
|---|---|
| USDC | 0x4822e58de6f5e485eF90df51C41CE01721331dC0 |
import { serializeTransaction } from "viem/celo";
import { parseGwei, parseEther } from "viem";
const serialized = serializeTransaction({
chainId: 42220,
gas: 21001n,
feeCurrency: "0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B", // USDC adapter
maxFeePerGas: parseGwei("20"),
maxPriorityFeePerGas: parseGwei("2"),
nonce: 69,
to: "0x1234512345123451234512345123451234512345",
value: parseEther("0.01"),
});
import { createWalletClient, custom, parseEther } from "viem";
import { celo } from "viem/chains";
const USDC_ADAPTER = "0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B";
const walletClient = createWalletClient({
chain: celo,
transport: custom(window.ethereum),
});
const [address] = await walletClient.getAddresses();
// Send transaction paying gas in USDC
const hash = await walletClient.sendTransaction({
account: address,
to: "0x...",
value: parseEther("1"),
feeCurrency: USDC_ADAPTER,
});
const hash = await walletClient.writeContract({
address: CONTRACT_ADDRESS,
abi: CONTRACT_ABI,
functionName: "transfer",
args: [recipient, amount],
feeCurrency: USDC_ADAPTER,
});
import { parseTransaction } from "viem/celo";
// Supports CIP-64, EIP-1559, EIP-2930, and Legacy transactions
const transaction = parseTransaction("0x7cf846...");
import { serializeTransaction } from "viem/celo";
const serialized = serializeTransaction({
chainId: 42220,
feeCurrency: "0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B",
// ... other params
});
import { createPublicClient, http } from "viem";
import { celo } from "viem/chains";
const publicClient = createPublicClient({
chain: celo,
transport: http(),
});
const ERC20_ABI = [
{
name: "balanceOf",
type: "function",
stateMutability: "view",
inputs: [{ name: "account", type: "address" }],
outputs: [{ type: "uint256" }],
},
] as const;
const balance = await publicClient.readContract({
address: "0x765de816845861e75a25fca122bb6898b8b1282a", // USDm
abi: ERC20_ABI,
functionName: "balanceOf",
args: ["0x..."],
});
Batch multiple read calls efficiently:
const results = await publicClient.multicall({
contracts: [
{
address: TOKEN_ADDRESS,
abi: ERC20_ABI,
functionName: "balanceOf",
args: [userAddress],
},
{
address: TOKEN_ADDRESS,
abi: ERC20_ABI,
functionName: "totalSupply",
},
],
});
feeCurrency)0x7b (CIP-64)feeCurrency defaults to paying in CELOviem/celo for Celo-specific utilities (parseTransaction, serializeTransaction){
"dependencies": {
"viem": "^2.0.0"
}
}