Ethereum Transactions

Hello friends, Hope you are doing good and having fun. I am here with another article on the blockchain. Previously, we have discussed the blockchain, some of its concepts, and its characteristics, and today I will talk about transactions. We would also explore the concept of gas in this tutorial. So let’s start by defining a transaction.

What is Ethereum Transaction?

  • A transaction is a message signed by an account owner that is added to a block and recorded in the blockchain.
  • A transaction is initiated by an externally owned account and then it gets transmitted to the Ethereum network.
  • It can be originated only by an externally owned account (an account owned by a human) and not by a contract account.
  • Through transactions, one can interact with the Ethereum world. As a result, they change and update the state of Ethereum.
  • The transaction can be any action such as transferring ether or calling functions of a smart contract. Consequently, the state of the Ethereum virtual machine (EVM) is changed. For example, when account x transfers some ether to account y, a transaction is initiated and after that, the balances of both accounts are updated. The new balances are then stored in the Ethereum network.
  • Any account or node has the right to initiate a transaction. But it must be verified through mining.
  • Every transaction has a gas limit and a gas fee. This fee is given to miners as a reward for verifying (or mining) that transaction. I will cover the concept of mining in my next tutorials.

These points highlight the importance of a transaction. You can see that a transaction is the only thing that can change the state of the Ethereum virtual machine. By transaction, you can execute a smart contract or deploy a new smart contract to Ethereum and there is no other way to do that. Contracts cannot deploy themselves, contracts cannot call other contracts unless a transaction is initiated by an externally owned account. So, the Ethereum network state depends on the transactions.

Now, this was the definition and importance of a transaction in the blockchain. In the next part, I am going to explain the structure of a transaction.

Structure of Ethereum Transaction

Any transaction in the Ethereum network has some specific components when it is transmitted to the network. Every node receives the transaction and stores it in its memory. The data of a transaction or the components are listed below:

1. Recipient:

  • The address of the account that will receive the transaction is called the recipient. The recipient can be an externally owned account or a contract account. Each transaction is directed towards a recipient.

2. Nonce:

  • A nonce is a number showing the sequence of a transaction, Nonce is assigned by the account initiating the transaction.

3. Gas Price:

  • Any transaction requires some fee that is paid by the creator of the transaction. The fee is calculated per gas unit. The unit is Wei a smaller unit of ether.

4. Gas Limit:

  • The creator of the transaction gives the number of gas units that can be used for the transaction. This is the maximum limit of gas that would be consumed.

5. Value:

  • The value specifies the amount of Wei or Ether that the sender account wants to send to the recipient.

6. Data:

  • If a transaction recipient is a smart contract then the data contains information for executing functions of the contract. This includes data of variable length.

7. Signature:

  • A Signature is the identification of the sender. The signature is generated when an externally owned account confirms and signs the transaction via its private key.

These are the components included in a transaction. In the next section, I will discuss the types of transactions in the Ethereum blockchain.

Types of Ethereum Transaction

The transactions can be classified into three general types that are listed below and defined further.
  1. Funds Transfer
  2. Contract Deployment
  3. Function Execution

Funds Transfer

This type of transaction takes place whenever an account sends some funds (in form of ether) to another account. This transaction has a value associated with it but does not have any data. For example, when account A sends some money to account B for buying something. The gas price is set by the sender.

Contract Deployment

Whenever a contract is deployed on the Ethereum network, this transaction takes place. It has data that is the bytecode of the smart contract. There is no recipient for this kind of transaction. The gas limit must be enough for deploying a contract.

Function Execution

After a contract is deployed on Ethereum, its functions can be called. When a function is called by an account, then this type of transaction occurs. The transaction is directed towards a contract account, therefore the recipient is a contract address. The data contains the function name and its arguments.

So, friends, this was a general classification of transactions. Up till now, you must have got an idea of a transaction and its components. The steps of a transaction generation till its confirmation can be listed as below:

  1. A transaction is initiated by the sender. The sender’s account provides important information such as recipient address, data, value, and gas limit. After generation, a hash is created that is called a transaction hash.
  2. The transaction has is a unique identifier for a transaction. An example of this hash is given below:

0x2446f1fd773fbb9f080f674b60c6a033c7ed7427b8b9413cf28a2a4a6da9b56c

  1. The transaction generated is transmitted to the network and added to the transactions pool waiting to be confirmed.
  2. A miner picks transactions for the pool to add to the block. This verifies the transactions. When there are a lot of transactions, the waiting time is more. Therefore, a transaction with a higher gas price would be picked first by a miner. In this way, the miner will get more money.
  3. A number called block confirmation number is given to a verified and added transaction. This shows the number of blocks created after the block in which the transaction was added. As the chain length of the blockchain increases, the transaction becomes more and more trusted and immutable.

This is the process through which a transaction passes. I hope you have an idea of it's working. Next time I will be here with another topic. Till then, take care!

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir