🌱
Dev Compendium
  • Ethereum
    • Solidity
      • EVM
      • Architecture
      • Execution Context
      • Transactions
      • Gas
      • Calldata, Memory & Storage
      • Gas Optimisation
      • Function Declarations
      • receive() & fallback()
      • CALL vs. DELEGATE CALL
    • Yul
      • Introduction
      • Types
      • Basic Operations
      • Storage
      • Memory
        • Arrays
        • Structs
        • Tuples, revert, keccak256
        • Logs and Events
        • Gotchas
        • abi.encode
      • Calldata
        • External Calls
        • Dynamic Length Inputs
        • Transferring Value
        • Receiving Contract Calls
      • Contracts in Yul
      • Other Yul Functions
    • Foundry
    • Security
      • Common Vulnerabilities
      • Best Practices
      • Development Workflow
      • Contract Migration
    • Auditing Tools
      • Slither
      • Mythril
      • Fuzzing
    • Upgradable Contracts
      • Upgrade Patterns
      • ERC-1967 Implementation
      • Deployment
    • MEV
    • Tooling
      • Chainlink
      • IPFS
      • Radicle
    • Frontend
      • Contract Hooks
      • Wallet Connection
        • wagmi.sh
        • Rainbow Kit
      • thirdweb
    • Protocol Research
      • Uniswap v2
      • Uniswap v3
      • Curve
      • GMX
  • Starkware
    • Fundamentals
    • Account Abstraction
    • Universal Deployer
    • Cairo 1.0
    • starknet.js
    • Security Model
  • Zero Knowledge
    • Group Theory
    • ECDSA
  • Rust
    • Basic Operations
    • Set up
    • Primitives
    • Control Flow
    • Mutability & Shadowing
    • Adding Behavior
    • Lifetimes
    • Std Library
  • SUI
    • Architecture
    • Consensus Mechanism
    • Local Node Setup
    • Sui Client CLI
    • Move Contracts
      • Move
      • Move.toml
      • Move.lock
      • Accessing Time in Sui Move
      • Set up Development Framework
      • Debug & Publish
      • Package Upgrades
      • Sui Move Library
      • Difference from Core Move
    • Object Programming
      • Object Basics
      • Using Objects
      • Immutable Objects
      • Object Wrapping
      • Dynamic Fields
      • Collections
      • Unit Testing
      • Deployment with CLI
  • NEAR
    • Architecture
    • Contract Standards
      • Fungible Token (NEP-141)
      • Non-Fungible Token (NEP-171)
      • Storage Management (NEP-145)
      • Events (NEP-297)
      • Meta-Transactions
    • Rust Contracts
      • Development Workflow
      • Smart Contract Layout
      • Storage Management
      • Events & Meta-transactions
      • Method Types
      • Upgrading Contracts
      • Unit Testing
    • NEAR Libraries
    • Environment Variables
    • Serialisation
    • Security Concepts
    • Collections
    • JS SDK
Powered by GitBook
On this page
  1. Ethereum
  2. Yul

Calldata

Previousabi.encodeNextExternal Calls

Last updated 1 year ago

Features of calldata

  • The longer the transaction calldata is (tx.data), the more gas the sender pays

  • Transaction data can have arbitrary length and arbitrary values

  • Solidity’s dominance has enforced a convention on how is used

  • When sending a transaction to a wallet, you don’t typically put any data in, unless you are trying to send that person a message (you can even send a message without sending ether; it is considered a valid transaction)

  • When sending transactions to a smart contract, the first four bytes specify the function selector, and the bytes that follow are abi-encoded function arguments

  • Solidity expects the bytes after the function selector to always be a multiple of 32 in length, but this is purely just convention

  • If you send more bytes, Solidity will ignore them

  • However, a Yul smart contract can be programmed to respond to arbitrary length [tx.data](<http://tx.data>) in an arbitrary manner

  • Function selector - first four bytes of keccak256 of the function signature

ABI specification

  • Frontend apps know how to format the transaction based on the ABI specification of the contract

  • In Solidity, the function selector and 32-byte encoded arguments are created under the hood by interfaces, or if you use abi.encodeWithSignature("balanceOf(address)", 0x....)

  • But in Yul, you have to be explicit

  • Yul doesn’t have a notion of function selectors, interfaces, or abi encoding

  • If you want to make an external call to a Solidity contract, you have to implement all of that yourself

tx.data