Analysis of Ethereum Blockchairs into Sqlite Databases: Effective Approach

The analysis of blockchairs, the analysis of blockchairs. In this article,

Why sqlite3?

Sqlite3 is an excellent choice for this task as a result:

  • Relational database capacity : easy to query, create, update and delete in the database.

2.

  • Support for multiple databases : more databases can handle at the same time.

  • Easy and fast

    Ethereum: Reliable, efficient way to parse the blockchain into a SQL database

    : sqlite3 is optimized for performance.

Ethereum Blockchain Data Structure

Before we get into the implementation details, understand how Ethereum blockchairs are structured:

1.

  • Each Block Contains:

* Time Stamp

* The Previous Block Hashja (yes partenthash)

* Number of Transactions in the Block (NumtransectionCount)

* List of Transactions Within The Block (Transactions')

Blockchain Analyst Execution

We use Python as our program language, together with sqlite3 for database operations. The Eth-Bocks directory is also used to retrieve the Ethereum blockchain data.

Python

Import Sqlite3

From Datetime Import Datetime

Class Blockparser:

Def __init __ (self):

Self.conn = sqlite3.connect (': memory:')

Self.cursor = self.conn.cursor ()

Def parse_blockchain (self, blockchain_url):

Roll First Block from Blockchain URL

Block = eth_blocks.get (blockchain_url)

If the Block is Not:

restore

Create a table for the database

Self.create_table ()

Insert data into the database

Self.inSert_Data (block.timestamp, block.hash, block.parenthash, block.numtransectioncount, block.transections)

Return

DEF CREATE_TABLE (SELF):

"" "Create a table with the columns you need." "

sql = "" "

Creating a table if there is no blockchain_data (

ID Integer Primary Key Auto Installation,

The time stamp text is not zero,

Parent_hash text is not zero,

Num_transections Whole Number is Not Zero,

TEXT TRANSACTIONS

);

"" "

Self.curssor.execute (sql)

Self.conn.commit ()

Def Insert_Data (Self, Timestamp, Hash, Bracket, Numtransctions, Transactions):

"" "Insert data into the blockchain table." "

sql = "" "

Insert Blockchain_data (Time Stamp, Parent_hash, Num_transctions, Transactions)

Values ​​(?,? ,,? ,,?);

"" "

Self.curssor.execute (sql, (timestamp, hash, numtransctions, transactions))

Self.conn.commit ()

An example of use

Analyst = blockparser ()

Url = '

If the analysis.parse_blockchain (URL):

Print ("Blockchain Successfully Analyzed!")

Other:

Print ("Error Analysis of the Blockchain.")

To Optimize Efficiency

The special implementation is effective for most uses, there are some optimizations that can be done to further improved performance:

.

  • Using a more effective database scheme

    :

3.

METAMASK CONTRACT PROBLEM METAMASK