{"id":15076,"library":"abitype","title":"ABIType: Ethereum ABI TypeScript Types","description":"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.","status":"active","version":"1.2.4","language":"javascript","source_language":"en","source_url":"https://github.com/wevm/abitype","tags":["javascript","abi","eth","ethereum","types","typescript","viem","wagmi","web3"],"install":[{"cmd":"npm install abitype","lang":"bash","label":"npm"},{"cmd":"yarn add abitype","lang":"bash","label":"yarn"},{"cmd":"pnpm add abitype","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for type checking and inference, especially for advanced conditional types and template literal types used extensively by ABIType.","package":"typescript","optional":false},{"reason":"Used for runtime validation of ABIs. It's a peer dependency, allowing users to manage its version.","package":"zod","optional":true}],"imports":[{"note":"This is a type utility, so `import type` is preferred for tree-shaking and clarity, though `import` works at compile-time.","wrong":"import { AbiParametersToPrimitiveTypes } from 'abitype'","symbol":"AbiParametersToPrimitiveTypes","correct":"import type { AbiParametersToPrimitiveTypes } from 'abitype'"},{"note":"ABIType is primarily an ESM package. CommonJS `require()` is not officially supported and may lead to issues, especially with type-only imports.","wrong":"const ExtractAbiFunction = require('abitype').ExtractAbiFunction","symbol":"ExtractAbiFunction","correct":"import type { ExtractAbiFunction } from 'abitype'"},{"note":"Pre-defined ABIs like `erc20Abi` are located in the `abitype/abis` subdirectory to keep the main bundle light.","wrong":"import { erc20Abi } from 'abitype'","symbol":"erc20Abi","correct":"import { erc20Abi } from 'abitype/abis'"},{"note":"`parseAbi` is a runtime utility. While ABIType is heavily type-driven, it also provides runtime functions. The primary export path is correct.","wrong":"import { parseAbi } from 'abitype/runtime'","symbol":"parseAbi","correct":"import { parseAbi } from 'abitype'"}],"quickstart":{"code":"import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction, ExtractAbiFunctionNames } from 'abitype';\nimport { erc20Abi, parseAbi } from 'abitype/abis';\n\n// Example 1: Extracting function names from an ABI\ntype ViewFunctionNames = ExtractAbiFunctionNames<typeof erc20Abi, 'view'>;\n//   ^? type ViewFunctionNames = \"symbol\" | \"name\" | \"allowance\" | \"balanceOf\" | \"decimals\" | \"totalSupply\"\n\n// Example 2: Getting primitive types for a function's inputs\ntype TransferInputTypes = AbiParametersToPrimitiveTypes<\n  ExtractAbiFunction<typeof erc20Abi, 'transfer'>['inputs']\n>;\n//   ^? type TransferInputTypes = readonly [`0x${string}`, bigint]\n\n// Example 3: Parsing a custom ABI string at runtime\nconst customAbi = parseAbi([\n  'function deposit() payable',\n  'event Deposit(address indexed user, uint256 amount)'\n]);\n\nconsole.log(customAbi[0].name); // 'deposit'\nconsole.log(customAbi[1].type); // 'event'\n\n// Example 4: Type-checking a variable against an ABI type\ntype MyCustomAbi = typeof customAbi;\n\n// This will error if the structure doesn't match MyCustomAbi\nconst invalidAbi: MyCustomAbi = [\n  {\n    type: 'function',\n    name: 'withdraw',\n    inputs: [],\n    stateMutability: 'nonpayable',\n    outputs: []\n  }\n];","lang":"typescript","description":"Demonstrates how to extract function names, derive primitive types from ABI parameters, and parse custom ABI strings at runtime for type-safe contract interactions."},"warnings":[{"fix":"Ensure `zod` is updated to `^3.22.0 || ^4.0.0` in your project's `package.json` and reinstall dependencies.","message":"ABIType `v1.1.0` introduced support for Zod `v4`, broadening compatibility. Users migrating from older Zod versions (pre-v3.22) might experience issues if their `zod` peer dependency is not updated accordingly.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"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).","message":"The package is designed for ESM (ECMAScript Modules). Using CommonJS `require()` syntax directly might lead to 'Module not found' or incorrect type inference, especially for type-only imports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade your project's `typescript` version to `5.0.4` or higher.","message":"ABIType relies heavily on advanced TypeScript features. Ensure your `typescript` peer dependency meets the minimum requirement of `>=5.0.4` to avoid compilation errors related to type inference or declaration merging.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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).","message":"Version `1.2.4` fixed a regex issue for Zod identifiers, preventing invalid identifiers (like those containing spaces or starting with numbers) from being accepted. While a fix, it might make previously 'accepted' but invalid ABIs now fail validation.","severity":"gotcha","affected_versions":">=1.2.4"},{"fix":"Always import pre-defined ABIs using `import { abiName } from 'abitype/abis'`.","message":"Pre-defined ABIs (like `erc20Abi`) are located in the `abitype/abis` path, not directly from the main `abitype` export. Attempting to import them from the root might result in undefined symbols.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"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.","cause":"Attempting to import `abitype` using CommonJS `require()` syntax or running an ESM file in a CommonJS context.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'abitype' imported from /path/to/your/file.js"},{"fix":"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]`.","cause":"Mismatch between an ABI type string and the expected primitive TypeScript type. ABIType automatically converts ABI types (e.g., `'uint256'`) to their corresponding TypeScript primitive type (e.g., `bigint`).","error":"Type '\"uint256\"' is not assignable to type '\"string\" | \"number\" | \"boolean\" | \"null\" | \"undefined\" | \"bigint\" | `0x${string}` | `0x${string}`[] | ...'."},{"fix":"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.","cause":"Attempting to access a property that might not be present on a generic ABI type or an improperly typed ABI object. For example, a tuple type might not have a direct `name` property at its root.","error":"Property 'name' does not exist on type 'AbiParameter'."}],"ecosystem":"npm"}