Skip to content

Zod

ABIType exports the core types as Zod schemas from the 'abitype/zod' entrypoint.

Install

Install the Zod peer dependency:

bash
pnpm add zod
pnpm add zod
bash
bun add zod
bun add zod
bash
npm i zod
npm i zod
bash
yarn add zod
yarn add zod

Usage

Import and use schemas:

ts
ts
import { Abi } from 'abitype/zod'
 
const result = await fetch(
'https://api.etherscan.io/api?module=contract&action=getabi&address=0x…'
)
const abi = Abi.parse(result)
Try
ts
import { Abi } from 'abitype/zod'
 
const result = await fetch(
'https://api.etherscan.io/api?module=contract&action=getabi&address=0x…'
)
const abi = Abi.parse(result)
Try

Schemas

ts
ts
import {
Abi,
AbiConstructor,
AbiEvent,
AbiEventParameter,
AbiError,
AbiFallback,
AbiFunction,
AbiParameter,
Address,
AbiReceive,
AbiStateMutability,
SolidityAddress,
SolidityArray,
SolidityArrayWithoutTuple,
SolidityArrayWithTuple,
SolidityBool,
SolidityBytes,
SolidityFunction,
SolidityInt,
SolidityString,
SolidityTuple,
TypedData,
TypedDataDomain,
TypedDataParameter,
TypedDataType,
} from 'abitype/zod'
Try
ts
import {
Abi,
AbiConstructor,
AbiEvent,
AbiEventParameter,
AbiError,
AbiFallback,
AbiFunction,
AbiParameter,
Address,
AbiReceive,
AbiStateMutability,
SolidityAddress,
SolidityArray,
SolidityArrayWithoutTuple,
SolidityArrayWithTuple,
SolidityBool,
SolidityBytes,
SolidityFunction,
SolidityInt,
SolidityString,
SolidityTuple,
TypedData,
TypedDataDomain,
TypedDataParameter,
TypedDataType,
} from 'abitype/zod'
Try

Released under the MIT License.