Skip to content

Comparisons

No other library does what ABIType does (inferring TypeScript types from ABIs and EIP-712 Typed Data), but there are some similarities with other libraries. This page compares ABIType to other libraries that are similar in some way.

Comparisons strive to be as accurate and as unbiased as possible. If you use any of these libraries and feel the information could be improved, feel free to suggest changes.

TypeChain

TypeChain is a command-line tool that generates types and runtime wrappers for popular libraries at build time. People often use the generated types to cast values (e.g. new Contract(…) as TypeChainType). ABIType is a TypeScript library that infers static types from any ABI using type-level programming.

Below is a comparison of the libraries's type-level features:

TypeChainABIType
Lifecycle StepGenerated at build timeInferred at compile time
ABI SourcePath(s) to CLI commandDirectly reference in code
Type GenerationIterates through ABIs and builds stringsStatic from type-level

OPINION

If you are a library author looking to support type inference and autocomplete based on ABIs and EIP-721 Typed Data, you are better off writing your code using ABIType so users don't need to set up anything to get type-safety (e.g. install TypeChain, set up build step).

ethers.js

ethers.js is a JavaScript library for interacting with Ethereum. Among other features, it has utilities for working with human-readable ABIs. In addition to runtime functions, ABIType also has type utilities for working with human-readable ABIs.

Below is a comparison of the runtime functions from ethers.js and ABIType for parsing and formatting human-readable ABIs.

Interface versus parseAbi

Parses a human-readable ABI into a JSON ABI.

ts
ts
import { parseAbi } from 'abitype'
 
