ABIType

Strict TypeScript types for Ethereum ABIs

README



ABIType logo


Version Downloads per month MIT License Best of JS


Strict TypeScript types for Ethereum ABIs. ABIType provides utilities and type definitions for ABI properties and values, covering the Contract ABI Specification, as well as EIP-712 Typed Data.

  1. ```ts
  2. import { ExtractAbiFunctions } from 'abitype'
  3. import { erc20Abi } from 'abitype/test'

  4. type FunctionNames = ExtractAbiFunctionNames<typeof erc20Abi, 'view'>
  5. //   ^? type FunctionNames = "symbol" | "name" | "allowance" | "balanceOf" | "decimals" | "totalSupply"

  6. type TransferInputTypes = AbiParametersToPrimitiveTypes<
  7.   // ^? type TransferInputTypes = readonly [`0x${string}`, bigint]
  8.   ExtractAbiFunction<typeof erc20Abi, 'transfer'>['inputs']
  9. >
  10. ```

Works great for adding blazing fast autocomplete and type checking to functions, variables, or your own types. No need to generate types with third-party tools – just use your ABI and let TypeScript do the rest!

TL;DR


ABIType might be a good option for your project if:

- You want to typecheck your ABIs or EIP-712 Typed Data.
- You want to add type inference and autocomplete to your library based on user-provided ABIs or EIP-712 Typed Data, like wagmi and viem.
- You need to convert ABI types (e.g.'string') to TypeScript types (e.g. string) or other type transformations.
- You need to validate ABIs at runtime (e.g. after fetching from external resource).
- You don’t want to set up a build process to generate types (e.g. TypeChain).

Install


  1. ```fish
  2. npm i abitype
  3. yarn add abitype
  4. pnpm add abitype
  5. ```

Documentation


For full documentation, visit abitype.dev.

Community


If you have questions or need help, reach out to the community at the ABIType GitHub Discussions.

Sponsor


If you find ABIType useful, please consider supporting development on GitHub Sponsors or sending crypto towagmi-dev.eth. Thank you 🙏

Contributing


If you're interested in contributing to ABIType, please read our contributing docsbefore submitting a pull request.