Ethereum: How do I read the block transaction
Ethereium is a decentralized platform that allows you to stretch and expose the intense counteracts that are independent when counteracting predatory rules. One of the key components of Ethereum is Blockchain, who is the main sister of the data for all transactions on the network.
Block – this collection of one or more transactions and it baptizes in a transaction of a transaction called blockchain. Each block contains a unique Idyntifiper (also existence as “hash”), which refers to the block pre -trial, the river of the blocks.
To read the block transaction, you need to know a few things:
- Block Block
: Block Block – This is a unique actifier who introduces a concrete block of blockchain.
- hash
: While wounds, each block has a hash that affects the foreground. This hash can be used for the message of the block and killed that it is rotating.
- The first transaction in the block has index 0, at a time when the publication transaction is indices that are extended to one.
Here are a few can read the block transaction:
Method 1: Using a feature Blockhash
The ‘BlockhashRetinds feature is a six -stack that has a block. This can be used to listen to the block and be killed that he is properly inherited.
Javascript
CONST Blocknumber = 12345;
CONST BLOCKHASH = Web3.eth.blockhash (Blocknumber);
Console.log (blockhash); // Extract a six -tank stack by introducing the Hush block
Method 2: Using property txcount
Txcount
withdraw a number of transactions to the block. This can be used to listen to the block and be killed that he is properly inherited.
`Javascript
CONST Blocknumber = 12345;
CONST TXCOUNT = Web3.eth.gettransctionCount (Blocknumber);
Console.log (TXCOUNT); // extracts a number of transactions
Method 3: Using a library, such as euters.js
Ethers.js – a popular JavaScript library for reciprocity with Ucerevya and Transaction Ethereum. It introduces several methods for block transaction in volume:
`Javascript
CONST Web3 = New Web3 (Window.Thereum);
CONST Blocknumber = 12345;
CONST txhash = web3.eth.blocktransctionreceipt (blocknumber) .transction.hash;
Console.log (Txhash); // extracts a six -tank stack that has a transaction hash
Method 4: Using Consoli Magazine
You can also use the Console.log
feature for the transaction of the block. This method is smaller and should be used with the direction:
`Javascript
CONST Blocknumber = 12345;
web3.Tlocktransctionreceipt (blocknumber) .transaction.hash;
console.log (web3.eth.abi.rawransction); // extract data from an unlimited transaction
In the conclusion, the transaction of the block into Ethereum includes the accuracy of the Uncouragey Eve for the block and its content. Using one or more methods, you can turn to the condition of the blockchain and build an intensive contract.
Here are the fragments of the code of the code that demonstrates how to read the block transaction:
`Javascript
CONST Web3 = New Web3 (Window.Thereum);
CONST Blocknumber = 12345;
Console.log (Block $ {blocknumber} has $ {web3.eth.ettransctioncount (blocknumber)} transaction:);
web3.thlocktransctionreceipt (blocknumber) .transaction.hash.forech ((TX) => {{{{
Console.log (TX);
});
Holly, this is useful! Tell me if you have a question -you have to be more than you need.