viem quickstart
This example shows how to use viem with Sei outside a React context: in a Node.js script, a CLI tool, or a backend service. For React dApps, 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 does not need a private key.n: getBlockNumber() and getBalance() return a bigint, while getTransactionCount() returns a number.
Try it live
Run these read-only calls against Sei Mainnet. You do not need to install anything or use a private key. They are the same reads that the script above performs, sent directly from your browser.Edit and run
The buttons above send raw JSON-RPC requests. The sandbox below runs the full viem code from this page: imports, a public client, and several reads. You can edit and re-run it live. You do not need to install anything, connect a wallet, or use a key. The sandbox reads Sei Testnet, so its block number and balances do not match the Sei Mainnet reads above:Wallet client
A wallet client handles signing and broadcasting transactions.http() with custom(window.ethereum). Then call walletClient.getAddresses() to get the connected account.
Sending a transaction
This next step requires a funded account. Get testnet SEI from the faucet.Reading a contract
Writing to a contract
Simulating before writing
Estimating gas
Always useestimateGas instead of hard-coded values. Governance can adjust SSTORE costs on Sei.
Next steps
- Python quickstart (web3.py): the same first steps in Python
- ERC-20 interaction: full token read and write examples
- ERC-721 interaction: NFT ownership, transfers, and approvals
- Pointer contracts: interact with CosmWasm tokens through ERC interfaces
- WebSocket connections: real-time block and event subscriptions