const abi = parseAbi([
'function name((string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
abi
const abi: readonly [{ readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }, { ...; }]
Try
ts
import { parseAbi } from 'abitype'
 
const abi = parseAbi([
'function name((string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
abi
const abi: readonly [{ readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }, { ...; }]
Try
ts
ts
import { parseAbi } from 'abitype'
 
const abi = parseAbi([
'struct Foo { string name; uint256 age }',
'function name((string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
abi
const abi: readonly [{ readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }, { ...; }]
Try
ts
import { parseAbi } from 'abitype'
 
const abi = parseAbi([
'struct Foo { string name; uint256 age }',
'function name((string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
abi
const abi: readonly [{ readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }, { ...; }]
Try
ts
ts
import { Interface } from '@ethersproject/abi'
 
const iface = new Interface([
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
const abi = iface.fragments
const abi: readonly Fragment[]
Try
ts
import { Interface } from '@ethersproject/abi'
 
const iface = new Interface([
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
const abi = iface.fragments
const abi: readonly Fragment[]
Try
ts
ts
import { Interface } from 'ethers'
 
const iface = new Interface([
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
const abi = iface.fragments
const abi: readonly Fragment[]
Try
ts
import { Interface } from 'ethers'
 
const iface = new Interface([
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
'event Foo(address indexed bar)',
])
const abi = iface.fragments
const abi: readonly Fragment[]
Try
  • ABIType returns inferred ABI, while ethers.js just returns readonly Fragment[]
  • ABIType supports structs as signatures and inline tuples (e.g. (string name, uint256 age)).
  • ethers.js does not support struct signatures, but does support inline tuples with the optional tuple prefix keyword.
  • ABIType supports mixed named and unnamed parameters, while ethers.js only supports either all named or all unnamed parameters.

Fragment versus parseAbiItem

Parses a human-readable ABI item into a JSON ABI item.

ts
ts
import { parseAbiItem } from 'abitype'
 
const abiItem = parseAbiItem(
const abiItem: { readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }
'function name((string name, uint256 age) foo, uint256 tokenId)',
)
Try
ts
import { parseAbiItem } from 'abitype'
 
const abiItem = parseAbiItem(
const abiItem: { readonly name: "name"; readonly type: "function"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "string"; readonly name: "name"; }, { ...; }]; readonly name: "foo"; }, { ...; }]; readonly outputs: readonly []; }
'function name((string name, uint256 age) foo, uint256 tokenId)',
)
Try
ts
ts
import { Fragment } from '@ethersproject/abi'
 
const abiItem = Fragment.from(
const abiItem: Fragment
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
)
Try
ts
import { Fragment } from '@ethersproject/abi'
 
const abiItem = Fragment.from(
const abiItem: Fragment
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
)
Try
ts
ts
import { Fragment } from 'ethers'
 
const abiItem = Fragment.from(
const abiItem: Fragment
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
)
Try
ts
import { Fragment } from 'ethers'
 
const abiItem = Fragment.from(
const abiItem: Fragment
'function name(tuple(string name, uint256 age) foo, uint256 tokenId)',
)
Try

Benchmarks

bash
 pnpm bench src/human-readable/parseAbiItem.bench.ts

 Parse ABI item (3) 1716ms
  name              hz     min     max    mean     p75     p99    p995    p999     rme  samples
· abitype   597,815.38  0.0015  0.3760  0.0017  0.0016  0.0022  0.0022  0.0031  ±0.58%   298908   fastest
· ethers@5   83,313.74  0.0114  0.2662  0.0120  0.0119  0.0130  0.0141  0.0401  ±0.45%    41657  
· ethers@6   39,887.50  0.0233  0.3942  0.0251  0.0248  0.0308  0.0365  0.1979  ±0.43%    19944   slowest

Summary
abitype - src/human-readable/parseAbiItem.bench.ts > comparison
  7.18x faster than ethers@5
  14.99x faster than ethers@6
 pnpm bench src/human-readable/parseAbiItem.bench.ts

 Parse ABI item (3) 1716ms
  name              hz     min     max    mean     p75     p99    p995    p999     rme  samples
· abitype   597,815.38  0.0015  0.3760  0.0017  0.0016  0.0022  0.0022  0.0031  ±0.58%   298908   fastest
· ethers@5   83,313.74  0.0114  0.2662  0.0120  0.0119  0.0130  0.0141  0.0401  ±0.45%    41657  
· ethers@6   39,887.50  0.0233  0.3942  0.0251  0.0248  0.0308  0.0365  0.1979  ±0.43%    19944   slowest

Summary
abitype - src/human-readable/parseAbiItem.bench.ts > comparison
  7.18x faster than ethers@5
  14.99x faster than ethers@6

ParamType versus parseAbiParameter

Parses a human-readable ABI parameter into a JSON ABI parameter.

ts
ts
import { parseAbiParameter } from 'abitype'
 
const abiParameter = parseAbiParameter('string foo')
const abiParameter: { readonly type: "string"; readonly name: "foo"; }
Try
ts
import { parseAbiParameter } from 'abitype'
 
const abiParameter = parseAbiParameter('string foo')
const abiParameter: { readonly type: "string"; readonly name: "foo"; }
Try
ts
ts
import { ParamType } from '@ethersproject/abi'
 
const abiParameter = ParamType.from('string foo')
const abiParameter: ParamType
Try
ts
import { ParamType } from '@ethersproject/abi'
 
const abiParameter = ParamType.from('string foo')
const abiParameter: ParamType
Try
ts
ts
import { ParamType } from 'ethers'
 
const abiParameter = ParamType.from('string foo')
const abiParameter: ParamType
Try
ts
import { ParamType } from 'ethers'
 
const abiParameter = ParamType.from('string foo')
const abiParameter: ParamType
Try

Benchmarks

bash
 pnpm bench src/human-readable/parseAbiParameter.bench.ts

 Parse basic ABI Parameter (3) 2358ms
  name                hz     min     max    mean     p75     p99    p995    p999     rme  samples
· abitype   4,073,274.42  0.0001  1.0815  0.0002  0.0003  0.0003  0.0003  0.0005  ±0.52%  2036638   fastest
· ethers@6    288,007.56  0.0032  1.5593  0.0035  0.0034  0.0039  0.0058  0.0082  ±0.75%   144004   slowest
· ethers@5    507,627.43  0.0018  0.6730  0.0020  0.0020  0.0022  0.0023  0.0027  ±0.43%   253814  

Summary
abitype - src/human-readable/parseAbiParameter.bench.ts > Parse basic ABI Parameter
  8.02x faster than ethers@5
  14.14x faster than ethers@6
 pnpm bench src/human-readable/parseAbiParameter.bench.ts

 Parse basic ABI Parameter (3) 2358ms
  name                hz     min     max    mean     p75     p99    p995    p999     rme  samples
· abitype   4,073,274.42  0.0001  1.0815  0.0002  0.0003  0.0003  0.0003  0.0005  ±0.52%  2036638   fastest
· ethers@6    288,007.56  0.0032  1.5593  0.0035  0.0034  0.0039  0.0058  0.0082  ±0.75%   144004   slowest
· ethers@5    507,627.43  0.0018  0.6730  0.0020  0.0020  0.0022  0.0023  0.0027  ±0.43%   253814  

Summary
abitype - src/human-readable/parseAbiParameter.bench.ts > Parse basic ABI Parameter
  8.02x faster than ethers@5
  14.14x faster than ethers@6

Interface.format versus formatAbi

Format JSON ABI into human-readable ABI.

ts
ts
import { formatAbi } from 'abitype'
 
const abi = formatAbi([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
abi
const abi: readonly ["function name((string name, uint256 age) foo, uint256 tokenId)", "event Foo(address indexed bar)"]
Try
ts
import { formatAbi } from 'abitype'
 
const abi = formatAbi([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
abi
const abi: readonly ["function name((string name, uint256 age) foo, uint256 tokenId)", "event Foo(address indexed bar)"]
Try
ts
ts
import { Interface } from '@ethersproject/abi'
 
const iface = new Interface([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
const abi = iface.format('minimal')
const abi: string | string[]
Try
ts
import { Interface } from '@ethersproject/abi'
 
const iface = new Interface([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
const abi = iface.format('minimal')
const abi: string | string[]
Try
ts
ts
import { Interface } from 'ethers'
 
const iface = new Interface([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
const abi = iface.format(true)
const abi: string[]
Try
ts
import { Interface } from 'ethers'
 
const iface = new Interface([
{
type: 'function',
name: 'name',
stateMutability: 'nonpayable',
inputs: [
{
type: 'tuple',
name: 'foo',
components: [
{ type: 'string', name: 'name' },
{ type: 'uint256', name: 'age' },
],
},
{ type: 'uint256', name: 'tokenId' },
],
outputs: [],
},
{
type: 'event',
name: 'Foo',
inputs: [{ type: 'address', name: 'bar', indexed: true }],
},
])
const abi = iface.format(true)
const abi: string[]
Try

ABIType returns inferred human-readable ABI, while ethers.js just returns string[].

Benchmarks

bash
 pnpm bench src/human-readable/formatAbi.bench.ts

 Format ABI (3) 2068ms
· abitype   1,687,145.72 ops/sec ±0.39% (843573 samples) fastest
· ethers@5    117,287.14 ops/sec ±0.36% ( 58644 samples)
· ethers@6     46,075.42 ops/sec ±0.37% ( 23038 samples) slowest

Summary
abitype - src/human-readable/formatAbi.bench.ts > Format ABI
  14.38x faster than ethers@5
  36.62x faster than ethers@6
 pnpm bench src/human-readable/formatAbi.bench.ts

 Format ABI (3) 2068ms
· abitype   1,687,145.72 ops/sec ±0.39% (843573 samples) fastest
· ethers@5    117,287.14 ops/sec ±0.36% ( 58644 samples)
· ethers@6     46,075.42 ops/sec ±0.37% ( 23038 samples) slowest

Summary
abitype - src/human-readable/formatAbi.bench.ts > Format ABI
  14.38x faster than ethers@5
  36.62x faster than ethers@6

Fragment.format versus formatAbiItem

Formats a JSON ABI item into a human-readable ABI item.

ts
ts
import { formatAbiItem } from 'abitype'
 
const abiItem = formatAbiItem({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
abiItem
const abiItem: "function foo(string bar, string baz)"
Try
ts
import { formatAbiItem } from 'abitype'
 
const abiItem = formatAbiItem({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
abiItem
const abiItem: "function foo(string bar, string baz)"
Try
ts
ts
import { Fragment } from '@ethersproject/abi'
 
const iface = Fragment.from({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
const abiItem = iface.format('minimal')
const abiItem: string
Try
ts
import { Fragment } from '@ethersproject/abi'
 
const iface = Fragment.from({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
const abiItem = iface.format('minimal')
const abiItem: string
Try
ts
ts
import { Fragment } from 'ethers'
 
const iface = Fragment.from({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
const abiItem = iface.format('minimal')
const abiItem: string
Try
ts
import { Fragment } from 'ethers'
 
const iface = Fragment.from({
type: 'function',
name: 'foo',
stateMutability: 'nonpayable',
inputs: [
{ type: 'string', name: 'bar' },
{ type: 'string', name: 'baz' },
],
outputs: [],
})
const abiItem = iface.format('minimal')
const abiItem: string
Try

ABIType returns inferred human-readable ABI item, while ethers.js just returns string.

Benchmarks

bash
 pnpm bench src/human-readable/formatAbi.bench.ts

 Format basic ABI function (3) 2534ms
· abitype   4,833,836.91 ops/sec ±0.89% (2416919 samples) fastest
· ethers@6    123,697.64 ops/sec ±0.32% (  61849 samples) slowest
· ethers@5    343,959.66 ops/sec ±0.33% ( 171980 samples)

Summary
abitype - src/human-readable/formatAbiItem.bench.ts > Format basic ABI function
  14.05x faster than ethers@5
  39.08x faster than ethers@6
 pnpm bench src/human-readable/formatAbi.bench.ts

 Format basic ABI function (3) 2534ms
· abitype   4,833,836.91 ops/sec ±0.89% (2416919 samples) fastest
· ethers@6    123,697.64 ops/sec ±0.32% (  61849 samples) slowest
· ethers@5    343,959.66 ops/sec ±0.33% ( 171980 samples)

Summary
abitype - src/human-readable/formatAbiItem.bench.ts > Format basic ABI function
  14.05x faster than ethers@5
  39.08x faster than ethers@6

ParamType.format versus formatAbiParameter

Formats JSON ABI parameter to human-readable ABI parameter.

ts
ts
import { formatAbiParameter } from 'abitype'
 
const result = formatAbiParameter({ type: 'string', name: 'foo' })
const result: "string foo"
Try
ts
import { formatAbiParameter } from 'abitype'
 
const result = formatAbiParameter({ type: 'string', name: 'foo' })
const result: "string foo"
Try
ts
ts
import { ParamType } from '@ethersproject/abi'
 
const result = ParamType.from({ type: 'string', name: 'foo' }).format('minimal')
const result: string
Try
ts
import { ParamType } from '@ethersproject/abi'
 
const result = ParamType.from({ type: 'string', name: 'foo' }).format('minimal')
const result: string
Try
ts
ts
import { ParamType } from 'ethers'
 
const result = ParamType.from({ type: 'string', name: 'foo' }).format('minimal')
const result: string
Try
ts
import { ParamType } from 'ethers'
 
const result = ParamType.from({ type: 'string', name: 'foo' }).format('minimal')
const result: string
Try

ABIType returns inferred human-readable ABI parameter, while ethers.js just returns string

Benchmarks

bash
 pnpm bench src/human-readable/formatAbiParameter.bench.ts

 Format basic ABI Parameter (3) 5043ms
· abitype   10,550,231.55 ops/sec ±0.63% (5275116 samples) fastest
· ethers@6     398,639.32 ops/sec ±0.40% ( 199320 samples) slowest
· ethers@5   1,041,080.97 ops/sec ±0.45% ( 520541 samples)

Summary
abitype - src/human-readable/formatAbiParameter.bench.ts > Format basic ABI Parameter
  10.41x faster than ethers@5
  28.57x faster than ethers@6
 pnpm bench src/human-readable/formatAbiParameter.bench.ts

 Format basic ABI Parameter (3) 5043ms
· abitype   10,550,231.55 ops/sec ±0.63% (5275116 samples) fastest
· ethers@6     398,639.32 ops/sec ±0.40% ( 199320 samples) slowest
· ethers@5   1,041,080.97 ops/sec ±0.45% ( 520541 samples)

Summary
abitype - src/human-readable/formatAbiParameter.bench.ts > Format basic ABI Parameter
  10.41x faster than ethers@5
  28.57x faster than ethers@6

Released under the MIT License.