DEV Community

Mahima Thacker
Mahima Thacker

Posted on

2

Ethereum Transaction Calls and State Changes

Let’s break down how different transaction calls work in Ethereum, and how state changes happen using a simple example🫣:

  1. CALL
  • Imagine Contract A wants to send 1 ETH to Contract B and run a function there.
  • When Contract A makes the CALL:
  • A new environment (EVM instance) is created for Contract B.
  • msg.sender is Contract A, meaning Contract B knows who initiated the transaction.
  • msg.value is set to 1 ETH (the amount being sent).

  • State changes: Even though msg.sender is Contract A, any changes (like updating balances) happen in Contract B's storage, not Contract A’s.

Image description

2.STATICCALL

  • Suppose Contract A only wants to check a balance in Contract B without changing anything.
  • When Contract A uses STATICCALL:
  • It’s just like CALL, but no changes are allowed—just reading data.
  • msg.sender is still Contract A, but Contract B cannot change any state.

Image description

3.DELEGATECALL

  • Now, let’s say Contract A wants to use Contract B’s code but with its own (Contract A’s) storage.
  • When Contract A uses DELEGATECALL:
  • Contract B’s code runs, but it affects Contract A’s storage.
  • msg.sender: The original caller (EOA), not Contract A.

Image description

So In-short:

CALL: Contract A triggers changes in Contract B’s state.
STATICCALL: Same as CALL, but only reads data, no changes.
DELEGATECALL: Contract A runs Contract B’s code, but changes are made to Contract A’s storage.

Understanding these helps you see how smart contracts interact and manage state in #Ethereum. 💥

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay