Introduction to Ethereum Data Importer

DZone 's Guide to

Introduction to Ethereum Data Importer

Ethereum is popular for creating decentralized applications and running smart contracts. However, it can have trouble performing complex analytical queries.

· Big Data Zone ·
Free Resource

Ethereum is one of the popular blockchain platforms that runs smart contracts. It is used by many companies to create dapps (decentralized applications).

Query Ethereum Public Data

Libraries like Web3j can be used to fetch blocks and transactions and perform basic operations. But complex analytical queries like find top five miners in a particular block range can't be performed. 

One possible solution could be to save blocks and transactions data in another database and perform complicated queries there.

Kundera With Ethereum

The Kundera-Ethereum module can be used to import block data to any Kundera-supported database and also perform JPA queries over it.

Kundera uses Web3j under the hood to fetch block data and the JPA layer to store the data.

Add dependency:


Define kundera-ethereum.properties file in the classpath.

Sample file to store data in MongoDB:


## generate Block and Transaction tables 

## Drop existing tables

## RPC HTTP end point or IPC socket file location or infura end point can be specified

All set! Start importing blocks now.

Import Data

Import all the data starting from the genesis block:

BlockchainImporter importer = BlockchainImporter.initialize();

Import the data from block 1,000,000 block 2,000,000th:

BlockchainImporter importer = BlockchainImporter.initialize();
importer.importBlocks(BigInteger.valueOf(1000000), BigInteger.valueOf(2000000));

Query Data

We'll consider database-specific queries and JPA queries.

Database-Specific Queries

For example, let's find the top five miners with the number of blocks mined.

{$group:{_id:"$miner", numBlocksMined: { $sum: 1}}},
{ $sort : { numBlocksMined: -1 }},
{ $limit : 5 }

JPA queries

Let's find gas and gasPricefor a particular user in a particular block.

Query query = em.createQuery(
            "Select t.gas,t.gasPrice from Transaction t where t.blockNumber='0x455a56' and t.from='0x6c15291028d082e1b9358e19f15c83b9c54f2b35'");
List<Transaction> results = query.getResultList();

For more details check Kundera with Ethereum Blockchain.

kundera ,ethereum ,blockchain ,nosql ,mongodb ,big data ,data analytics

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}