Skip to content

AbiItem Errors

AbiItem.AmbiguityError

Throws when ambiguous types are found on overloaded ABI items.

Examples

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from(['function foo(address)', 'function foo(bytes20)'])
AbiFunction.fromAbi(foo, 'foo', {
  args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
})
AbiItem.AmbiguityError: Found ambiguous types in overloaded ABI Items.
`bytes20` in `foo(bytes20)`, and
`address` in `foo(address)`
These types encode differently and cannot be distinguished at runtime.
Remove one of the ambiguous items in the ABI.

Solution

Remove one of the ambiguous types from the ABI.

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from([
  'function foo(address)',
  'function foo(bytes20)'
])
AbiFunction.fromAbi(foo, 'foo', {
  args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
})
AbiItem.AmbiguityError: Found ambiguous types in overloaded ABI Items.
`bytes20` in `foo(bytes20)`, and
`address` in `foo(address)`
These types encode differently and cannot be distinguished at runtime.
Remove one of the ambiguous items in the ABI.

Source: src/core/AbiItem.ts

AbiItem.InvalidSelectorSizeError

Throws when the selector size is invalid.

Examples

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from([
  'function foo(address)',
  'function bar(uint)'
])
AbiFunction.fromAbi(foo, '0xaaa')
AbiItem.InvalidSelectorSizeError: Selector size is invalid. Expected 4 bytes. Received 2 bytes ("0xaaa").

Solution

Ensure the selector size is 4 bytes.

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from([
  'function foo(address)',
  'function bar(uint)'
])
AbiFunction.fromAbi(foo, '0x7af82b1a')

Source: src/core/AbiItem.ts

AbiItem.NotFoundError

Throws when an ABI item is not found in the ABI.

Examples

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from([
  'function foo(address)',
  'function bar(uint)'
])
AbiFunction.fromAbi(foo, 'baz')
AbiItem.NotFoundError: ABI function with name "baz" not found.

Solution

Ensure the ABI item exists on the ABI.

import { Abi, AbiFunction } from 'ox'
 
const foo = Abi.from([
  'function foo(address)',
  'function bar(uint)',
  'function baz(bool)'
])
AbiFunction.fromAbi(foo, 'baz')

Source: src/core/AbiItem.ts