Skip to content

ABITypeABIType

VersionVersionDownloads per monthDownloads per monthMIT LicenseMIT LicenseGitHub Repo starsGitHub Repo starsBest of JSBest 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.

ts
ts
import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype'
import { erc20Abi } from 'abitype/abis'
 
type TransferInputTypes = AbiParametersToPrimitiveTypes<
type TransferInputTypes = readonly [`0x${string}`, bigint]
ExtractAbiFunction<typeof erc20Abi, 'transfer'>['inputs']
>
Try
ts
import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype'
import { erc20Abi } from 'abitype/abis'
 
type TransferInputTypes = AbiParametersToPrimitiveTypes<
type TransferInputTypes = readonly [`0x${string}`, bigint]
ExtractAbiFunction<typeof erc20Abi, 'transfer'>['inputs']
>
Try

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

Read the Getting Started guide to learn more how to use ABIType.

bash
pnpm add abitype
pnpm add abitype
bash
bun add abitype
bun add abitype
bash
npm i abitype
npm i abitype
bash
yarn add abitype
yarn add abitype

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

Community

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

Released under the MIT License.