Skip to content

Configuration

How to configure ABIType in userland or as a library author.

Overview

ABIType's types are customizable using declaration merging. Just install abitype (make sure versions match) and extend the Register interface either directly in your code or in a d.ts file (e.g. abi.d.ts):

declare module 'abitype' {
  export interface Register {
    
Register.bigIntType: bigint & { foo: "bar"; }
bigIntType
: bigint & {
foo: "bar"
foo
: 'bar' }
} } import {
type ResolvedRegister = { addressType: Register extends { addressType: infer type; } ? type : Register extends { AddressType: infer type; } ? type : DefaultRegister["addressType"]; ... 14 more ...; StrictAbiType: ResolvedRegister["strictAbiType"]; }
ResolvedRegister
} from 'abitype'
type
type Result = bigint & { foo: "bar"; }
Result
=
type ResolvedRegister = { addressType: Register extends { addressType: infer type; } ? type : Register extends { AddressType: infer type; } ? type : DefaultRegister["addressType"]; ... 14 more ...; StrictAbiType: ResolvedRegister["strictAbiType"]; }
ResolvedRegister
['bigIntType']

Options

ABIType tries to strike a balance between type exhaustiveness and speed with sensible defaults. In some cases, you might want to tune your configuration (e.g. use a custom bigint type). To do this, the following configuration options are available:

addressType

TypeScript type to use for address values.

  • Type any
  • Default `0x${string}`
declare module 'abitype' {
  export interface Register {
    
Register.addressType: `0x${string}`
addressType
: `0x${string}`
} }

arrayMaxDepth

Maximum depth for nested array types (e.g. string[][]). When false, there is no maximum array depth.

  • Type number | false
  • Default false
declare module 'abitype' {
  export interface Register {
    
Register.ArrayMaxDepth: false
ArrayMaxDepth
: false
} }

bigIntType

TypeScript type to use for int<M> and uint<M> values, where M > 48.

  • Type any
  • Default bigint
declare module 'abitype' {
  export interface Register {
    
Register.bigIntType: bigint
bigIntType
: bigint
} }

bytesType

TypeScript type to use for bytes<M> values.

  • Type { inputs: any; outputs: any }
  • Default { inputs: `0x${string}` | Uint8Array; outputs: `0x${string}` }
declare module 'abitype' {
  export interface Register {
    
Register.bytesType: { inputs: `0x${string}`; outputs: `0x${string}`; }
bytesType
: {
inputs: `0x${string}`
inputs
: `0x${string}`
outputs: `0x${string}`
outputs
: `0x${string}`
} } }

fixedArrayMinLength

Lower bound for fixed-length arrays.

  • Type number
  • Default 1
declare module 'abitype' {
  export interface Register {
    
Register.FixedArrayMinLength: 1
FixedArrayMinLength
: 1
} }

fixedArrayMaxLength

Upper bound for fixed-length arrays.

  • Type number
  • Default 99
declare module 'abitype' {
  export interface Register {
    
Register.FixedArrayMinLength: 99
FixedArrayMinLength
: 99
} }

intType

TypeScript type to use for int<M> and uint<M> values, where M <= 48.

  • Type any
  • Default number
declare module 'abitype' {
  export interface Register {
    
Register.intType: number
intType
: number
} }

strictAbiType

When set, validates AbiParameter's type against AbiType.

  • Type boolean
  • Default false
declare module 'abitype' {
  export interface Register {
    
Register.strictAbiType: false
strictAbiType
: false
} }