{"id":10852,"library":"ethjs","title":"Ethjs Ethereum Utility Library","description":"Ethjs is a lightweight, highly optimized JavaScript utility library designed for interacting with the Ethereum blockchain. Released in its current stable version 0.4.0 in 2018, it aimed to provide a more modular and async-only alternative to the then-dominant `web3.js` library, featuring `BN.js` for large number arithmetic and a focus on smaller bundle sizes. However, the project has been unmaintained since its last publish nearly eight years ago. Developers should be aware that `ethjs` is effectively abandoned; its GitHub repository explicitly recommends using `ethers.js` instead. Modern Ethereum development typically leverages actively maintained libraries like `ethers.js` or the `@ethereumjs` monorepo, which offer contemporary features such as ESM support, TypeScript definitions, and native JavaScript `BigInt` for handling large numbers, providing a more robust and future-proof development experience.","status":"abandoned","version":"0.4.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/ethjs/ethjs","tags":["javascript","ethereum","events","rpc"],"install":[{"cmd":"npm install ethjs","lang":"bash","label":"npm"},{"cmd":"yarn add ethjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add ethjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for arbitrary-precision integer arithmetic (BigNumbers), which is fundamental for handling Ethereum values like wei, gas, and token amounts. This is an internal dependency implicitly used across the library.","package":"bn.js","optional":false}],"imports":[{"note":"Ethjs is a CommonJS-only library, last published in 2018. ESM `import` statements are not supported directly.","wrong":"import Eth from 'ethjs';","symbol":"Eth","correct":"const Eth = require('ethjs');"},{"note":"`HttpProvider` is a static property of the main `Eth` export. Destructuring from the package is not supported.","wrong":"import { HttpProvider } from 'ethjs'; const provider = new HttpProvider(...);","symbol":"Eth.HttpProvider","correct":"const Eth = require('ethjs'); const provider = new Eth.HttpProvider('https://mainnet.infura.io');"},{"note":"Utility functions like `toWei` are static methods on the main `Eth` export and cannot be imported directly via ES modules syntax.","wrong":"import { toWei } from 'ethjs'; const weiValue = toWei(...);","symbol":"Eth.toWei","correct":"const Eth = require('ethjs'); const weiValue = Eth.toWei(1, 'ether');"}],"quickstart":{"code":"const Eth = require('ethjs');\nconst eth = new Eth(new Eth.HttpProvider('https://ropsten.infura.io'));\n\n// Fetch a block by number using a callback (common in older Node.js libs)\neth.getBlockByNumber(45300, true, (err, block) => {\n  if (err) {\n    console.error('Error fetching block:', err);\n    return;\n  }\n  console.log('Block 45300 data:', block.number.toString(), block.hash);\n});\n\n// Convert ether to wei using Eth.toWei utility\nconst etherValue = Eth.toWei(72, 'ether');\nconsole.log('72 Ether in Wei (BN.js object):', etherValue.toString());\n\n// Interact with a contract using a promise-based API\nconst tokenABI = [{\n  \"constant\": true,\n  \"inputs\": [],\n  \"name\": \"totalSupply\",\n  \"outputs\":[{\"name\": \"\",\"type\": \"uint256\"}],\n  \"payable\": false,\n  \"type\": \"function\"\n}];\n\n// This contract address is an example and may not be valid on Ropsten today\nconst tokenAddress = '0x6e0E0e02377Bc1d90E8a7c21f12BA385C2C35f78';\nconst token = eth.contract(tokenABI).at(tokenAddress);\n\ntoken.totalSupply()\n  .then((totalSupply) => {\n    console.log(`Total supply for token at ${tokenAddress}: ${totalSupply.toString()}`);\n  })\n  .catch(error => {\n    console.error(`Error fetching total supply for token at ${tokenAddress}:`, error);\n  });\n","lang":"javascript","description":"This quickstart demonstrates initializing Ethjs with an HTTP provider, fetching blockchain data using a callback, converting units with a static utility, and interacting with a basic ERC-20 contract using a promise-based API."},"warnings":[{"fix":"Migrate your project to a modern, actively maintained Ethereum library such as `ethers.js` (e.g., `npm install ethers`) or specific `@ethereumjs` packages (e.g., `npm install @ethereumjs/tx`).","message":"The `ethjs` library is effectively unmaintained since its last release (v0.4.0) in 2018. It is strongly recommended to use actively maintained alternatives like `ethers.js` or packages from the `@ethereumjs` monorepo for any new development or migration of existing projects.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"If continuing to use `ethjs`, explicitly manage conversions between `BN.js` objects and other number types. For new projects, switch to libraries that support `BigInt` natively to avoid this impedance mismatch.","message":"Ethjs relies on the `BN.js` library for handling large numbers. Modern JavaScript environments and newer Ethereum libraries have largely transitioned to native `BigInt` for arbitrary-precision integers. Mixing `BN.js` objects with `BigInt` or standard JavaScript numbers can lead to unexpected behavior and errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your project uses `require('ethjs')` for importing. If you need ESM compatibility, you must use a transpiler like Babel or switch to a modern Ethereum library that offers hybrid CJS/ESM builds.","message":"Ethjs is a CommonJS-only library, meaning it can only be imported using `require()` syntax in Node.js environments. It does not provide native ES module (ESM) support (`import`). Attempting to use `import` statements will result in module resolution errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Standardize your async patterns. For callback-based functions, consider wrapping them in Promises (e.g., using `util.promisify`) to maintain a consistent promise-based workflow throughout your application.","message":"Ethjs employs a mixed asynchronous API, with some methods (like `getBlockByNumber`) using Node.js-style callbacks, while others (like contract calls) return Promises. This inconsistency can make error handling and control flow more complex.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const Eth = require('ethjs');`. Ensure `ethjs` is listed in your `package.json` dependencies and installed (`npm install ethjs`).","cause":"Attempting to import `ethjs` using ES module `import` syntax in an environment where only CommonJS `require` is supported, or when `ethjs` is not correctly installed.","error":"Error: Cannot find module 'ethjs' imported from ..."},{"fix":"Ensure `Eth` is imported as the main module (`const Eth = require('ethjs');`) and static methods like `toWei` are called directly on `Eth` (e.g., `Eth.toWei(value, unit)`). Do not attempt `const { toWei } = require('ethjs');`.","cause":"Incorrectly destructuring or accessing static methods, or calling a method on an instance when it should be called statically.","error":"TypeError: Eth.toWei is not a function"}],"ecosystem":"npm"}