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
):
tsTry
declare module 'abitype' {export interfaceRegister {BigIntType : bigint & {foo : 'bar' }}}import {ResolvedRegister } from 'abitype'typeResult =ResolvedRegister ['BigIntType']
tsTry
declare module 'abitype' {export interfaceRegister {BigIntType : bigint & {foo : 'bar' }}}import {ResolvedRegister } from 'abitype'typeResult =ResolvedRegister ['BigIntType']
Extending Config from third-party packages
If you are using ABIType via another package (e.g. viem
), you can customize the ABIType's types by targeting the package's abitype
module:
declare module 'viem/node_modules/abitype' {
export interface Register {
BigIntType: MyCustomBigIntType
}
}
declare module 'viem/node_modules/abitype' {
export interface Register {
BigIntType: MyCustomBigIntType
}
}
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:
WARNING
When configuring ArrayMaxDepth
, FixedArrayMinLength
, and FixedArrayMaxLength
, there are trade-offs. For example, choosing a non-false value for ArrayMaxDepth
and increasing the range between FixedArrayMinLength
and FixedArrayMaxLength
will make your types more exhaustive, but will also slow down the compiler for type checking, autocomplete, etc.
AddressType
TypeScript type to use for address
values.
- Type
any
- Default
`0x${string}`
tsTry
declare module 'abitype' {export interfaceRegister {AddressType : `0x${string}`}}
tsTry
declare module 'abitype' {export interfaceRegister {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
tsTry
declare module 'abitype' {export interfaceRegister {ArrayMaxDepth : false}}
tsTry
declare module 'abitype' {export interfaceRegister {ArrayMaxDepth : false}}
BigIntType
TypeScript type to use for int<M>
and uint<M>
values, where M > 48
.
- Type
any
- Default
bigint
tsTry
declare module 'abitype' {export interfaceRegister {BigIntType : bigint}}
tsTry
declare module 'abitype' {export interfaceRegister {BigIntType : bigint}}
BytesType
TypeScript type to use for bytes<M>
values.
- Type
{ inputs: any; outputs: any }
- Default
{ inputs: `0x${string}` | Uint8Array; outputs: `0x${string}` }
tsTry
declare module 'abitype' {export interfaceRegister {BytesType : {inputs : `0x${string}` |Uint8Array outputs : `0x${string}`}}}
tsTry
declare module 'abitype' {export interfaceRegister {BytesType : {inputs : `0x${string}` |Uint8Array outputs : `0x${string}`}}}
FixedArrayMinLength
Lower bound for fixed-length arrays.
- Type
number
- Default
1
tsTry
declare module 'abitype' {export interfaceRegister {FixedArrayMinLength : 1}}
tsTry
declare module 'abitype' {export interfaceRegister {FixedArrayMinLength : 1}}
FixedArrayMaxLength
Upper bound for fixed-length arrays.
- Type
number
- Default
99
tsTry
declare module 'abitype' {export interfaceRegister {FixedArrayMinLength : 99}}
tsTry
declare module 'abitype' {export interfaceRegister {FixedArrayMinLength : 99}}
IntType
TypeScript type to use for int<M>
and uint<M>
values, where M <= 48
.
- Type
any
- Default
number
tsTry
declare module 'abitype' {export interfaceRegister {IntType : number}}
tsTry
declare module 'abitype' {export interfaceRegister {IntType : number}}
StrictAbiType
When set, validates AbiParameter
's type
against AbiType
.
- Type
boolean
- Default
false
tsTry
declare module 'abitype' {export interfaceRegister {StrictAbiType : false}}
tsTry
declare module 'abitype' {export interfaceRegister {StrictAbiType : false}}
WARNING
You probably only want to set this to true
if parsed types are returning as unknown
and you want to figure out why. This will slow down type checking significantly.