EVM Blockchain Operations
A comprehensive skill for interacting with EVM-compatible blockchains using the viem library.
Supported Networks
Mainnets
- •Ethereum (mainnet, eth)
- •Optimism (optimism, op)
- •Arbitrum (arbitrum, arb)
- •Arbitrum Nova
- •Base
- •Polygon (polygon, matic)
- •Polygon zkEVM
- •Avalanche (avalanche, avax)
- •BSC (binance, bsc)
- •zkSync
- •Linea
- •Celo
- •Gnosis (gnosis, xdai)
- •Fantom (fantom, ftm)
- •Filecoin
- •Moonbeam
- •Moonriver
- •Cronos
- •Scroll
- •Mantle
- •Manta
- •Blast
- •Fraxtal
- •Mode
- •Metis
- •Kroma
- •Zora
- •Aurora
- •Canto
- •Flow
Testnets
- •Sepolia
- •Optimism Sepolia
- •Arbitrum Sepolia
- •Base Sepolia
- •Polygon Amoy
- •Avalanche Fuji
- •BSC Testnet
- •And many more...
Quick Reference
For detailed operations, see:
- •Network Operations - Chain info, supported networks
- •Balance Queries - ETH and token balances
- •Transactions - Transaction info, receipts, gas estimation
- •Token Operations - ERC20, ERC721, ERC1155 transfers
- •Smart Contracts - Read/write contract interactions
- •ENS Operations - ENS name resolution
Installation
bash
bun add viem
Basic Usage
typescript
import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';
const client = createPublicClient({
chain: mainnet,
transport: http('https://eth.llamarpc.com')
});
// Get balance
const balance = await client.getBalance({
address: '0x...'
});
// Get block
const block = await client.getBlock();
Common Operations
Get ETH Balance
typescript
import { formatEther } from 'viem';
const balance = await client.getBalance({
address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' // vitalik.eth
});
console.log(formatEther(balance)); // "1234.56789"
Get ERC20 Token Balance
typescript
const balance = await client.readContract({
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
abi: [{
name: 'balanceOf',
type: 'function',
stateMutability: 'view',
inputs: [{ name: 'account', type: 'address' }],
outputs: [{ type: 'uint256' }]
}],
functionName: 'balanceOf',
args: ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045']
});
Resolve ENS Name
typescript
const address = await client.getEnsAddress({
name: 'vitalik.eth'
});
// Returns: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
Get Transaction Details
typescript
const tx = await client.getTransaction({
hash: '0x...'
});
Estimate Gas
typescript
const gas = await client.estimateGas({
to: '0x...',
value: parseEther('0.1')
});
Security Notes
- •Never expose private keys in code or logs
- •Always validate addresses before transactions
- •Use testnets for development and testing
- •Double-check recipient addresses for transfers