viem Quickstart
This example shows how to use viem with Sei outside of a React context — in a Node.js script, CLI tool, or backend service. For React apps, see wagmi and the frontend guide.Install
tsx (Node 18+):
Public Client
A public client handles all read-only operations.http():
Reading Chain Data
This is the first milestone — it needs no private key.n: getBlockNumber() and getBalance() return bigint, while getTransactionCount() returns a number.
Try It Live
Run these read-only calls against Sei mainnet right now — no install, no private key. They’re the same reads the script above performs, issued straight from your browser.Edit and run
The buttons above issue raw JSON-RPC. To run the full viem code from this page — imports, a public client, several reads — edit and re-run it live in the sandbox below. No install, no wallet, no key:Wallet Client
A wallet client handles signing and broadcasting transactions.http() with custom(window.ethereum) and call walletClient.getAddresses() to get the connected account.
Sending a Transaction
Next step — this requires a funded account; get testnet SEI from the faucet.Reading a Contract
Writing to a Contract
Simulating Before Writing
Estimating Gas
Always useestimateGas rather than hard-coding values. SSTORE costs on Sei are governance-adjustable.
Next Steps
- Python quickstart (web3.py) — the same first steps in Python
- ERC-20 interaction — full token read/write examples
- ERC-721 interaction — NFT ownership, transfers, and approvals
- Pointer contracts — interact with CosmWasm tokens via ERC interfaces
- WebSocket connections — real-time block and event subscriptions