Guides contributions to essential-eth, a lightweight Ethereum library. Covers adding utility functions, writing tests, JSDoc conventions, and build workflow. Use when adding features, fixing bugs, or writing new utilities for this codebase.
essential-eth is a minimal, tree-shakeable Ethereum utility library (~43 kB) that serves as a lightweight alternative to ethers.js and web3.js. It uses native bigint instead of BigNumber classes.
src/
├── classes/ # Contract and BaseContract
├── providers/ # JsonRpcProvider, FallthroughProvider, AlchemyProvider
│ └── BaseProvider.ts # Abstract base with all RPC methods
├── utils/ # One file per utility function
│ └── tests/ # Colocated test files
├── conversions/ # Lightweight conversion-only entry point
├── types/ # TypeScript type definitions (Hex, Address, Hash, etc.)
└── index.ts # Barrel exports
src/utils/<function-name>.ts with a single exported function@param, @returns, and @example tagssrc/utils/tests/<function-name>.test.tssrc/index.ts (and src/utils/index-utils.ts if appropriate)import type { BytesLike } from './bytes';
/**
* Brief description of what the function does.
*
* @param input description of parameter
* @returns description of return value
* @example
* ```javascript
* myFunction('0x1234');
* // '0xabcd...'
* ```
*/
export function myFunction(input: BytesLike): string {
// implementation
}
import { describe, expect, it } from 'vitest';
import { myFunction } from './../my-function';
describe('myFunction', () => {
it('should handle hex strings', () => {
expect(myFunction('0x1234')).toBe('expected-output');
});
});
src/utils/, named with kebab-caseinterface not type for object shapes (@typescript-eslint/consistent-type-definitions)import type for type-only imports (@typescript-eslint/consistent-type-imports)console.log -- no-console is set to error@example blocksHex, Address, Hash from src/types/Primitives.types.tsbigint -- never use BigNumber librariessrc/utils/tests/ or src/<module>/test/npm run test (runs vitest + build + eslint)npx vitest runindex, utils, conversionsnpm run build@noble/hashes over heavier crypto librariesWhen adding provider methods, add them to src/providers/BaseProvider.ts. Each method should include JSDoc with comparison lines to ethers.js and web3.js equivalents.
@noble/hashes -- cryptographic hashing (keccak256, sha3)@noble/secp256k1 -- elliptic curve operationsisomorphic-unfetch -- universal fetch for RPC calls