Skip to content

Utilities

Utility types for working with ABIs and EIP-712 Typed Data.

AbiParameterToPrimitiveType

Converts AbiParameter to corresponding TypeScript primitive type.

NameDescriptionType
TAbiParameterParameter to convert to TypeScript representation.AbiParameter
TAbiParameterKindKind to narrow by parameter type.AbiParameterKind (optional)
returnsTypeScript primitive type.TType (inferred)

Example

import { 
type AbiParameterToPrimitiveType<TAbiParameter extends AbiParameter | { name: string; type: unknown; }, TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = TAbiParameter["type"] extends AbiBasicType ? AbiTypeToPrimitiveType<TAbiParameter["type"], TAbiParameterKind> : TAbiParameter extends { ...; } ? AbiComponentsToPrimitiveType<...> : MaybeExtractArrayParameterType<...> extends [...] ? AbiArrayToPrimitiveType<...> : TAbiParameter extends { ...; } ? TAbiParameter["components"] : unknown

Converts AbiParameter to corresponding TypeScript primitive type.

AbiParameterToPrimitiveType
} from 'abitype'
type
type Result = `0x${string}`
Result
=
type AbiParameterToPrimitiveType<TAbiParameter extends AbiParameter | { name: string; type: unknown; }, TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = TAbiParameter["type"] extends AbiBasicType ? AbiTypeToPrimitiveType<TAbiParameter["type"], TAbiParameterKind> : TAbiParameter extends { ...; } ? AbiComponentsToPrimitiveType<...> : MaybeExtractArrayParameterType<...> extends [...] ? AbiArrayToPrimitiveType<...> : TAbiParameter extends { ...; } ? TAbiParameter["components"] : unknown

Converts AbiParameter to corresponding TypeScript primitive type.

AbiParameterToPrimitiveType
<{
name: "owner"
name
: 'owner'
type: "address"
type
: 'address'
}>

AbiParametersToPrimitiveTypes

Converts array of AbiParameter to corresponding TypeScript primitive types.

NameDescriptionType
TAbiParametersParameters to convert to TypeScript representations.readonly AbiParameter[]
TAbiParameterKindKind to narrow by parameter type.AbiParameterKind (optional)
returnsTypeScript primitive types.TType[] (inferred)

Example

import { 
type AbiParametersToPrimitiveTypes<TAbiParameters extends readonly AbiParameter[], TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = { [K in keyof { [K in keyof TAbiParameters]: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>; }]: { [K in keyof TAbiParameters]: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>; }[K]; }

Converts array of AbiParameter to corresponding TypeScript primitive types.

AbiParametersToPrimitiveTypes
} from 'abitype'
type
type Result = [`0x${string}`, bigint]
Result
=
type AbiParametersToPrimitiveTypes<TAbiParameters extends readonly AbiParameter[], TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = { [K in keyof { [K in keyof TAbiParameters]: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>; }]: { [K in keyof TAbiParameters]: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind>; }[K]; }

Converts array of AbiParameter to corresponding TypeScript primitive types.

AbiParametersToPrimitiveTypes
<
[ {
name: "to"
name
: 'to';
type: "address"
type
: 'address'; },
{
name: "tokenId"
name
: 'tokenId';
type: "uint256"
type
: 'uint256'; },
] >

AbiTypeToPrimitiveType

Converts AbiType to corresponding TypeScript primitive type.

NameDescriptionType
TAbiTypeABI type to convert to TypeScript representation.AbiType
TAbiParameterKindKind to narrow by parameter type.AbiParameterKind (optional)
returnsTypeScript primitive type.TType (inferred)

Example

