Quick Start
The Hemera Protocol offers a streamlined approach for developers to build data-driven dApps. The Hemera Indexer, a core component of this protocol, facilitates parallel execution of User-Defined Functions (UDFs) alongside essential indexing tasks, enhancing performance and simplifying complex data workflows.
To get started with Hemera Indexer and UDFs, you can follow this guide:
Set Up Your Development Environment
Clone the Repository:
Install Python 3.9:
Ensure Python 3.9 is installed on your system. You can download it from the official Python website.
Building from Source is recommended when getting started with UDFs.
Building from Source
Install Dependencies and Activate Environment :
Navigate to the cloned repository and run:
Replace
<your-environment>
with the name of your virtual environment.Switch Branches:
Depending on your development needs, you may switch between branches:
Replace
<branch-name>
with the desired branch.
Writing a UDF
User-Defined Functions (UDFs) in Hemera are designed to streamline the extraction, transformation, and analysis of blockchain data. Here’s how you can create a UDF by defining a dataclass
, integrating a model
, and writing the job logic
.
Define a Dataclass
A dataclass
is used to structure the data you will process. It defines the schema for the blockchain data extracted by the Hemera Indexer.
This example defines a schema for transactions with attributes like block number, transaction hash, sender, receiver, and value.
Learn more about Dataclass in the UDF: Components of UDFs
Create a Model
A model
encapsulates the processing logic to transform or compute derived values from the raw data.
This TransactionModel
processes the TransactionData
and includes additional logic like calculating transaction fees.
Learn more about Model in the UDF section: Components of UDFs
Write the Job Logic
The job logic
is where the UDF interacts with the Hemera Indexer to fetch and process blockchain data.
Here’s what’s happening:
The
run
method processes each block’s transactions.Raw blockchain data is mapped to the
TransactionData
dataclass.The
TransactionModel
performs transformations, and the results are formatted for output
Learn more about Job Logic: Components of UDFs
Running the Indexer with UDFs
Once your UDF is ready, it can be deployed and executed alongside the Hemera Indexer. The following example demonstrates how to run the indexer with a demo job:
Command to Execute a Demo Job with UDF
CLI Parameters:
--provider-uri
: The Ethereum node URL used to fetch blockchain data.--start-block
and--end-block
: The block range for processing.--output-types
: Specifies the job type, heredemo_job
, to indicate the UDF logic applied.--block-batch-size
: Number of blocks processed in each batch for efficient indexing.--postgres-url
: PostgreSQL connection URL to store processed data.--output
: Specifies the output format, such aspostgres
.--config-file
: Path to the Hemera configuration file.
Learn more about the CLI Parameters: Configurations
Leveraging SocialScan Developer APIs
Hemera offers APIs to build advanced blockchain explorers with features like real-time transactions, token activity, and customizable wallet activity focus.
API Documentation:
Access detailed API documentation to integrate these features into your applications.
Example Applications
Developers can utilize Hemera for various applications, including:
DeFi Analytics:
Track liquidity pools and yield metrics.
NFT Monitoring:
Visualize collections, sales, and holder activity.
Social Graphs:
Map on-chain interactions and relationships.
Last updated