ABIType is a TypeScript-first library providing strict type definitions and utilities for Ethereum ABIs (Application Binary Interfaces) and EIP-712 Typed Data. It enables developers to achieve compile-time type-checking and inference for contract interactions without requiring external code generation tools. The current stable version is 1.2.4, with frequent patch and minor releases addressing bug fixes, performance improvements, and adding experimental features like named tuple support. Its primary differentiator is its deep integration with TypeScript's type system to convert ABI types (e.g., 'string') directly into TypeScript types (e.g., `string` or `0x${string}`) for enhanced developer experience, widely adopted by prominent libraries such as Wagmi and Viem. It also offers runtime validation capabilities for ABIs.
npm install abitypeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to extract function names, derive primitive types from ABI parameters, and parse custom ABI strings at runtime for type-safe contract interactions.
Ensure `zod` is updated to `^3.22.0 || ^4.0.0` in your project's `package.json` and reinstall dependencies.
Use `import` statements for all imports. If running in Node.js, ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or `.mjs` file extension).
Upgrade your project's `typescript` version to `5.0.4` or higher.
Review any custom ABIs that previously worked but might contain non-standard or invalid Zod identifiers. Ensure identifiers conform to typical programming naming conventions (e.g., alphanumeric, starting with a letter or underscore).
Always import pre-defined ABIs using `import { abiName } from 'abitype/abis'`.Ensure your Node.js project is configured for ESM (`"type": "module"` in `package.json` or `.mjs` extension) and use `import` statements. If you absolutely must use CommonJS, consider dynamic `import('abitype')` within an `async` function, but this is not the intended usage.Ensure you are using the correct `AbiParametersToPrimitiveTypes` or similar utility to transform the ABI type string into its TypeScript equivalent before assigning or comparing. For example, `AbiParametersToPrimitiveTypes<['uint256']>['inputs']` would resolve to `[bigint]`.
Use ABIType's specific type utilities like `ExtractAbiFunction` or `ExtractAbiEvent` to narrow down the type of an ABI item, which will then expose properties like `name`, `inputs`, or `outputs` with correct type safety. Ensure your ABI structure is valid according to the Solidity ABI specification.