import { 
type AbiTypeToPrimitiveType<TAbiType extends AbiType, TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = TAbiType extends "bytes" | "bytes1" | "bytes2" | "bytes3" | "bytes4" | "bytes5" | "bytes6" | "bytes7" | "bytes8" | "bytes9" | "bytes10" | "bytes11" | "bytes12" | ... 19 more ... | "bytes32" ? PrimitiveTypeLookup[TAbiType][TAbiParameterKind] : PrimitiveTypeLookup[TAbiType]

Converts AbiType to corresponding TypeScript primitive type.

Does not include full array or tuple conversion. Use AbiParameterToPrimitiveType to fully convert arrays and tuples.

AbiTypeToPrimitiveType
} from 'abitype'
type
type Result = `0x${string}`
Result
=
type AbiTypeToPrimitiveType<TAbiType extends AbiType, TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = TAbiType extends "bytes" | "bytes1" | "bytes2" | "bytes3" | "bytes4" | "bytes5" | "bytes6" | "bytes7" | "bytes8" | "bytes9" | "bytes10" | "bytes11" | "bytes12" | ... 19 more ... | "bytes32" ? PrimitiveTypeLookup[TAbiType][TAbiParameterKind] : PrimitiveTypeLookup[TAbiType]

Converts AbiType to corresponding TypeScript primitive type.

Does not include full array or tuple conversion. Use AbiParameterToPrimitiveType to fully convert arrays and tuples.

AbiTypeToPrimitiveType
<'address'>

ExtractAbiError

Extracts AbiError with name from Abi.

NameDescriptionType
TAbiABI.Abi
TErrorNameName of error.string (inferred)
returnsABI Error.AbiError

Example

