Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Calldata

Calldata is the immutable data field in an Ethereum transaction that contains the input arguments for a smart contract function call.
Chainscore © 2026
definition
BLOCKCHAIN GLOSSARY

What is Calldata?

A technical definition of calldata, the immutable input data for smart contract function execution on the Ethereum Virtual Machine (EVM).

Calldata is the immutable, read-only data field of an Ethereum transaction that contains the encoded function selector and arguments for a smart contract call. It is the primary mechanism for passing information into a contract's functions and is stored separately from the transaction's value or signature. Unlike contract storage or memory, calldata is non-persistent and cannot be modified by the contract during execution, making it a gas-efficient location for passing large data arrays or complex parameters.

When a user or another contract initiates a transaction, the Application Binary Interface (ABI) encodes the desired function name and arguments into a hexadecimal string placed in the calldata field. The first four bytes are the function selector, a hash that uniquely identifies the function to be called. The remaining bytes contain the arguments, packed according to their data types. Within the executing function, the msg.data global variable provides access to the full calldata, while individual arguments are automatically decoded into the function's parameters for use in the contract logic.

Understanding calldata is crucial for gas optimization. Reading from calldata using the calldataload opcode is cheap, making it ideal for data that only needs to be inspected, not stored. Since Ethereum's London upgrade, transactions that specify certain opcodes to execute with only calldata (and no value) benefit from a new transaction type, EIP-2930, which can further reduce costs. Developers must also be aware of calldata when writing secure code, as malformed or malicious calldata is a common attack vector that must be properly validated.

how-it-works
BLOCKCHAIN GLOSSARY

How Calldata Works

A technical breakdown of calldata, the immutable and gas-efficient input data for smart contract function calls on the Ethereum Virtual Machine.

Calldata is a special, read-only data area in the Ethereum Virtual Machine (EVM) that contains the immutable arguments passed to a smart contract during a transaction or message call. When a user or contract initiates a transaction that calls a function—like transfer(address,uint256)—the function selector and its encoded parameters are packed into this byte array. This data is stored outside the contract's storage and persists on-chain as part of the transaction, making it a critical component for verifying execution and enabling blockchain explorers to decode transaction details.

The structure of calldata is highly optimized. The first four bytes are the function selector, a unique identifier derived from hashing the function's signature (e.g., keccak256("transfer(address,uint256)")). The remaining bytes contain the ABI-encoded parameters, packed contiguously according to the Ethereum ABI specification. This encoding is deterministic, allowing both the EVM and off-chain tools to parse the input correctly. Because calldata is immutable and external to contract state, reading from it is a low-cost operation, making it the preferred location for function arguments that do not need to be stored permanently.

A key advantage of calldata is its impact on gas optimization. Storing data in persistent contract storage (SSTORE) is one of the most expensive operations on Ethereum. In contrast, using calldata for input parameters, especially for arrays and structs, can drastically reduce gas costs. For this reason, developers often designate function parameters as calldata instead of memory for external functions, as it prevents an unnecessary copy of the data into memory, which itself consumes gas. This makes calldata essential for building efficient decentralized applications (dApps).

Calldata is distinct from other data locations. Unlike transaction data (a broader term for the entire data field of a transaction, which is the calldata for contract calls), or event logs (cheap, indexed storage for off-chain consumption), calldata is the precise input for execution. It is also different from msg.data, a global variable in Solidity that provides direct, low-level access to the complete calldata byte array, allowing for advanced function dispatch patterns like fallback and receive functions.

key-features
BLOCKCHAIN DATA LAYER

Key Features of Calldata

Calldata is the primary mechanism for passing input data into smart contract functions on the Ethereum Virtual Machine (EVM). Understanding its properties is essential for gas optimization and contract interaction.

01

Immutable & Persistent Storage

Calldata is a read-only, non-modifiable data area. Once a transaction is included in a block, its calldata is permanently recorded on-chain. This provides a verifiable, tamper-proof record of all inputs to a contract function call, which is crucial for audit trails and event reconstruction.

02

Gas Cost Structure

