Skip to main content

Documentation Index

Fetch the complete documentation index at: https://seilabs-docs-evm-reference-and-sei-js-examples.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

ethers v6 Quickstart

This example covers ethers v6 with Sei. The patterns apply whether you are writing a Node.js script, a CLI tool, or a browser app.

Install

npm install ethers

Read-Only Provider

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://evm-rpc.sei-apis.com');

Reading Chain Data

const blockNumber = await provider.getBlockNumber();

const block = await provider.getBlock('latest');

const balance = await provider.getBalance('0xYourAddress');

const nonce = await provider.getTransactionCount('0xYourAddress');

Browser Provider

In a browser context, connect to the user’s injected wallet:
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const address = await signer.getAddress();

Wallet from Private Key

For scripts and backend services:
const wallet = new ethers.Wallet('0xYourPrivateKey', provider);

Sending a Transaction

const tx = await wallet.sendTransaction({
  to: '0xRecipient',
  value: ethers.parseEther('1'),
});

const receipt = await tx.wait();
// receipt is final immediately — Sei has instant finality

Reading a Contract

const abi = ['function balanceOf(address owner) view returns (uint256)'];
const contract = new ethers.Contract('0xTokenAddress', abi, provider);

const balance = await contract.balanceOf('0xYourAddress');

Writing to a Contract

Pass a signer (wallet or browser signer) to the contract constructor for write operations:
const contract = new ethers.Contract('0xTokenAddress', abi, wallet);

const tx = await contract.transfer('0xRecipient', 1_000_000n);
const receipt = await tx.wait();

Estimating Gas

const gas = await provider.estimateGas({
  from: wallet.address,
  to: '0xContractAddress',
  data: '0xCalldata',
});

Listening for Events

contract.on('Transfer', (from, to, value) => {
  console.log('Transfer:', { from, to, value });
});

// Stop listening
contract.off('Transfer');

Next Steps