Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/Abi / Error

Error

Interfaces

AbiErrorConstructor()

Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:27
AbiErrorConstructor<TName, TInputs>(error): AbiErrorPrototype<TName, TInputs>
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:28

Type Parameters

TName
TName extends string = string
TInputs
TInputs extends readonly ParameterType[] = readonly ParameterType[]

Parameters

error
ErrorType<TName, TInputs>

Returns

AbiErrorPrototype<TName, TInputs>

Properties

decodeParams()
decodeParams: <TName, TInputs>(error, data) => ParametersToPrimitiveTypes<TInputs>
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:38 Decode error parameters from encoded data
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
data
Uint8Array<ArrayBufferLike> Encoded error data with selector prefix
Returns
ParametersToPrimitiveTypes<TInputs> Decoded parameter values
Throws
If data is too short for selector
Throws
If selector doesn’t match expected
Example
const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const decoded = decodeParams(error, encodedData); // [100n]
encodeParams()
encodeParams: <TName, TInputs>(error, args) => Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:37 Encode error parameters with selector prefix
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
args
ParametersToPrimitiveTypes<TInputs> Parameter values to encode
Returns
Uint8Array<ArrayBufferLike> Encoded error data with 4-byte selector prefix
Example
const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const encoded = encodeParams(error, [100n]); // Uint8Array with selector + encoded params
getSelector()
getSelector: (error) => Uint8Array
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:35
Parameters
error
any
Returns
Uint8Array
getSignature()
getSignature: <TName, TInputs>(error) => string
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:36 Get the signature string for an error (e.g., “MyError(uint256,address)“)
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
Returns
string Error signature string
Example
const error = { type: "error", name: "Unauthorized", inputs: [{ type: "address", name: "sender" }] };
const sig = getSignature(error); // "Unauthorized(address)"
prototype
prototype: AbiErrorPrototype
Defined in: src/primitives/Abi/error/AbiErrorConstructor.ts:34

Type Aliases

ErrorType

ErrorType<TName, TInputs> = object
Defined in: src/primitives/Abi/error/ErrorType.ts:3

Type Parameters

TName
TName extends string = string
TInputs
TInputs extends readonly Parameter[] = readonly Parameter[]

Properties

inputs
inputs: TInputs
Defined in: src/primitives/Abi/error/ErrorType.ts:9
name
name: TName
Defined in: src/primitives/Abi/error/ErrorType.ts:8
type
type: "error"
Defined in: src/primitives/Abi/error/ErrorType.ts:7

Variables

AbiError

const AbiError: AbiErrorConstructor
Defined in: src/primitives/Abi/error/index.ts:18

Error

const Error: object
Defined in: src/primitives/Abi/error/Error.js:30 Factory function for creating Error instances Note: Error is a plain object, not a class instance This namespace provides convenient methods for working with errors

Type Declaration

decodeParams()
decodeParams: <TName, TInputs>(error, data) => ParametersToPrimitiveTypes<TInputs>
Decode error parameters from encoded data
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
data
Uint8Array<ArrayBufferLike> Encoded error data with selector prefix
Returns
ParametersToPrimitiveTypes<TInputs> Decoded parameter values
Throws
If data is too short for selector
Throws
If selector doesn’t match expected
Example
const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const decoded = decodeParams(error, encodedData); // [100n]
encodeParams()
encodeParams: <TName, TInputs>(error, args) => Uint8Array<ArrayBufferLike>
Encode error parameters with selector prefix
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
args
ParametersToPrimitiveTypes<TInputs> Parameter values to encode
Returns
Uint8Array<ArrayBufferLike> Encoded error data with 4-byte selector prefix
Example
const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const encoded = encodeParams(error, [100n]); // Uint8Array with selector + encoded params
getSelector()
getSelector: (error) => Uint8Array
Parameters
error
any
Returns
Uint8Array
GetSelector()
GetSelector: (deps) => (error) => Uint8Array
Factory: Get the 4-byte selector for an error
Parameters
deps
Crypto dependencies
keccak256String
(str) => Uint8Array Keccak256 hash function for strings
Returns
Function that computes error selector
(error): Uint8Array
Parameters
error
any
Returns
Uint8Array
See
https://voltaire.tevm.sh/primitives/abi
Since
0.0.0
Example
import { GetSelector } from './primitives/Abi/error/index.js';
import { keccak256String } from './primitives/Hash/index.js';

