Skip to main content

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

These snippets are TypeScript. To run any of them without a separate build step, use tsx (Node 18+):

Read-only provider

Reading chain data

This is the first milestone. It does not need a private key.
You are done when you see:
The exact numbers are illustrative. Your block number and balance will differ. 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 v6 JsonRpcProvider 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