Accessing calldata is gas-efficient for contract execution. On Ethereum, non-zero bytes cost 16 gas and zero bytes cost 4 gas, making data compression (e.g., using lots of zeros) beneficial. However, it contributes to the base transaction fee as it increases the payload size stored by all network nodes.

03

ABI-Encoded Format

Calldata is structured according to the Contract ABI Specification. It includes:

  • A 4-byte function selector (hash of the function signature)
  • The encoded arguments for the function This standardized encoding allows wallets and clients to correctly construct transactions that any compliant EVM node can decode and execute.
04

`calldata` vs. `memory` Keywords

In Solidity, function parameters with complex types (like arrays, structs) can be marked with a data location. Using calldata for external functions is more gas-efficient than memory because it avoids copying data to a new location. Parameters marked calldata are immutable within the function.

05

Primary Use Case: Contract Interactions

Every external call to a smart contract uses calldata. This includes:

  • Direct user transactions from an Externally Owned Account (EOA)
  • Cross-contract calls using call, delegatecall, or staticcall
  • Transactions submitted by decentralized applications (dApps) via wallets like MetaMask.
06

Access via Assembly

Developers can inspect raw calldata using inline Yul assembly (assembly { ... }). Key opcodes include:

  • calldatasize(): Gets the size of calldata in bytes.
  • calldataload(p): Reads 32 bytes from calldata starting at position p.
  • calldatacopy(t, f, s): Copies s bytes from calldata position f to memory position t. This allows for low-level, gas-optimized decoding.
code-example
TECHNICAL PRIMER

Calldata in Code

A deep dive into the technical implementation and critical role of calldata within the Ethereum Virtual Machine (EVM) and smart contract execution.

In the Ethereum Virtual Machine (EVM), calldata is a special, immutable, and non-persistent data area used to pass input arguments to a smart contract function. It is the primary mechanism for encoding the function selector and its parameters when a transaction or message call is made. This data is stored outside the contract's persistent storage and is accessible via low-level opcodes like CALLDATALOAD, CALLDATASIZE, and CALLDATACOPY. Understanding calldata is fundamental for developers writing gas-efficient contracts and interacting with the blockchain at a low level.

The structure of calldata is defined by the Ethereum Application Binary Interface (ABI) specification. The first four bytes are the function selector, a hash of the function signature (e.g., transfer(address,uint256)), which the EVM uses to route the call to the correct contract logic. Subsequent bytes contain the ABI-encoded arguments, packed according to strict rules for each data type. This encoding is deterministic, allowing both off-chain clients and on-chain contracts to correctly serialize and deserialize complex data structures like arrays, tuples, and nested objects.

From a gas economics perspective, calldata is uniquely cost-effective. On Ethereum, writing data to transaction calldata is significantly cheaper than writing to storage (SSTORE) or even memory within a contract execution. This is because calldata is part of the transaction, which all nodes must store and propagate, making its cost model different from volatile execution memory. Consequently, optimizing functions to use external visibility and read directly from calldata, rather than copying it to memory, is a common technique for reducing gas consumption, especially for functions that only read input data.

gas-optimization
BLOCKCHAIN GLOSSARY

Calldata and Gas Optimization

Calldata is the primary mechanism for passing input data into smart contract functions on Ethereum and EVM-compatible chains. Its structure and usage have a direct, significant impact on transaction gas costs.

01

What is Calldata?

Calldata is a read-only, non-modifiable data area in an Ethereum transaction that contains the function signature and arguments passed to a smart contract. It is the primary input mechanism for contract execution.

  • Location: Exists outside the EVM's memory and storage.
  • Purpose: Specifies which function to call and what data to pass.
  • Structure: Begins with a 4-byte function selector, followed by ABI-encoded arguments.
02

Gas Cost Mechanics

Using calldata is cheaper than using memory or storage for data input in many scenarios. The gas cost is based on two rules:

  • Non-zero bytes: Cost 16 gas each.
  • Zero bytes: Cost 4 gas each (68 gas post-EIP-2028).

This incentivizes efficient encoding, such as using smaller integer types (uint8 vs uint256) and packing multiple arguments into bytes to maximize zero bytes.

