Skip to content
Skillv1.0.0

ethers-js

Interact with Ethereum and EVM blockchains using ethers.js. Use when a user asks to connect to Ethereum, read blockchain data, send transactions, interact with smart contracts, or build a dApp fronten

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/ethers-js/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill ethers-js. Copyright stays with the author (Apache-2.0).

ethers.js

Overview

ethers.js is the most popular library for interacting with Ethereum and EVM-compatible blockchains (Polygon, Arbitrum, Base, BSC). It handles wallet connections, contract interactions, transaction signing, and blockchain queries.

Instructions

Step 1: Setup

npm install ethers

Step 2: Read Blockchain Data

// lib/ethereum.ts — Read-only blockchain access
import { ethers } from 'ethers'

// Connect to Ethereum (read-only)
const provider = new ethers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY')

// Get ETH balance
const balance = await provider.getBalance('0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18')
console.log(ethers.formatEther(balance))    // "1.234"

// Get current block
const block = await provider.getBlockNumber()

// Get transaction
const tx = await provider.getTransaction('0x...')

Step 3: Interact with Smart Contracts

// Read from a contract (no wallet needed)
const USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
const ERC20_ABI = [
  'function balanceOf(address) view returns (uint256)',
  'function decimals() view returns (uint8)',
  'function symbol() view returns (string)',
  'function transfer(address to, uint256 amount) returns (bool)',
]

const usdc = new ethers.Contract(USDC_ADDRESS, ERC20_ABI, provider)
const balance = await usdc.balanceOf('0x...')
const decimals = await usdc.decimals()
console.log(ethers.formatUnits(balance, decimals))    // "1000.00"

Step 4: Send Transactions

// Write to blockchain (needs wallet)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
const usdcWithSigner = usdc.connect(wallet)

// Transfer USDC
const tx = await usdcWithSigner.transfer(
  '0xRecipient...',
  ethers.parseUnits('100', 6)    // 100 USDC (6 decimals)
)
await tx.wait()    // wait for confirmation
console.log('TX hash:', tx.hash)

Step 5: Frontend (MetaMask)

// Connect to user's MetaMask wallet
const provider = new ethers.BrowserProvider(window.ethereum)
const signer = await provider.getSigner()
const address = await signer.getAddress()

Guidelines

  • ethers.js v6 is current — v5 syntax is different (avoid mixing).
  • Never expose private keys in frontend code — use MetaMask/WalletConnect for user wallets.
  • Use Alchemy, Infura, or QuickNode as RPC providers — don't run your own node unless needed.
  • Always await tx.wait() before confirming success — tx.hash alone doesn't mean it's mined.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-ethers-js/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-ethers-js.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-ethers-js",
  "kind": "skill",
  "name": "ethers-js",
  "description": "Interact with Ethereum and EVM blockchains using ethers.js. Use when a user asks to connect to Ethereum, read blockchain data, send transactions, interact with smart contracts, or build a dApp frontend.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "ethers",
      "ethereum",
      "web3",
      "blockchain",
      "smart-contracts",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Interact with Ethereum and EVM blockchains using ethers.js. Use when a user asks to connect to Ethereum, read blockchain data, send transactions, interact with smart contracts, or build a dApp frontend."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/ethers-js/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/ethers-js/SKILL.md",
      "key": "terminalskills/skills/skills/ethers-js/SKILL.md"
    },
    "compatibility": "Node.js, browsers",
    "license": "Apache-2.0"
  },
  "instructions": "# ethers.js\n\n## Overview\n\nethers.js is the most popular library for interacting with Ethereum and EVM-compatible blockchains (Polygon, Arbitrum, Base, BSC). It handles wallet connections, contract interactions, transaction signing, and blockchain queries.\n\n## Instructions\n\n### Step 1: Setup\n\n```bash\nnpm install ethers\n```\n\n### Step 2: Read Blockchain Data\n\n```typescript\n// lib/ethereum.ts — Read-only blockchain access\nimport { ethers } from 'ethers'\n\n// Connect to Ethereum (read-only)\nconst provider = new ethers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY')\n\n// Get ETH balan",
  "cost": {
    "context_tokens": 632
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-ethers-js/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.

ethers-js - Skill - OpenSmartRoute