import { 
type ExtractAbiError<TAbi extends Abi, TErrorName extends ExtractAbiErrorNames<TAbi>> = Extract<TAbi[number], { type: "error"; }> extends { name: TErrorName; } ? { name: TErrorName; } & Extract<TAbi[number], { type: "error"; }> : never

Extracts AbiError with name from Abi.

ExtractAbiError
} from 'abitype'
const
const abi: readonly [{ readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
= [
{
name: "BarError"
name
: 'BarError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
{
name: "FooError"
name
: 'FooError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
] as
type const = readonly [{ readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }]
const
type
type Result = { readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }
Result
=
type ExtractAbiError<TAbi extends Abi, TErrorName extends ExtractAbiErrorNames<TAbi>> = Extract<TAbi[number], { type: "error"; }> extends { name: TErrorName; } ? { name: TErrorName; } & Extract<TAbi[number], { type: "error"; }> : never

Extracts AbiError with name from Abi.

ExtractAbiError
<typeof
const abi: readonly [{ readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
, 'FooError'>

ExtractAbiErrorNames

Extracts all AbiError names from Abi.

NameDescriptionType
TAbiABI.Abi
returnsABI Error names.string (inferred)

Example

import { 
type ExtractAbiErrorNames<TAbi extends Abi> = Extract<TAbi[number], { type: "error"; }>["name"]

Extracts all AbiError names from Abi.

ExtractAbiErrorNames
} from 'abitype'
const
const abi: readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
= [
{
name: "FooError"
name
: 'FooError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
{
name: "BarError"
name
: 'BarError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
] as
type const = readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
const
type
type Result = "FooError" | "BarError"
Result
=
type ExtractAbiErrorNames<TAbi extends Abi> = Extract<TAbi[number], { type: "error"; }>["name"]

Extracts all AbiError names from Abi.

ExtractAbiErrorNames
<typeof
const abi: readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
>

ExtractAbiErrors

Extracts all AbiError types from Abi.

NameDescriptionType
TAbiABI.Abi
returnsABI Errors.AbiError (union)

Example

import { 
type ExtractAbiErrors<TAbi extends Abi> = TAbi[number] extends { type: 'error'; } ? TAbi[number] : never

Extracts all AbiError types from Abi.

ExtractAbiErrors
} from 'abitype'
const
const abi: readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
= [
{
name: "FooError"
name
: 'FooError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
{
name: "BarError"
name
: 'BarError',
type: "error"
type
: 'error',
inputs: readonly []
inputs
: [] },
] as
type const = readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
const
type
type Result = { readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; } | { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }
Result
=
type ExtractAbiErrors<TAbi extends Abi> = TAbi[number] extends { type: 'error'; } ? TAbi[number] : never

Extracts all AbiError types from Abi.

ExtractAbiErrors
<typeof
const abi: readonly [{ readonly name: "FooError"; readonly type: "error"; readonly inputs: readonly []; }, { readonly name: "BarError"; readonly type: "error"; readonly inputs: readonly []; }]
abi
>

ExtractAbiEvent

Extracts AbiEvent with name from Abi.

NameDescriptionType
TAbiABI.Abi
TEventNameName of event.string (inferred)
returnsABI Event.AbiEvent

Example

import { 
type ExtractAbiEvent<TAbi extends Abi, TEventName extends ExtractAbiEventNames<TAbi>> = Extract<TAbi[number], { type: "event"; }> extends { name: TEventName; } ? { name: TEventName; } & Extract<TAbi[number], { type: "event"; }> : never

Extracts AbiEvent with name from Abi.

ExtractAbiEvent
} from 'abitype'
const
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
= [
{
name: "Approval"
name
: 'Approval',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "approved"
name
: 'approved',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, {
name: "Transfer"
name
: 'Transfer',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "from"; readonly type: "address"; readonly indexed: true; }, { readonly name: "to"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, ] as
type const = readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
const
type
type Result = { readonly name: "Transfer"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "from"; readonly type: "address"; readonly indexed: true; }, { readonly name: "to"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }
Result
=
type ExtractAbiEvent<TAbi extends Abi, TEventName extends ExtractAbiEventNames<TAbi>> = Extract<TAbi[number], { type: "event"; }> extends { name: TEventName; } ? { name: TEventName; } & Extract<TAbi[number], { type: "event"; }> : never

Extracts AbiEvent with name from Abi.

ExtractAbiEvent
<typeof
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
, 'Transfer'>

ExtractAbiEventNames

Extracts all AbiEvent names from Abi.

NameDescriptionType
TAbiABI.Abi
returnsABI Error names.string (inferred)

Example

import { 
type ExtractAbiEventNames<TAbi extends Abi> = Extract<TAbi[number], { type: "event"; }>["name"]

Extracts all AbiEvent names from Abi.

ExtractAbiEventNames
} from 'abitype'
const
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
= [
{
name: "Approval"
name
: 'Approval',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "approved"
name
: 'approved',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, {
name: "Transfer"
name
: 'Transfer',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "from"; readonly type: "address"; readonly indexed: true; }, { readonly name: "to"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, ] as
type const = readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
const
type
type Result = "Approval" | "Transfer"
Result
=
type ExtractAbiEventNames<TAbi extends Abi> = Extract<TAbi[number], { type: "event"; }>["name"]

Extracts all AbiEvent names from Abi.

ExtractAbiEventNames
<typeof
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
>

ExtractAbiEvents

Extracts all AbiEvent types from Abi.

NameDescriptionType
TAbiABI.Abi
returnsABI Events.AbiEvent (union)

Example

import { 
type ExtractAbiEvents<TAbi extends Abi> = TAbi[number] extends { type: 'event'; } ? TAbi[number] : never

Extracts all AbiEvent types from Abi.

ExtractAbiEvents
} from 'abitype'
const
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
= [
{
name: "Approval"
name
: 'Approval',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "approved"
name
: 'approved',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, {
name: "Transfer"
name
: 'Transfer',
type: "event"
type
: 'event',
anonymous: false
anonymous
: false,
inputs: readonly [{ readonly name: "from"; readonly type: "address"; readonly indexed: true; }, { readonly name: "to"; readonly type: "address"; readonly indexed: true; }, { readonly name: "tokenId"; readonly type: "uint256"; readonly indexed: true; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address',
indexed: true
indexed
: true },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256',
indexed: true
indexed
: true },
], }, ] as
type const = readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
const
type
type Result = { readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; } | { ...; }
Result
=
type ExtractAbiEvents<TAbi extends Abi> = TAbi[number] extends { type: 'event'; } ? TAbi[number] : never

Extracts all AbiEvent types from Abi.

ExtractAbiEvents
<typeof
const abi: readonly [{ readonly name: "Approval"; readonly type: "event"; readonly anonymous: false; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; readonly indexed: true; }, { readonly name: "approved"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }, { ...; }]
abi
>

ExtractAbiFunction

Extracts AbiFunction with name from Abi.

NameDescriptionType
TAbiABI.Abi
TFunctionNameName of function.string (inferred)
TAbiStateMutabilityABI state mutability.AbiStateMutability (optional)
returnsABI Function.AbiFunction

Example

import { 
type ExtractAbiFunction<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi, AbiStateMutability>, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }> extends { name: TFunctionName; } ? { name: TFunctionName; } & Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }> : never

Extracts AbiFunction with name from Abi.

ExtractAbiFunction
} from 'abitype'
const
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
= [
{
name: "balanceOf"
name
: 'balanceOf',
type: "function"
type
: 'function',
stateMutability: "view"
stateMutability
: 'view',
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]
inputs
: [{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address' }],
outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]
outputs
: [{
name: "balance"
name
: 'balance',
type: "uint256"
type
: 'uint256' }],
}, {
name: "safeTransferFrom"
name
: 'safeTransferFrom',
type: "function"
type
: 'function',
stateMutability: "nonpayable"
stateMutability
: 'nonpayable',
inputs: readonly [{ readonly name: "from"; readonly type: "address"; }, { readonly name: "to"; readonly type: "address"; }, { readonly name: "tokenId"; readonly type: "uint256"; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address' },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address' },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256' },
],
outputs: readonly []
outputs
: [],
}, ] as
type const = readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
const
type
type Result = { readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }
Result
=
type ExtractAbiFunction<TAbi extends Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi, AbiStateMutability>, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }> extends { name: TFunctionName; } ? { name: TFunctionName; } & Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }> : never

Extracts AbiFunction with name from Abi.

ExtractAbiFunction
<typeof
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
, 'balanceOf'>

ExtractAbiFunctionNames

Extracts all AbiFunction names from Abi.

NameDescriptionType
TAbiABI.Abi
TAbiStateMutabilityABI state mutability.AbiStateMutability (optional)
returnsABI Event names.string (inferred)

Example

import { 
type ExtractAbiFunctionNames<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }>["name"]

Extracts all AbiFunction names from Abi.

ExtractAbiFunctionNames
} from 'abitype'
const
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
= [
{
name: "balanceOf"
name
: 'balanceOf',
type: "function"
type
: 'function',
stateMutability: "view"
stateMutability
: 'view',
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]
inputs
: [{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address' }],
outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]
outputs
: [{
name: "balance"
name
: 'balance',
type: "uint256"
type
: 'uint256' }],
}, {
name: "safeTransferFrom"
name
: 'safeTransferFrom',
type: "function"
type
: 'function',
stateMutability: "nonpayable"
stateMutability
: 'nonpayable',
inputs: readonly [{ readonly name: "from"; readonly type: "address"; }, { readonly name: "to"; readonly type: "address"; }, { readonly name: "tokenId"; readonly type: "uint256"; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address' },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address' },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256' },
],
outputs: readonly []
outputs
: [],
}, ] as
type const = readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
const
type
type Result = "balanceOf" | "safeTransferFrom"
Result
=
type ExtractAbiFunctionNames<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], { type: "function"; stateMutability: TAbiStateMutability; }>["name"]

Extracts all AbiFunction names from Abi.

ExtractAbiFunctionNames
<typeof
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
>

ExtractAbiFunctions

Extracts all AbiFunction types from Abi.

NameDescriptionType
TAbiABI.Abi
returnsABI Functions.AbiFunction (union)

Example

import { 
type ExtractAbiFunctions<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = TAbi[number] extends { type: 'function'; stateMutability: TAbiStateMutability; } ? TAbi[number] : never

Extracts all AbiFunction types from Abi.

ExtractAbiFunctions
} from 'abitype'
const
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
= [
{
name: "balanceOf"
name
: 'balanceOf',
type: "function"
type
: 'function',
stateMutability: "view"
stateMutability
: 'view',
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]
inputs
: [{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address' }],
outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]
outputs
: [{
name: "balance"
name
: 'balance',
type: "uint256"
type
: 'uint256' }],
}, {
name: "safeTransferFrom"
name
: 'safeTransferFrom',
type: "function"
type
: 'function',
stateMutability: "nonpayable"
stateMutability
: 'nonpayable',
inputs: readonly [{ readonly name: "from"; readonly type: "address"; }, { readonly name: "to"; readonly type: "address"; }, { readonly name: "tokenId"; readonly type: "uint256"; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address' },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address' },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256' },
],
outputs: readonly []
outputs
: [],
}, ] as
type const = readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
const
type
type Result = { readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; } | { ...; }
Result
=
type ExtractAbiFunctions<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = TAbi[number] extends { type: 'function'; stateMutability: TAbiStateMutability; } ? TAbi[number] : never

Extracts all AbiFunction types from Abi.

ExtractAbiFunctions
<typeof
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
>

By default, extracts all functions, but you can also filter by AbiStateMutability:

type Result = ExtractAbiFunctions<typeof erc721Abi, 'view'>

IsAbi

Checks if type is Abi.

NameDescriptionType
TAbiABI.Abi
returnsBoolean value. true if valid Abi, false if not.boolean

Example

import { 
type IsAbi<TAbi> = TAbi extends Abi ? true : false

Checks if type is Abi.

IsAbi
} from 'abitype'
const
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
= [
{
name: "balanceOf"
name
: 'balanceOf',
type: "function"
type
: 'function',
stateMutability: "view"
stateMutability
: 'view',
inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]
inputs
: [{
name: "owner"
name
: 'owner',
type: "address"
type
: 'address' }],
outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]
outputs
: [{
name: "balance"
name
: 'balance',
type: "uint256"
type
: 'uint256' }],
}, {
name: "safeTransferFrom"
name
: 'safeTransferFrom',
type: "function"
type
: 'function',
stateMutability: "nonpayable"
stateMutability
: 'nonpayable',
inputs: readonly [{ readonly name: "from"; readonly type: "address"; }, { readonly name: "to"; readonly type: "address"; }, { readonly name: "tokenId"; readonly type: "uint256"; }]
inputs
: [
{
name: "from"
name
: 'from',
type: "address"
type
: 'address' },
{
name: "to"
name
: 'to',
type: "address"
type
: 'address' },
{
name: "tokenId"
name
: 'tokenId',
type: "uint256"
type
: 'uint256' },
],
outputs: readonly []
outputs
: [],
}, ] as
type const = readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
const
type
type Result = true
Result
=
type IsAbi<TAbi> = TAbi extends Abi ? true : false

Checks if type is Abi.

IsAbi
<typeof
const abi: readonly [{ readonly name: "balanceOf"; readonly type: "function"; readonly stateMutability: "view"; readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; }, { ...; }]
abi
>

IsTypedData

Checks if type is TypedData.

NameDescriptionType
TTypedDataEIP-712 Typed Data schema.TypedData
returnsBoolean value. true if valid TypedData, false if not.boolean

Example

import { 
type IsTypedData<TTypedData> = TTypedData extends { [x: string]: readonly TypedDataParameter[]; [x: `string[${string}]`]: undefined; [x: `function[${string}]`]: undefined; [x: `address[${string}]`]: undefined; [x: `bool[${string}]`]: undefined; [x: `bytes[${string}]`]: undefined; [x: `bytes2[${string}]`]: undefined; [x: `bytes3[${string}]`]: undefined; [x: `bytes1[${string}]`]: undefined; [x: `bytes4[${string}]`]: undefined; [x: `bytes5[${string}]`]: undefined; [x: `bytes6[${string}]`]: undefined; [x: `bytes7[${string}]`]: undefined; [x: `bytes8[${string}]`]: undefined; [x: `bytes9[${string}]`]: undefined; [x: `bytes10[${string}]`]: undefined; [x: `bytes11[${string}]`]: undefined; [x: `bytes12[${string}]`]: undefined; [x: `bytes13[${string}]`]: undefined; [x: `bytes14[${string}]`]: undefined; [x: `bytes15[${string}]`]: undefined; [x: `bytes16[${string}]`]: undefined; [x: `bytes17[${string}]`]: undefined; [x: `bytes18[${string}]`]: undefined; [x: `bytes19[${string}]`]: undefined; [x: `bytes20[${string}]`]: undefined; [x: `bytes21[${string}]`]: undefined; [x: `bytes22[${string}]`]: undefined; [x: `bytes23[${string}]`]: undefined; [x: `bytes24[${string}]`]: undefined; [x: `bytes25[${string}]`]: undefined; [x: `bytes26[${string}]`]: undefined; [x: `bytes27[${string}]`]: undefined; [x: `bytes28[${string}]`]: undefined; [x: `bytes29[${string}]`]: undefined; [x: `bytes30[${string}]`]: undefined; [x: `bytes31[${string}]`]: undefined; [x: `bytes32[${string}]`]: undefined ...

Checks if type is TypedData.

IsTypedData
} from 'abitype'
const
const types: { readonly Person: readonly [{ readonly name: "name"; readonly type: "string"; }, { readonly name: "wallet"; readonly type: "address"; }]; readonly Mail: readonly [{ readonly name: "from"; readonly type: "Person"; }, { ...; }, { ...; }]; }
types
= {
type Person: readonly [{ readonly name: "name"; readonly type: "string"; }, { readonly name: "wallet"; readonly type: "address"; }]
Person
: [
{
name: "name"
name
: 'name',
type: "string"
type
: 'string' },
{
name: "wallet"
name
: 'wallet',
type: "address"
type
: 'address' },
],
type Mail: readonly [{ readonly name: "from"; readonly type: "Person"; }, { readonly name: "to"; readonly type: "Person"; }, { readonly name: "contents"; readonly type: "string"; }]
Mail
: [
{
name: "from"
name
: 'from',
type: "Person"
type
: 'Person' },
{
name: "to"
name
: 'to',
type: "Person"
type
: 'Person' },
{
name: "contents"
name
: 'contents',
type: "string"
type
: 'string' },
], } as
type const = { readonly Person: readonly [{ readonly name: "name"; readonly type: "string"; }, { readonly name: "wallet"; readonly type: "address"; }]; readonly Mail: readonly [{ readonly name: "from"; readonly type: "Person"; }, { ...; }, { ...; }]; }
const
type
type Result = true
Result
=
type IsTypedData<TTypedData> = TTypedData extends { [x: string]: readonly TypedDataParameter[]; [x: `string[${string}]`]: undefined; [x: `function[${string}]`]: undefined; [x: `address[${string}]`]: undefined; [x: `bool[${string}]`]: undefined; [x: `bytes[${string}]`]: undefined; [x: `bytes2[${string}]`]: undefined; [x: `bytes3[${string}]`]: undefined; [x: `bytes1[${string}]`]: undefined; [x: `bytes4[${string}]`]: undefined; [x: `bytes5[${string}]`]: undefined; [x: `bytes6[${string}]`]: undefined; [x: `bytes7[${string}]`]: undefined; [x: `bytes8[${string}]`]: undefined; [x: `bytes9[${string}]`