03

Calldata vs. Memory

A critical optimization is declaring function arguments as calldata instead of memory for reference types (arrays, structs, strings).

  • calldata: Arguments are read directly from the transaction data. No copy cost.
  • memory: Arguments are copied from calldata into a new memory location, incurring significant allocation gas.

Rule: Use calldata for all external function inputs unless you need to modify them within the function.

04

ABI Encoding & Selector

The Application Binary Interface (ABI) defines how to encode data into calldata. The first 4 bytes are the function selector, a hash of the function signature (e.g., transfer(address,uint256)).

  • Example: transfer(address,uint256) selector is 0xa9059cbb.
  • Optimization: Using existing, standardized function signatures (like ERC-20's) avoids the need for custom encoding logic and reduces contract size.
05

Use Case: Batch Operations

Calldata is ideal for batch operations where the contract processes a list of inputs. Passing an array of structs or addresses as calldata is far more gas-efficient than multiple individual transactions.

Example: An airdrop contract that takes a calldata array of (address, uint256) pairs can process hundreds of transfers in one transaction, saving massively on base transaction fees (21,000 gas per tx).

06

Limitations & Best Practices

While optimized for reading, calldata has constraints.

  • Immutable: Data cannot be modified by the contract.
  • External Only: The calldata location is only valid for parameters of external functions. Public functions can use it if called externally.
  • Best Practice: Always use the smallest, most packed data representation possible and audit ABI encoding off-chain to minimize byte size before submission.
SOLIDITY DATA LOCATIONS

Calldata vs. Memory vs. Storage

A comparison of the three primary data location types in Solidity, detailing their purpose, mutability, gas cost, and lifecycle.

FeatureCalldataMemoryStorage

Primary Purpose

Function input parameters (external calls)

Temporary variables within function execution

Persistent state variables on-chain

Mutability

Immutable (read-only)

Mutable within function

Mutable (persists changes)

Gas Cost (Read)

Lowest (part of tx data)

Low (in-memory)

Highest (SLOAD operation)

Gas Cost (Write)

Not applicable (immutable)

Low (in-memory)

Very High (SSTORE operation)

Data Lifetime

Duration of function call

Duration of function call

Permanent (lifetime of contract)

Where Declared

Function parameters (external), returns

Function variables, returns, internal function parameters

Contract-level state variables

Persistence

Non-persistent

Non-persistent

Persistent

Example Keyword

calldata (explicit for arrays/structs)

memory (explicit for reference types)

storage (explicit for references)

ecosystem-usage
CALLDATA

Ecosystem Usage & Examples

Calldata is a critical, non-persistent data location for function arguments in Ethereum transactions. Its efficient use directly impacts transaction costs and scalability.

01

Cost-Efficient Data Storage

Calldata is the cheapest data location for passing arguments to a contract function, as it is non-persistent and read-only. Unlike storage, writing to calldata is impossible, and unlike memory, it is not allocated within the EVM for the contract's execution. This makes it ideal for bulk data that only needs to be read, such as signatures, proofs, or batch operation parameters. Its cost was significantly reduced by EIP-2028, making Layer 2 solutions like Optimistic Rollups more economical.

02

Function Selector & ABI Encoding

The first 4 bytes of calldata are the function selector, a hash of the function signature. The remaining bytes contain the ABI-encoded arguments. For example, a call to transfer(address,uint256) encodes the recipient address and token amount into a predictable byte sequence. Off-chain clients and indexers decode this calldata to interpret transaction intent. Understanding this structure is essential for building wallets, explorers, and interacting with contracts programmatically.

03

Core Use Case: Contract Interactions

Every external call to a smart contract uses calldata. Common examples include:

  • Sending tokens via a transfer function.
  • Approving a spender with an approve call.
  • Swapping assets on a decentralized exchange (DEX).
  • Submitting a bid in an auction contract. The calldata contains all the necessary instructions for the contract to execute the specific function with the provided parameters.
05

Advanced Pattern: Calldata for Immutable Arguments

Using calldata for function parameters in view and pure functions, or in internal functions that pass on data without modification, saves gas. Since Solidity 0.6.9, you can declare parameters as calldata instead of memory for reference types (like arrays, strings). This prevents an expensive copy operation, as the function reads directly from the immutable transaction data.

security-considerations
CALLDATA

Security Considerations

Calldata is the primary input mechanism for smart contract functions, carrying immutable arguments and function selectors. Its structure and usage have direct security implications for gas costs, validation, and reentrancy.

01

Gas Cost & Denial-of-Service

Calldata is the cheapest data location for input parameters, costing 4 gas for a zero byte and 16 gas for a non-zero byte. However, functions that process unbounded calldata arrays (e.g., airdrops) can be exploited for gas griefing, causing transactions to fail or become prohibitively expensive. Contracts must implement reasonable limits on input size to prevent denial-of-service attacks.

02

Input Validation & Encoding

Malformed or maliciously encoded calldata is a primary attack vector. Key risks include:

  • Signature Replay: Using abi.encodePacked for signed messages can create hash collisions.
  • Type Confusion: Improper use of abi.decode can lead to misinterpretation of data.
  • Selector Clashing: Custom function selectors may conflict, leading to unintended function execution. Always use abi.encode, validate data length/range, and employ checks-effects-interactions.
03

DelegateCall & Calldata Forwarding

When using delegatecall, the entire calldata context (including msg.sender and msg.value) is forwarded to the logic contract. If the calldata is not validated before delegation, an attacker can craft calls that exploit the logic contract's state from the proxy's context. This is critical in proxy upgrade patterns and requires strict access control on the delegatecall entry point.

04

Reentrancy via Fallback Data

When sending Ether via low-level calls (e.g., addr.call{value: x}("")), any calldata provided is executed by the recipient's fallback function. An attacker's contract can use this calldata to re-enter the calling function before state updates are finalized. The Checks-Effects-Interactions pattern and using transfer or send (which forward limited 2300 gas) mitigate this, but the safest practice is to complete all state changes before any external call.

05

Frontrunning & Calldata Privacy

Calldata is public on-chain data from the moment a transaction is broadcast to the mempool. This exposes:

  • Function arguments (e.g., token amounts, wallet addresses).
  • Contract logic intent before execution.
  • Signature parameters for permit functions. Malicious actors can frontrun transactions by copying and replacing the calldata with a higher gas fee. Solutions include using commit-reveal schemes or private mempools.
06

Verification with Calldata Proofs

Zero-knowledge proofs, like those used in zk-Rollups, often use calldata as a data availability layer. The security of the system depends on the integrity and availability of this posted data. If calldata is withheld or corrupted, proofs cannot be verified, potentially freezing funds. This highlights the role of Ethereum calldata as a secure, immutable bulletin board for layer-2 state transitions.

FAQ

Common Misconceptions About Calldata

Clarifying frequent misunderstandings about Ethereum's calldata, a critical component for transaction execution and gas cost calculation.

Yes, calldata is the technical term for the immutable, read-only input data field of an Ethereum transaction. When you call a smart contract function, the encoded function selector and arguments are placed into this field. It is the primary component of a transaction's data field, which is broadcast to the network and stored on-chain. While 'transaction data' is a common synonym, 'calldata' specifically refers to this data's role during contract execution within the EVM.

CALDATA

Frequently Asked Questions (FAQ)

Calldata is a critical component of Ethereum transactions, used to pass information to smart contracts. These questions cover its technical function, costs, and optimization strategies.

Calldata is a read-only, non-persistent data area in an Ethereum transaction that contains the function signature and arguments passed to a smart contract. It is the primary mechanism for a transaction's sender to communicate with a contract's code. When you call a contract function, the Ethereum Virtual Machine (EVM) reads the calldata to determine which function to execute and with what parameters. Unlike contract storage, calldata is not stored on-chain after execution, making it a cheaper location for temporary data. It is a key part of the transaction's payload and is essential for all contract interactions, from simple token transfers to complex DeFi operations.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team
What is Calldata? | Ethereum Transaction Data | ChainScore Glossary