Hemera Doc
  • 👋Welcome
    • Introduction
    • Quick Start
    • Account Centric Indexing Protocol
      • What is Account-Centric Indexing?
      • Why "account-centric" indexing?
      • The advantages of Account-Centric Indexing
      • What's next for account-centric indexing?
      • Why create a new protocol here?
      • The Hemera Network
        • Network Roles
        • Indexers
        • Validators
        • Proprietary models & knowledge
        • Proprietary data and labels
        • Smart Contracts
        • Key roadmap items
        • Supported blockchains
      • Example Hemera use cases
        • SocialScan Explorers
        • Anti-sybil UML algorithm
        • Ethereum long term DA
        • EVM chain history preservation
        • Ecosystem AI Agents
        • User-defined AI Agents
  • 👩‍💻Developer Resources
    • Smart Contract Developers
    • EVM-compatible chains
      • Blockchain explorers
      • SocialScan explorer API doc
      • Ecosystem AI Agents
    • Dapp developers
    • User-defined Agent creators
    • AVS Operator
  • 🖥️Hemera Indexer
    • Introduction
    • Installation
      • Prerequisites
      • Install & Run
      • Export Result
    • Configurations
    • Benchmark
    • Data Class
      • Raw Data Tables
        • Blocks
        • Transactions
        • Logs
        • Traces
      • Generated Tables
        • Contract Internal Transactions
        • ERC20 Token Transfers
        • Tokens
        • ERC20 Token Holders
        • ERC721 Token Transfers
        • ERC721 Token Holders
        • ERC1155 Token Transfers
        • ERC1155 Token Holders
        • Address Coin Balances
        • Address Token Balances
        • Address Current Token Balances
        • Daily Wallet Address Stats
        • Contracts
      • Other Tables
        • Inscriptions
        • Bridges
          • L1 to L2 Transactions
          • L2 to L1 Transactions
          • Optimistic Rollup Data Availability Batches
          • Optimistic Rollup State Batches
    • Use Cases
      • UniSwap V3
        • Data Class
        • Trigger and Function
        • Run & Query
      • ENS
        • Data Class
        • Trigger and Function
        • Run & Query
      • OpenSea
        • Data Class
        • Trigger and Function
        • Run & Query
      • Deposit to L2
        • Data Class
        • Trigger and Function
        • Run & Query
      • User Profile
  • UDFs - User Defined Functions
    • Introduction
    • Components of UDFs
    • Building User Defined Functions(UDF)
    • Testing and Running UDF
    • Troubleshooting and Support
    • Supported UDFs
    • FAQs
  • 😄About us
    • The story behind building Hemera
    • Partners & Backers
    • Partnership inquiries
    • Hemera Powered Explorers
    • Active Developer Hackathons
    • Developer Contribution
  • Documentation feedback
Powered by GitBook
On this page
  • Unit Tests
  • Integration Tests
  • Running the hemera indexer with UDFs
  • Steps to Running
  1. UDFs - User Defined Functions

Testing and Running UDF

Before deploying your UDF, it's important to test it to ensure it works as expected.

Unit Tests

Write unit tests for your processing logic:

import unittest from your_udf_jobs import YourCustomJob from hemera.dataclasses import Transaction

class TestYourCustomJob(unittest.TestCase):

def test_process(self):
    # Setup test data
    transactions = [
        Transaction(hash='0x1', value='0xde0b6b3a7640000', from_address='0xabc'),  # 1 Ether
        Transaction(hash='0x2', value='0x1bc16d674ec80000', from_address='0xdef'),  # 2 Ether
    ]
    job = YourCustomJob()
    # Run the process method
    result = job.process(transactions)
    # Assert the results
    self.assertEqual(len(result), 1)
    self.assertEqual(result[0].field1, '0x2')
    # Add more assertions as necessary

if name == 'main': unittest.main()

Integration Tests

Run the indexer with your UDF in a test environment:

  • Use a test blockchain network (e.g., Ganache, or a testnet) to provide blockchain data.

  • Use a test database to avoid affecting production data.

  • Run the indexer and verify that your UDF processes data correctly and stores it in the database.

Running the hemera indexer with UDFs

Once you've tested your UDF, you can deploy it as part of the Hemera Indexer in your production environment.

Steps to Running

  1. Ensure Code is in the Correct Location: Place your UDF code in the appropriate directories within the Hemera Indexer project.

  2. Update Configuration: Make sure any configuration files or scripts include your UDF.

  3. Update Database: Apply any new database migrations.

  4. Restart the Indexer: Restart the Hemera Indexer to pick up the new UDF.

Using Docker

If you're using Docker to run Hemera Indexer:

  • Update the Docker Image: Include your UDF code in the Docker image.

  • Rebuild the Image:

docker-compose build
  • Restart the Containers:

docker-compose up -d

Running from Source

  1. Install development tools as specified in the Hemera documentation.

  2. Prepare PostgreSQL and other dependencies.

  3. Setup the enviroment:

make development
source .venv/bin/activate

Run the hemera Indexer through CLI:


 python3 hemera.py stream \  --provider-uri https://ethereum.publicnode.com \  --start-block 12598072 \  --end-block 20804486 \
  --output-types UniswapV3Token \
  --block-batch-size 10000 \
  --postgres-url postgresql://hemera:123asd@localhost:5432/demo \
  --output postgres \
  --config-file config/indexer-config-template.yaml

Another way to test whether your UDFs are correctly configured and functioning is by checking the output folder or the PostgreSQL database. If you're using a PostgreSQL database, you can query the relevant table to verify the data.

For more detailed setup and deployment options, refer to the Installation section.

PreviousBuilding User Defined Functions(UDF)NextTroubleshooting and Support

Last updated 5 months ago