Ethereum Fundamentals: Transactions and Messages Explained

·

What Are Transactions and Messages?

Transactions and messages are two fundamental yet distinct concepts in the Ethereum ecosystem. While they share similarities in structure, their purposes differ significantly. This guide explores transactions, messages, and message calls, clarifying their roles and differences.

Understanding Transactions

A transaction is a signed piece of data from an external actor (e.g., a user) sent to the Ethereum network. It facilitates the transfer of value or data between accounts or triggers contract creation. Ethereum supports two transaction types:

  1. Message-Calling Transactions: Invoke contract functions.
  2. Contract-Creation Transactions: Deploy new smart contracts.

Key Components of a Transaction

Transaction Fields (Per Ethereum Yellow Paper)

FieldDescription
nonceSender’s transaction counter (prevents replay attacks).
gasPricePrice per gas unit.
gasLimitMaximum gas allocated.
toRecipient address (or null for contract creation).
valueEther amount (wei).
v, r, sECDSA signature components (derives sender’s public key).

For contract-creation transactions:

👉 Learn how gas fees impact Ethereum transactions

Understanding Messages

A message is a virtual object generated by contracts during execution. Unlike transactions, messages exist only within the EVM and aren’t recorded on-chain. Structurally, they resemble transactions but serve internal purposes (e.g., cross-contract function calls).

Message Components

Key Differences: Transactions, Messages, and Calls

FeatureTransactionMessageMessage Call
OriginExternal actor (signed).Contract-generated.Local function invocation.
PersistenceRecorded on-chain.EVM-only (transient).Non-persistent (simulation).
Gas CostPaid by sender.Deducted from contract balance.No Ether spent (read-only).

Ethereum Yellow Paper Definitions:

Function Calls: Transaction or Message Call?

Here’s how different invocation methods behave:

  1. Direct call to a contract function: Message call (read-only).
  2. sendTransaction to a function: On-chain transaction.
  3. Contract-to-contract call: Message call.
  4. Contract-to-contract sendTransaction: Message (not a transaction; lacks external signature).

👉 Explore smart contract interaction patterns

FAQs

1. Can a message modify blockchain state?

No. Messages are internal to the EVM and don’t persist. Only transactions alter state.

2. Why does sendTransaction create a transaction but not contract-to-contract calls?

Transactions require external signatures. Contract-initiated actions are messages, even if they use similar methods.

3. How does nonce prevent replay attacks?

Each transaction increments the sender’s nonce. Replayed transactions with outdated nonce values are rejected.

4. What happens if a transaction exceeds its gasLimit?

The EVM reverts all changes, and the sender loses the spent gas.

5. Are messages free to send?

No. Messages consume gas from the sender contract’s balance, though they’re cheaper than transactions.

6. Can I simulate a transaction without broadcasting it?

Yes. Use eth_call for read-only simulations or testnets for dry runs.


Copyright © Luo Yuanhang. Licensed under Attribution-NonCommercial 3.0.