ethers v6 quickstart
This example shows how to use ethers v6 with Sei. The patterns apply whether you write a Node.js script, a CLI tool, or a browser dApp.Install
tsx (Node 18+):
Read-only provider
Reading chain data
This is the first milestone. It does not need a private key.getBlockNumber() and getTransactionCount() return a number, while getBalance() returns a bigint in wei. To format the balance, use ethers.formatEther().
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 plain JSON-RPC calls, the same reads that the script above performs.Edit and run
Edit and re-run the full ethers code from this page live in the browser. The sandbox uses a real ethers v6JsonRpcProvider that reads Sei Testnet. Its block number and balances therefore do not match the Sei Mainnet reads above:
Browser provider
In a browser context, connect to the user’s injected wallet:Wallet from private key
Use this pattern in scripts and backend services:Sending a transaction
This next step requires a funded account. Get testnet SEI from the faucet.Reading a contract
Writing to a contract
For write operations, pass a signer (a wallet or a browser signer) to the contract constructor:Estimating gas
Listening for events
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