AgentSkillsCN

essential-eth-api

指导Essential-eth的使用——这是一款轻量级的以太坊实用程序库(相较于ethers.js/web3.js,其体积仅为43KB)。涵盖提供者、合约、转换、哈希算法,以及地址相关的实用工具。当你需要在代码中导入essential-eth时,可使用此技能。

SKILL.md
--- frontmatter
name: essential-eth-api
description: Guides usage of essential-eth, a lightweight Ethereum utility library (43 kB alternative to ethers.js/web3.js). Covers providers, contracts, conversions, hashing, and address utilities. Use when writing code that imports from essential-eth.

essential-eth

A tree-shakeable Ethereum library using native bigint (no BigNumber). Minimal alternative to ethers.js and web3.js.

Entry Points

  • essential-eth -- full library with providers, contracts, and utilities
  • essential-eth/utils -- utilities without providers (smaller)
  • essential-eth/conversions -- unit conversions only (~1.2 kB)

Key Differences from ethers.js

  • Uses native bigint instead of BigNumber
  • Read-only -- no signer or wallet support
  • ~10x smaller bundle size
  • Tree-shakeable with multiple entry points

Finding the API

To see all available exports, read node_modules/essential-eth/dist/index.d.ts. This is the generated type declarations file and is always up to date.

For source code and JSDoc examples, read files in node_modules/essential-eth/dist/. Each function includes @example blocks showing usage.

Quick Reference

Providers: JsonRpcProvider, FallthroughProvider, AlchemyProvider -- create with an RPC URL, then call methods like getBalance, getBlock, call, getLogs, resolveName.

Contracts: new Contract(address, jsonAbi, provider) -- ABI methods become async functions on the instance. Read-only.

Conversions: etherToWei, weiToEther, etherToGwei, gweiToEther, formatUnits, parseUnits -- accept string | number | bigint.

Hashing: keccak256, solidityKeccak256, id, hashMessage, namehash.

Addresses: isAddress, getAddress, toChecksumAddress, computeAddress, computePublicKey.

ABI: encodeFunctionData, decodeFunctionResult, decodeEventLog.

Bytes: arrayify, hexlify, concat, hexZeroPad, isHexString, and more.