** Ethereum: Chainsstate vs Blocks fold
Ethereum ecosystem, both Chainstate and Blocksfolder, are essential components to store and obtain Blockchain data. However, they serve for different purposes, so it is important to understand their disagreement before reading and showing the web front.
Chainsstate
The Chainstate folder is the most important storage mode of the Ethereum mode containing a variety of information, such as:
The Chainstate folder stores this information in a hierarchical structure, each file depicts a block or block chain. The files are divided into lists such as State_root, State_tree and TX_Count.
prevented the folder
Blocksfolder is responsible for storing individual blocks. Each block contains a variety of data such as:
Blocksfolder stores each block in a separate file, each file describes one block.
General Differences
Although both folders hold the same type of information, there are basic differences:
Reading and Displaying Information
You need to use Chainsstate and Blocksfolder to read and show the network in front, such as Blockchain Explorer. Here is an example of how this is done with a solid (Ethereum programming language) and web3.js:
`Javascript
Bring * web3 from web3;
Const web3 = new web3 (new web3.providers.httpprovider (‘
// Get Chainsstate
Const chinstate = web3.eth.chaystate;
// Get all blocks
Async’s feature of Getbocks () {
Const txlist = Wait web3.et.gettraSactionlist ();
for (let i = 0; i
Const block = txlist [i] .block;
// Read the Chainsstate Block Information
Console.log (block.itimestamp);
}
}
// Get a particular block under her bag
Async’s feature of getblockbyhash () {
Const blockhash = ‘0x1234567890ABCDEF’;
Const blockdata = wait for web3.eth.getblock (blockhash, true);
// Read Blockfolder Block Information
Console.log (blockdata.hash);
}
`
Information that appears in front of the network
You need to use a web3.js ethical library to show web information, such as Blockchain Explorer, to interact with the Ethereum network and scan certain information. You can then use HTML5 fabric or other technology to visualize data.
Here is an example of how you can show the block time tag on HTML5 fabric:
`Html
Const CTX = Document.getelementbyid ('block -Itimestamp'). GetContext ('2D');
Wallval (() => {
web3.eth.getbalance (web3.eth.ccount.getaddress (), (Error, balance) => {
If (error) {
Console.error (error);
} Else {
Const Timestamp = new date (). Gettime () / 1000;
CTX.Clearrect (0, 0, fabric.theks, fabric.height);
ctx.beginpath ();
ctx.arc (canvas.width / 2, canvas.height / 2, Math.min (time tag, balance), 0, 2 * Math.pi);
ctx.fillstyle = 'black';
ctx.fill ();
}
});
}, 1000); // update every second
This code scans the current block time tag and uses it to draw a circle in the HTML5 fabric element. You can customize the appearance of the circle by editing CTX.