Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/CallData

primitives/CallData

Classes

InvalidCallDataLengthError

Defined in: src/primitives/CallData/errors.ts:4 Error thrown when calldata is too short (must be at least 4 bytes for selector)

Extends

  • Error

Constructors

Constructor
new InvalidCallDataLengthError(message, options?): InvalidCallDataLengthError
Defined in: src/primitives/CallData/errors.ts:9
Parameters
message
string
options?
expected?
string
value?
unknown
Returns
InvalidCallDataLengthError
Overrides
Error.constructor

Properties

code
readonly code: "INVALID_CALLDATA_LENGTH" = "INVALID_CALLDATA_LENGTH"
Defined in: src/primitives/CallData/errors.ts:5
expected
readonly expected: string
Defined in: src/primitives/CallData/errors.ts:7
value
readonly value: unknown
Defined in: src/primitives/CallData/errors.ts:6

InvalidHexFormatError

Defined in: src/primitives/CallData/errors.ts:23 Error thrown when hex string format is invalid

Extends

  • Error

Constructors

Constructor
new InvalidHexFormatError(message): InvalidHexFormatError
Defined in: src/primitives/CallData/errors.ts:26
Parameters
message
string
Returns
InvalidHexFormatError
Overrides
Error.constructor

Properties

code
readonly code: "INVALID_HEX_FORMAT" = "INVALID_HEX_FORMAT"
Defined in: src/primitives/CallData/errors.ts:24

InvalidValueError

Defined in: src/primitives/CallData/errors.ts:35 Error thrown when value type is unsupported

Extends

  • Error

Constructors

Constructor
new InvalidValueError(message, options?): InvalidValueError
Defined in: src/primitives/CallData/errors.ts:40
Parameters
message
string
options?
expected?
string
value?
unknown
Returns
InvalidValueError
Overrides
Error.constructor

Properties

code
readonly code: "INVALID_VALUE" = "INVALID_VALUE"
Defined in: src/primitives/CallData/errors.ts:36
expected?
readonly optional expected: string
Defined in: src/primitives/CallData/errors.ts:38
value
readonly value: unknown
Defined in: src/primitives/CallData/errors.ts:37

Interfaces

BaseCallData

Defined in: src/primitives/CallData/index.ts:12 Base CallData interface with instance methods

Extends

Indexable

[index: number]: number

Properties

[brand]
readonly [brand]: "CallData"
Defined in: src/primitives/CallData/CallDataType.ts:10
Inherited from
CallDataType.[brand]

Methods

equals()
equals(other): boolean
Defined in: src/primitives/CallData/index.ts:17
Parameters
other
CallDataType
Returns
boolean
getSelector()
getSelector(): Uint8Array
Defined in: src/primitives/CallData/index.ts:15
Returns
Uint8Array
hasSelector()
hasSelector(selector): boolean
Defined in: src/primitives/CallData/index.ts:16
Parameters
selector
string | Uint8Array<ArrayBufferLike>
Returns
boolean
toBytes()
toBytes(): Uint8Array
Defined in: src/primitives/CallData/index.ts:14
Returns
Uint8Array
toHex()
toHex(): string
Defined in: src/primitives/CallData/index.ts:13 Convert the Uint8Array to a hex encoded string
Returns
string The hex encoded string representation of the Uint8Array
Overrides
CallDataType.toHex

Type Aliases

CallDataType

CallDataType = Uint8Array & object
Defined in: src/primitives/CallData/CallDataType.ts:9 Branded CallData type for EVM transaction calldata CallData is a branded Uint8Array containing function selector (first 4 bytes) followed by ABI-encoded parameters.

Type Declaration

[brand]
readonly [brand]: "CallData"

Variables

decode()

const decode: (calldata, abi) => CallDataDecoded = BrandedCallData.decode
Defined in: src/primitives/CallData/index.ts:118 Decode CallData to structured form

Parameters

calldata
CallDataType CallData to decode
abi
readonly Item[] ABI specification with function definitions

Returns

CallDataDecoded Decoded structure with selector, signature, and parameters

Throws

If function not found in ABI or decoding fails

Example

const abi = [{
  name: "transfer",
  type: "function",
  inputs: [
    { name: "to", type: "address" },
    { name: "amount", type: "uint256" }
  ]
}];

const decoded = CallData.decode(calldata, abi);
console.log(decoded.signature); // "transfer(address,uint256)"
console.log(decoded.parameters[0]); // "0x..."
console.log(decoded.parameters[1]); // bigint

encode()

const encode: (signature, params) => CallDataType = CallData.encode
Defined in: src/primitives/CallData/index.ts:117

Parameters

signature
string
params
unknown[]

Returns

CallDataType

equals()

const equals: (a, b) => boolean = BrandedCallData.equals
Defined in: src/primitives/CallData/index.ts:114 Check if two CallData instances are equal (constant-time comparison) Uses constant-time comparison to prevent timing attacks.

Parameters

a
CallDataType First CallData
b
CallDataType Second CallData

Returns

boolean True if instances are bytewise identical

Example

const calldata1 = CallData.from("0xa9059cbb...");
const calldata2 = CallData.from("0xa9059cbb...");
console.log(CallData.equals(calldata1, calldata2)); // true

from()

const from: (value) => CallDataType = CallData.from
Defined in: src/primitives/CallData/index.ts:107

Parameters

value
string | Uint8Array<ArrayBufferLike>

Returns

CallDataType

fromBytes()

const fromBytes: (value) => CallDataType = CallData.fromBytes
Defined in: src/primitives/CallData/index.ts:109

Parameters

value
Uint8Array

Returns

CallDataType

fromHex()

const fromHex: (value) => CallDataType = CallData.fromHex
Defined in: src/primitives/CallData/index.ts:108

Parameters

value
string

Returns

CallDataType

getSelector()

const getSelector: (calldata) => Uint8Array<ArrayBufferLike> = BrandedCallData.getSelector
Defined in: src/primitives/CallData/index.ts:112 Extract 4-byte function selector from CallData

Parameters

calldata
CallDataType CallData to extract selector from

Returns

Uint8Array<ArrayBufferLike> 4-byte array containing function selector (view, not copy)

Example

const calldata = CallData.from("0xa9059cbb...");
const selector = CallData.getSelector(calldata);
console.log(selector); // Uint8Array [0xa9, 0x05, 0x9c, 0xbb]

hasSelector()

const hasSelector: (calldata, selector) => boolean = BrandedCallData.hasSelector
Defined in: src/primitives/CallData/index.ts:113 Check if CallData matches a specific function selector Uses constant-time comparison to prevent timing attacks.

Parameters

calldata
CallDataType CallData to check
selector
Expected selector (hex string or bytes) string | Uint8Array<ArrayBufferLike>

Returns

boolean True if selector matches

Example

const calldata = CallData.from("0xa9059cbb...");

// Check with hex string
CallData.hasSelector(calldata, "0xa9059cbb"); // true

// Check with bytes
CallData.hasSelector(calldata, new Uint8Array([0xa9, 0x05, 0x9c, 0xbb])); // true

is()

const is: (value) => value is CallDataType = BrandedCallData.is
Defined in: src/primitives/CallData/index.ts:115 Type guard to check if value is CallData

Parameters

value
unknown Value to check

Returns

value is CallDataType True if value is CallData

Example

if (CallData.is(value)) {
  // value is CallDataType here (type narrowed)
  const selector = CallData.getSelector(value);
}

isValid()

const isValid: (value) => boolean = BrandedCallData.isValid
Defined in: src/primitives/CallData/index.ts:116 Check if value can be converted to CallData

Parameters

value
unknown Value to validate

Returns

boolean True if value can be converted to CallData

Example

CallData.isValid("0xa9059cbb"); // true (valid 4-byte selector)
CallData.isValid("0x1234"); // false (only 2 bytes)
CallData.isValid("0xGGGG"); // false (invalid hex)
CallData.isValid(null); // false

MIN_SIZE

const MIN_SIZE: number = 4
Defined in: src/primitives/CallData/constants.js:5 Minimum size for calldata (4 bytes for function selector)

SELECTOR_SIZE

const SELECTOR_SIZE: number = 4
Defined in: src/primitives/CallData/constants.js:11 Size of function selector in bytes

toBytes()

const toBytes: (calldata) => Uint8Array<ArrayBufferLike> = BrandedCallData.toBytes
Defined in: src/primitives/CallData/index.ts:111 Return the underlying Uint8Array representation (zero-copy)

Parameters

calldata
CallDataType CallData to convert

Returns

Uint8Array<ArrayBufferLike> Raw byte array (shares underlying buffer)

Example

const calldata = CallData.from("0xa9059cbb");
const bytes = CallData.toBytes(calldata);
console.log(bytes.length); // 4

toHex()

const toHex: (calldata) => HexType = BrandedCallData.toHex
Defined in: src/primitives/CallData/index.ts:110 Convert CallData to hex string with 0x prefix

Parameters

calldata
CallDataType CallData to convert

Returns

HexType Lowercase hex string with 0x prefix

Example

const calldata = CallData.fromBytes(new Uint8Array([0xa9, 0x05, 0x9c, 0xbb]));
console.log(CallData.toHex(calldata)); // "0xa9059cbb"

Functions

CallData()

CallData(value): BaseCallData
Defined in: src/primitives/CallData/index.ts:35 Creates CallData instances with prototype chain

Parameters

value
Value to convert (hex string or bytes) string | Uint8Array<ArrayBufferLike>

Returns

BaseCallData CallData instance with prototype methods

See

https://voltaire.tevm.sh/primitives/calldata for CallData documentation

Since

0.0.0

Throws

If value format is invalid

Example

import { CallData } from './primitives/CallData/index.js';
const calldata = CallData('0xa9059cbb...');
console.log(calldata.toHex());

References

default

Renames and re-exports CallData