Ethereum transaction Calculation hash
=======================================
The calculation of the hash of the Ethereum transactions can be a little complicated, especially for the new ones for Ethereum. In this article, we will explore Howereum calculates transaction hashes and give examples to help you understand the process.
Understanding Ethereum transactions
————————————
In Ethereum, each block contains several transactions, known as “messages”. Each message is a sequence of entries (called “data”) followed by a signature (known as “hash block”). The hash of the block is calculated using a complex algorithm that takes into account the previous data and hashs.
The calculation algorithm of the transaction hash
———————————–
Ethereum’s calculation algorithm is based on the following steps:
- Hash functions
: Ethereum uses two types of hash functions:
* Keccak-256
: a 256-bit hash feature designed to be quickly in terms of calculation.
* Blake2b
: a 256 -bit hash feature designed to be safe in memory and fast.
- MESSAGE NORMALIZATION : Each transaction is normalized in a byte picture, which represents the entry data.
- Calculation of the Hash block
: The hash of the block is calculated by the concatenation of the hash of the anterior block, the message header (a 4-bit signature of the block) and the normalized input data.
Example: Calculation of the hash of a single transaction
————————————————– ———
Let’s say we have a transaction with the following entries:
Transactions_id":
0x1234567890ABCDEF
De la:
0x9876543210fedcba
All:0x876543210fedcba
Value":
0x1234567890ABCDEF”
Input data would be:
[0x1234567890ABCDEF, 0x9876543210FEDCBA, 0x876543210FEDCBA]
Next, we concise the block of the block (using Keccaak-256
) with the message header (a signature) and the normalized input data:
Block_hash = keccak-256 (0x1234567890abcdef + 0x9876543210fedcba + 0x876543210fedcba)
Message_head = 0x67454bf
Normalized_input_data = [0x1234567890ABCDEF, 0x9876543210FEDCBA, 0x876543210FEDCBA]
Then, we concateate the hash of the concatenated block with the normalized input data to form the transaction hash:
Transaction_hash = keccak-256 (block_hash + message_head + normalized_input_data)
The use of an instrument or library
——————–
To calculate the hash of the transaction, you will need a tool or library to accept the Ethereum hash functions. Some popular options include:
Ethhasha: a Python library that calculates Hashes Ethereum.
- blockchain (a node.js library): it offers a convenient API for working with Ethereum data structures.
In summary, Ethereum calculates the transaction hash by concatenation of the hash of the previous block, the message header (a signature) and the normalized input data. The resulting hash is then calculated using two hash functions: Keccak-256 and Blake2B. Following the steps of the thesis and using a tool or library to help, you should be able to calculate the hash of any Ethereum transaction.
Please note that this is just an introduction of the process. For more advanced topics, such as smart contracts and blockchain programming, please see official resources and documentation from Ethereum developers.