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 
type Register = Register
Register
{
Register.BigIntType: bigint & { foo: 'bar'; }
BigIntType
: bigint & {
foo: "bar"
foo
: 'bar' }
} } import {
type ResolvedRegister = { AddressType: `0x${string}`; BigIntType: bigint & { foo: "bar"; }; BytesType: { inputs: `0x${string}`; outputs: `0x${string}`; }; IntType: number; ArrayMaxDepth: false; FixedArrayMinLength: 1; FixedArrayMaxLength: 99; StrictAbiType: false; }
ResolvedRegister
} from 'abitype'
type
type Result = bigint & { foo: 'bar'; }
Result
=
type ResolvedRegister = { AddressType: `0x${string}`; BigIntType: bigint & { foo: "bar"; }; BytesType: { inputs: `0x${string}`; outputs: `0x${string}`; }; IntType: number; ArrayMaxDepth: false; FixedArrayMinLength: 1; FixedArrayMaxLength: 99; StrictAbiType: false; }
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
} }