const getSelector = GetSelector({ keccak256String });
const error = { type: "error", name: "Unauthorized", inputs: [] };
const selector = getSelector(error);
getSignature()
getSignature: <TName, TInputs>(error) => string
Get the signature string for an error (e.g., “MyError(uint256,address)“)
Type Parameters
TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]
Parameters
error
ErrorType<TName, TInputs> ABI error definition
Returns
string Error signature string
Example
const error = { type: "error", name: "Unauthorized", inputs: [{ type: "address", name: "sender" }] };
const sig = getSignature(error); // "Unauthorized(address)"

See

https://voltaire.tevm.sh/primitives/abi

Since

0.0.0

Throws

Example

import * as Abi from './primitives/Abi/index.js';
const error = {
  type: 'error',
  name: 'Unauthorized',
  inputs: [{ type: 'address', name: 'caller' }]
};
const selector = Abi.Error.getSelector(error);

getSelector()

const getSelector: (error) => Uint8Array
Defined in: src/primitives/Abi/error/index.ts:24

Parameters

error
any

Returns

Uint8Array

Functions

decodeParams()

decodeParams<TName, TInputs>(error, data): ParametersToPrimitiveTypes<TInputs>
Defined in: src/primitives/Abi/error/decodeParams.js:22 Decode error parameters from encoded data

Type Parameters

TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]

Parameters

error
ErrorType<TName, TInputs> ABI error definition
data
Uint8Array<ArrayBufferLike> Encoded error data with selector prefix

Returns

ParametersToPrimitiveTypes<TInputs> Decoded parameter values

Throws

If data is too short for selector

Throws

If selector doesn’t match expected

Example

const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const decoded = decodeParams(error, encodedData); // [100n]

encodeParams()

encodeParams<TName, TInputs>(error, args): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Abi/error/encodeParams.js:19 Encode error parameters with selector prefix

Type Parameters

TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]

Parameters

error
ErrorType<TName, TInputs> ABI error definition
args
ParametersToPrimitiveTypes<TInputs> Parameter values to encode

Returns

Uint8Array<ArrayBufferLike> Encoded error data with 4-byte selector prefix

Example

const error = { type: "error", name: "InsufficientBalance", inputs: [{ type: "uint256", name: "balance" }] };
const encoded = encodeParams(error, [100n]); // Uint8Array with selector + encoded params

GetSelector()

GetSelector(deps): (error) => Uint8Array
Defined in: src/primitives/Abi/error/getSelector.js:21 Factory: Get the 4-byte selector for an error

Parameters

deps
Crypto dependencies
keccak256String
(str) => Uint8Array Keccak256 hash function for strings

Returns

Function that computes error selector
(error): Uint8Array
Parameters
error
any
Returns
Uint8Array

See

https://voltaire.tevm.sh/primitives/abi

Since

0.0.0

Example

import { GetSelector } from './primitives/Abi/error/index.js';
import { keccak256String } from './primitives/Hash/index.js';

const getSelector = GetSelector({ keccak256String });
const error = { type: "error", name: "Unauthorized", inputs: [] };
const selector = getSelector(error);

getSignature()

getSignature<TName, TInputs>(error): string
Defined in: src/primitives/Abi/error/getSignature.js:15 Get the signature string for an error (e.g., “MyError(uint256,address)“)

Type Parameters

TName
TName extends string
TInputs
TInputs extends readonly ParameterType<AbiType, string, string>[]

Parameters

error
ErrorType<TName, TInputs> ABI error definition

Returns

string Error signature string

Example

const error = { type: "error", name: "Unauthorized", inputs: [{ type: "address", name: "sender" }] };
const sig = getSignature(error); // "Unauthorized(address)"