Ethereum: What is the difference between chainstate and blocks folder?

Ethereum: understanding of the chain folder and blocks

In Ethereum’s ecosystem, both Chainstate and ‘Blocksfolder’ are crucial components to archive and recover the blockchain data. However, they are used for different purposes, making them essential to understand their differences before immersing themselves in reading and viewing data on a Frontend Web.

Cainstate

The cainstate 'folder is the central repository of the state of Ethereum, which includes various information such as:

  • Height of the block

  • Block number

  • TimesTamp block

  • Transactions count

  • Gas ​​price

  • Non -confirmed transactions count

The foldercainstate ‘stores these data in a hierarchical structure, with each file that represents a block or a section of the blockchain. The files are organized in the directory as state_root,State_Tee and TX_COUNT.

Block folder

`Blocksfolder 'is responsible for storing individual blockchain blocks. Each block contains various data such as:

  • Block hash

  • Hash of the previous block (parent hash)

  • Transactions count

  • Non -confirmed transactions count

  • Gas ​​price

  • Timestamp

Blocksfolder 'stores each block in a separate file, with each file that represents a single block.

Key differences

Ethereum: What is the difference between chainstate and blocks folder?

While both folders archive the same types of data, there are key differences:

  • Cainstateis the central repository of the state of Ethereum, while blocksfolder will store individual blocks.

  • The files inCainstatehave a hierarchical structure, with each directory containing subdirectory and files, while 'Blocksfolder' has separate files for each block.

Reading and viewing of data

To read and view the data on a front web such as BlockchaIn Explorer websites, you will have to access both thecainstateand a 'blocksfolder' folder. Here is an example of how you can do it using solidity (the programming language Ethereum) and web3.js:

Javascript

import * as web3 from «web3»;

Const Web3 = New Web3 (New Web3.providers.httpprovider (‘

// Get the chain chain

Const Chainstate = web3.eth.chainstate;

// Get all the blocks

Getblocks asynchronic function () {

Const Txlist = Wait Web3.eth.gettransationlist ();

for (let i = 0; i

Const Block = txlist [i] .block;

// Read the data of the block of Cainstate

Console.log (block.timestamp);

}

}

// Get a specific block from his hash

Getblockbyhash () {) asynchment function

Const Blockhash = ‘0x1234567890Abcdef’;

Const Blockdata = Abswait Web3.eth.getblock (Blockhash, True);

// Read the data of the Blocksfolder block

Console.log (Blockdata.Hash);

}

`

viewing data on a front web

To view the data on a web Frontend as BlockChand Explorer websites, you will have to use the web3.js "Ethers to interact with the Ethereum network and recover specific data. It is therefore possible to use the HTML5 canvas or other technologies to view data .

Here is an example of how you can view the block TimesTamp using the HTML5 canvas:

`HTML

CONT CTX = Document.getelementyid (‘Block-Timestamp’). Getcontext (‘2D’);

sectinterval (() => {

Web3.eth.getbalance (Web3.eth.acount.egetAddress () (Error, Balance) => {

If (error) {

console.error (error);

} other {

Const TimesTamp = New Date (). Throw () / 1000;

CTX.CLECARTECT (0, 0, Canvas.width, Canvas.height);

CTX.BEGINPATH ();

CTX.ARC (CANVAS.WIDTH / 2, CANVAS.HEIGHT / 2, MATH.min (TimesTamp, Libra), 0, 2 * Math.pi);

Ctx.fillstyle = ‘black’;

CTX.FILL ();

}

});

}, 1000); // Update every second

`

This code recovers the Timestamp of the current block and uses it to draw a circle on an HTML5 canvas element. You can customize the appearance of the circle by changing theCTX.

Dejar un comentario

Tu dirección de correo electrónico no será publicada.