Qaynaq LABS · TOOLS

CRYPTO GLOSSARY

Calldata

Calldata is the non-persistent input data sent to a smart contract during a transaction, separate from the contract's storage. It is used to specify the function to call and its arguments.

Technical definition

In Ethereum and other EVM-compatible blockchains, calldata is a read-only byte array passed to a smart contract when a transaction invokes a function. Unlike contract storage, which is persistent and stored on-chain, calldata is temporary and only exists during the execution of the transaction. It is encoded according to the Ethereum ABI (Application Binary Interface) specification, where the first 4 bytes specify the function selector (a hash of the function name and its parameter types), followed by the encoded arguments. Calldata is immutable during execution and cannot be modified by the contract, ensuring predictable and secure function calls.

An analogy

Imagine sending a letter to a friend where the envelope contains instructions (e.g., 'Pay $50 to Alice') and the letter itself is the detailed message (e.g., 'Here’s how to transfer the money'). The envelope (calldata) is the input that tells the recipient what to do, while the letter’s content is the specific data (arguments) needed to complete the task. The envelope is discarded after reading, just as calldata is temporary.

Why it matters

Calldata enables smart contracts to receive and process external inputs in a standardized and secure way. It ensures that function calls are unambiguous and that the contract can interpret the caller's intent correctly, which is critical for composability and interoperability in decentralized applications.

Where it came from

Calldata has been a core part of Ethereum’s design since its inception in 2015, inherited from the EVM’s design principles. It was introduced to standardize how external calls to smart contracts are structured, ensuring consistency across transactions and reducing ambiguity in function execution.

Example in practice

A user sends a transaction to a decentralized exchange (DEX) smart contract to swap 1 ETH for 1500 DAI. The calldata for this transaction would include: (1) the function selector for the swap function (e.g., `0xa945e51e` for `swapExactETHForTokens`), and (2) the encoded arguments, such as the minimum amount of DAI expected (1490 DAI) and the recipient address. The contract reads this calldata to execute the swap.

Common misconceptions

  • Calldata is the same as contract storage → Correction: Calldata is temporary and read-only during execution, while contract storage is persistent and can be modified by the contract.
  • Calldata can be modified by the contract → Correction: Calldata is immutable during execution; only the contract’s storage can be modified.
  • Calldata is only used for function calls → Correction: Calldata is also used for contract creation (e.g., deploying a new contract), where it contains the contract bytecode and constructor arguments.

Risks & limitations

  • Gas costs: Calldata increases transaction gas costs because each byte of calldata consumes gas. Complex or large calldata can make transactions prohibitively expensive.
  • Data encoding errors: Incorrectly encoded calldata can lead to failed transactions or unintended contract behavior, such as calling the wrong function or passing invalid arguments.
  • Front-running: In some cases, calldata can be observed by miners or bots before execution, leading to front-running attacks where malicious actors exploit the pending transaction's intent.
  • Privacy concerns: Calldata is visible on-chain, meaning sensitive data (e.g., private keys or personal information) should never be included in calldata.

Related terms

About "Calldata" in crypto

Cryptocurrency vocabulary moves faster than any other technical field. New terms appear weekly, old terms quietly change meaning, and most "definitions" online were written by someone trying to sell you something. Qaynaq Labs' crypto glossary aims for the opposite: neutral, accurate, skeptical explainers that include the downside.

This entry covers the technical mechanics, a real-world analogy, where the concept came from, and what could go wrong. Pair it with the related terms to build a working mental model of how the pieces fit together.

Frequently asked

Can calldata be used to store data permanently on-chain?

No, calldata is temporary and only exists during the execution of a transaction. To store data permanently, you must use contract storage (e.g., state variables in Solidity).

Why is calldata more expensive than contract storage in terms of gas?

Calldata is more expensive because it is part of the transaction payload, which is stored in the blockchain’s state trie temporarily. Contract storage, while also gas-intensive, is optimized for repeated reads and writes within the contract’s execution context.

How does calldata differ from transaction input data?

In Ethereum, calldata is a subset of transaction input data. The entire transaction input includes the calldata (for smart contract calls) or the contract bytecode (for contract creation), while calldata specifically refers to the input passed to a smart contract function.

Can calldata be encrypted to hide its contents?

No, calldata is transmitted in plaintext on-chain and cannot be encrypted. If you need to hide data, you must use off-chain methods (e.g., encrypting data before sending it to a contract) or zero-knowledge proofs (e.g., zk-SNARKs).

What happens if calldata is too large for a transaction?

If calldata exceeds the block gas limit or transaction size limit, the transaction will fail. This is a common issue for complex smart contract interactions, such as those involving large arrays or nested structs.