paint-brush
How Ethereum Transactions Work (Explained Like You're 5 Years Old) by@web3tales
172 reads

How Ethereum Transactions Work (Explained Like You're 5 Years Old)

by IvySeptember 3rd, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Ethereum was developed by Vitalik Buterin to address Bitcoin's limitations, including its basic smart contracts and lack of advanced transaction capabilities. Ethereum introduces smart contracts, gas fees, and a proof of stake consensus mechanism to enhance blockchain functionality, enabling more complex applications and efficient transactions.
featured image - How Ethereum Transactions Work (Explained Like You're 5 Years Old)
Ivy HackerNoon profile picture


In this article, you’ll learn:

  • Why Ethereum exists
  • Ethereum’s ‘advantages’ over Bitcoin.
  • How Ethereum transactions work.

A young Russian programmer, Vitalik Buterin, who was an active participant in the Bitcoin community and co-founded Bitcoin Magazine, began to question the limitations of Bitcoin.


He felt that Satoshi Nakamoto's concept of self-executing code (smart contracts) was basic. This prompted Vitalik to create a new blockchain called Ethereum, designed to support the development of applications on its blockchain, making it move from merely being a cryptocurrency to becoming a hub for further technological advancement.


Bitcoin's core functionality, even without additional features or upgrades, supports a basic form of smart contracts that allow you to send and receive Bitcoin.


Beyond that, Bitcoin’s smart contract can allow more advanced transactions, such as those requiring multiple signatures (proofs of ownership) for approval or enabling the exchange of Bitcoin for other cryptocurrencies. However, Vitalik still believed this breakthrough was limited.



Limitations of Bitcoin's scripting language

  • Lack of universal computing ability

    As a programmer, Vitalik discovered that Bitcoin's scripting language lacked loops—the ability to easily perform repetitive actions. This limitation is in place to prevent infinite loops that could disrupt transaction processing. Although programmers can work around this by manually repeating code, it makes the scripts much longer. For example, creating an alternative signature method might require writing the same multiplication step 256 times in the code. This elongates the code and is also time-consuming.


  • Value-blindness

    Bitcoin’s scripting language can't control the exact amount of Bitcoin that can be withdrawn from a transaction. For example, if two people each put $1000 worth of Bitcoin into a contract, and after 30 days, one should get $1000 back while the other gets the remainder, the script can't handle this directly. Typically, you'd need an external source of information (oracle) to determine the value of Bitcoin, but Bitcoin's system doesn't easily allow for splitting amounts. To work around this, you’d need to create multiple chunks of Bitcoin in different amounts and have the oracle decide which chunk goes to each person. This approach is quite complicated.


  • Limited use case

    Bitcoin’s scripting initially, couldn't handle more complicated tasks, like managing multi-step contracts, creating decentralized organizations, or setting withdrawal limits.


  • Data blindness

    The inability of Bitcoin's scripting to allow viewing or using important blockchain data like the timestamp, previous block hash, or other details, makes it difficult to create certain applications because they can’t access the contextual data that these elements provide.




Enter: Ethereum

Based on the limitations listed above, Vitalik Buterin decided to create the Ethereum blockchain—a platform that reimagines cryptocurrency by enabling the development of decentralized applications on the blockchain through smart contracts.

Sending Ethereum

To send Ethereum to a wallet, you need:

  • The recipient's wallet address.
  • A signature identifying you as the sender.
  • The amount of ether (Ethereum tokens) to transfer to the recipient.
  • Some amount for a gas fee. Every time you send Ethereum, you need to pay a small fee to the network. This fee, called "gas”, ensures your transaction gets processed. The fee varies depending on how busy the network is.


Once you have the wallet address, ETH, and your private key, you create and sign a transaction. The transaction is then sent to the Ethereum network, where it gets confirmed and added to the blockchain.


Understanding “Messages” in Ethereum

In Ethereum, contracts can communicate with each other by sending what is called "messages”. These messages are similar to transactions, but instead of coming from a person (like you or me), they come from a program that is already running on the Ethereum blockchain.


Messages are created when a contract uses a specific command to "call" another contract. When this happens, the recipient contract will run its code based on the instructions in the message.


A simple breakdown of how contracts interact in Ethereum:

  • The contract sends the message to a recipient—the contract that receives the message.
  • The message can include some Ethereum (ETH) to be sent along with it, similar to sending money with a note.
  • Extra instructions or information, depending on what the contracts are trying to do.
  • The fuel (gas) used to run the messages is capped. So if one contract sends a message to another, the gas allowance has to cover the entire process—from the first contract running its code to the second contract executing its tasks.  For a clearer understanding, see the example below 👇🏻


- Contract A sends a message to Contract B to perform its task, along with 400 units of gas.

- Contract B begins executing its code using the 400 units of gas.

  • If Contract B uses 300 units of gas, it completes its task successfully, and there are 100 units of gas left.
  • If Contract B uses more than 400 units of gas, it will run out of gas and its task will fail.


What's the difference between a message and a transaction?

A transaction is created by a person— the sender.

A message is like a transaction but it is created by a contract.


State Transition Function in Ethereum

Before a transaction on Ethereum is approved, here's a glimpse of what goes on behind the scenes:


  1. Ethereum makes sure that the transaction is correctly formatted, that the signature (digital fingerprint) is valid, and that it matches the sender's account. If anything is wrong, the transaction is rejected.


  2. The transaction fee is calculated based on how much work the transaction will require. This fee is subtracted from the sender’s account. If the sender doesn’t have enough money to cover the fee, the transaction is rejected.


  1. The specified amount of Ethereum (ETH) is moved from the sender’s account to the recipient’s account. If the recipient is a smart contract (an automated program), the Ethereum blockchain will run the contract's code until it’s finished or runs out of gas.


  1. If something goes wrong, like the sender not having enough funds or the contract running out of gas, Ethereum cancels the transaction and returns the accounts to how they were before, except that the sender still has to pay the fees.


  1. If everything goes well, any remaining gas is refunded to the sender, and the miner (the one processing the transaction) gets paid the fees for the gas that was used.


How Blocks Are Validated in Ethereum

Unlike Bitcoin, Ethereum uses proof of stake as its consensus mechanism to validate blocks. Before 2022, Ethereum used proof of work to validate blocks which requires more energy than proof of stake.


Proof of work requires participants on a blockchain to solve complex puzzles before a block is approved while proof of stake gives validating power to participants with large stakes in the blockchain’s token.


To easily remember, just think of proof of work as having to do some work and proof of stake as showing that you have staked tokens before being allowed to make important decisions.


Here's how proof of stake works in Ethereum:

  • Instead of miners solving puzzles to propose new blocks, Ethereum uses validators who have staked their ETH as collateral. Validators are randomly chosen to propose new blocks. This selection is not entirely random but is influenced by the amount of ETH they have staked.


  • When validators are chosen, they propose a new block that includes transactions and other important data. This block is then broadcast to the network.


  • Other validators on the network then check the block to ensure it is valid. They verify that the transactions are correct, the block is in the correct order, and it follows all the protocol rules. If a majority of validators agree, the block is added to the blockchain.


  • For a block to be considered final and irreversible, it must be confirmed by a supermajority (two-thirds) of the validators. Once this happens, it becomes part of the permanent record on the Ethereum blockchain, and altering it would require a massive amount of staked ETH, making it nearly impossible.


  • Validators who correctly validate blocks are rewarded with more ETH. However, if they act dishonestly or make mistakes (like trying to validate multiple conflicting blocks), they can lose a portion of their staked ETH through a process called slashing.


Ethereum Virtual Machine (EVM)

Smart contracts are usually written in lines of code as programs or languages that the Ethereum network fully understands. This language is called the Ethereum Virtual Machine code. It contains instructions on what the contract should do when an action is taken.


The Ethereum network runs through these instructions one by one, starting from the beginning and moving through each step until it either finishes or hits a problem.

The code has three main places where it can store and use data:


  • Stack: Think of this like a stack of plates—when you add a plate (data), it goes on top. When you take a plate, you take the top one first. It’s temporary storage.
  • Memory: A more flexible area where the code can store data temporarily while it's running.
  • Storage: Long-term memory for a contract. Anything stored here stays even after the contract is done running.


The EVM code can also use information from the incoming transaction, such as who sent it, how much Ethereum (ETH) is included, and any additional data sent along with it. After the contract runs, it can send back some data as a result, like answering a question or confirming that a task is done.


Ethereum v. Bitcoin

  • Ethereum blocks store both the list of transactions and the latest state of the network (like account balances and smart contract data) while Bitcoin blocks only store the transaction list. Ethereum’s blockchain keeps track of everything that happens on the network.


  • Merkle trees are typically used in Bitcoin for transaction verification, while Ethereum uses Patricia trees to manage its state, which includes account balances and contract storage.


  • Bitcoin uses proof of work to validate blocks while Ethereum uses proof of stake.


바카라사이트 바카라사이트 온라인바카라