Skip to main content
Transaction calldata contains the function selector and ABI-encoded parameters sent to smart contracts. It’s the primary mechanism for invoking contract functions on Ethereum.
New to EVM calldata? Start with Fundamentals to learn how calldata works in the EVM, function selectors, and ABI encoding.

Overview

CallData is a specialized branded Uint8Array that subtypes Hex for representing transaction data. It contains a 4-byte function selector followed by ABI-encoded parameters.
import type { brand } from './brand.js'

export type CallDataType = Uint8Array & {
  readonly [brand]: "CallData"
}
CallData is a branded Uint8Array. TypeScript enforces type safety through a unique Symbol brand, preventing accidental mixing with other byte arrays while maintaining zero runtime overhead.

Developer Experience

Despite being a Uint8Array, calldata displays formatted in most environments:
const calldata = CallData("0xa9059cbb000000000000000000000000...");
console.log(calldata);
// CallData("0xa9059cbb...")
This makes debugging more readable than raw byte arrays while maintaining performance.

Quick Start

import { CallData, Abi, Address, TokenBalance } from '@tevm/voltaire';

// Define ABI
const abi = Abi([{
  name: "transfer",
  type: "function",
  inputs: [
    { name: "to", type: "address" },
    { name: "amount", type: "uint256" }
  ]
}]);

// Encode function call
const recipient = Address("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const amount = TokenBalance.fromUnits("1", 18);

const calldata: CallData = abi.transfer.encode(recipient, amount);

console.log(CallData.toHex(calldata));
// "0xa9059cbb00000000000000000000000070997970..."

Practical Examples

See Fundamentals for detailed explanations of how the EVM processes calldata, function selector derivation, and ABI encoding mechanics.

API Methods

Constructors

Conversions

Selectors

Validation

  • isValid(value) - Check if value can be converted to calldata
  • is(value) - Type guard to check if value is CallData

Comparisons

Type Hierarchy

CallData conceptually subtypes Hex but stores as Uint8Array internally:
// Conceptual relationship
CallData extends Hex

// Runtime representation
CallData: Uint8Array & { readonly [brand]: "CallData" }
This design provides:
  • Type safety: Can’t accidentally pass arbitrary Uint8Array where CallData expected
  • Performance: Direct byte manipulation without string conversion
  • Interop: Works with Web APIs expecting Uint8Array