{"id":10851,"library":"ethereumjs-util","title":"EthereumJS Utilities","description":"EthereumJS Util (currently at stable version 10.1.1, with version 7.1.5 referenced in the prompt as a specific historical point) is a foundational utility library within the larger EthereumJS ecosystem. It provides a comprehensive collection of low-level, high-performance functions essential for interacting with the Ethereum blockchain, including cryptographic hashing (e.g., Keccak256), RLP encoding/decoding, address validation (like checksum addresses), byte array manipulation, and elliptic curve operations. It is actively maintained as part of the EthereumJS monorepo, with regular minor and patch releases, and major versions typically aligning with significant Ethereum protocol updates or fundamental architectural shifts (e.g., ESM-only in v7). Its key differentiators include its tight integration and alignment with official Ethereum specifications, extensive TypeScript support, and being a reference implementation for various Ethereum primitives. It re-exports critical libraries like `BN.js` for arbitrary-precision arithmetic and `rlp` for Recursive Length Prefix encoding, making it a central point for many Ethereum-related development tasks.","status":"active","version":"7.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/ethereumjs/ethereumjs-monorepo","tags":["javascript","ethereum","utilities","utils","typescript"],"install":[{"cmd":"npm install ethereumjs-util","lang":"bash","label":"npm"},{"cmd":"yarn add ethereumjs-util","lang":"bash","label":"yarn"},{"cmd":"pnpm add ethereumjs-util","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Arbitrary-precision arithmetic, re-exported for convenience.","package":"bn.js","optional":false},{"reason":"Recursive Length Prefix encoding/decoding, re-exported for convenience.","package":"rlp","optional":false},{"reason":"Underlying elliptic curve cryptography operations, updated to v2 in 10.1.1.","package":"@noble/curves","optional":false},{"reason":"Cryptographic hashing primitives, updated to v2 in 10.1.1.","package":"@noble/hashes","optional":false}],"imports":[{"note":"Since v7, this package is ESM-only. CommonJS 'require' syntax will not work.","wrong":"const { isValidChecksumAddress } = require('ethereumjs-util')","symbol":"isValidChecksumAddress","correct":"import { isValidChecksumAddress } from 'ethereumjs-util'"},{"note":"BN.js is re-exported directly from ethereumjs-util for convenience. It is not the default export of BN.js itself.","wrong":"import BN from 'bn.js'","symbol":"BN","correct":"import { BN } from 'ethereumjs-util'"},{"note":"Functionality from ethjs-util has been internalized since v7.1.3; import directly from 'ethereumjs-util'.","wrong":"import { stripHexPrefix } from 'ethjs-util'","symbol":"stripHexPrefix","correct":"import { stripHexPrefix } from 'ethereumjs-util'"},{"note":"The rlp library is re-exported by ethereumjs-util for direct access.","symbol":"rlp","correct":"import { rlp } from 'ethereumjs-util'"}],"quickstart":{"code":"import assert from 'assert';\nimport { isValidChecksumAddress, unpadBuffer, BN } from 'ethereumjs-util';\n\n// Example 1: Validate an Ethereum checksum address\nconst address = '0x2F015C60E0be116B1f0CD534704Db9c92118FB6A';\nconst isValid = isValidChecksumAddress(address);\nconsole.log(`Address ${address} is valid: ${isValid}`);\nassert.ok(isValid, 'Checksum address validation failed');\n\n// Example 2: Unpad a Buffer\nconst paddedBuffer = Buffer.from('000000006600', 'hex');\nconst unpaddedBuffer = unpadBuffer(paddedBuffer);\nconsole.log(`Unpadded buffer: ${unpaddedBuffer.toString('hex')}`);\nassert.ok(unpaddedBuffer.equals(Buffer.from('6600', 'hex')), 'Buffer unpadding failed');\n\n// Example 3: Perform arithmetic with BN.js\nconst bn1 = new BN('dead', 16); // Hexadecimal 'dead'\nconst bn2 = new BN('101010', 2); // Binary '101010'\nconst sum = bn1.add(bn2);\nconst expectedValue = new BN(57047); // Decimal equivalent of 'dead' (57005) + '101010' (42) = 57047\nconsole.log(`BN sum: ${sum.toString()}`);\nassert.ok(sum.eqn(expectedValue), 'BN arithmetic failed');\n\nconsole.log('All quickstart assertions passed!');","lang":"typescript","description":"This quickstart demonstrates basic usage, including Ethereum checksum address validation, byte buffer manipulation, and arbitrary-precision arithmetic using the re-exported BN.js library."},"warnings":[{"fix":"Migrate your codebase to use ES module `import` syntax. For Node.js, ensure your package.json specifies `\"type\": \"module\"` or use a `.mjs` extension for files importing this package.","message":"Starting with version 7.0.0, `ethereumjs-util` is an ESM-only package. Direct `require()` statements will result in runtime errors. Projects must use ES module syntax (`import`) and configure their build tools accordingly.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Upgrade your Node.js environment to version 20 or higher to maintain compatibility and receive updates.","message":"Node.js 18 support has been deprecated across the EthereumJS monorepo, including `@ethereumjs/util`. The minimum required Node.js version is now 20.","severity":"breaking","affected_versions":">=10.1.1"},{"fix":"Review your usage of `createBinaryObject` and replace it with alternative, actively supported methods for binary object creation or manipulation. The documentation in the `src/object.ts` file or API docs might provide alternatives.","message":"The `createBinaryObject` helper function within the `object` module (src/object.ts) has been marked as deprecated.","severity":"deprecated","affected_versions":">=7.1.3"},{"fix":"Continue importing these functions (e.g., `stripHexPrefix`) directly from `ethereumjs-util`. Be aware that their underlying implementation is now managed by EthereumJS.","message":"Functions originally from the `ethjs-util` package have been internalized into `ethereumjs-util` since v7.1.3. While their API remains largely the same, this internalization means that subtle behavioral changes or future deprecations might occur independently of the original `ethjs-util` library.","severity":"gotcha","affected_versions":">=7.1.3"},{"fix":"If your project directly or indirectly relies on specific versions or behaviors of `@noble/curves` or `@noble/hashes`, review their v2 changelogs for potential breaking changes and update your code accordingly.","message":"Recent updates in version 10.1.1 include dependency bumps for `@noble/curves` and `@noble/hashes` to v2. While these are indirect dependencies for most users, direct interaction with these libraries or reliance on their previous versions' specific behaviors could lead to breaking changes.","severity":"breaking","affected_versions":">=10.1.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { Name } = require('ethereumjs-util')` to `import { Name } from 'ethereumjs-util'`. Ensure your project's `package.json` has `\"type\": \"module\"` or that files using `import` have a `.mjs` extension.","cause":"Attempting to use CommonJS `require()` syntax in an ES module context or with an ES module library.","error":"ReferenceError: require is not defined"},{"fix":"Ensure that hex string inputs are properly formatted, typically with a '0x' prefix and valid hexadecimal characters. If an empty value is intended, pass an empty Buffer or Uint8Array instead of an empty string for byte-related functions.","cause":"Providing an empty string or incorrectly formatted string where a hex-prefixed hex string is expected by a utility function (e.g., `toBuffer`, `bufferToHex`).","error":"TypeError: Invalid hex string (0x<length 0>)"},{"fix":"Double-check the Ethereum address for typos or incorrect casing. Ensure it matches the EIP-55 checksum standard. If you intend to work with non-checksummed addresses, use functions that do not perform checksum validation or convert to lowercase before validation if appropriate for your use case.","cause":"The provided Ethereum address does not pass the EIP-55 checksum validation.","error":"Error: Invalid checksum address"}],"ecosystem":"npm"}