DipDup Framework

repository·next·Indexed 42 days ago

https://github.com/dipdup-io/dipdup

A Python framework for building efficient, selective smart contract indexers for dapps. DipDup reduces boilerplate by focusing on business logic and optimizing data retrieval from blockchain APIs. It supports multiple storage modes, including in-memory, SQLite, and a full stack with PostgreSQL and Hasura via Docker Compose. Version 8.6.1.

Tokens
115.2K
Snippets
437
Records
655
Agent score
55%

What's inside DipDup

  1. Overview of DipDup

    next

    DipDup is a Python framework designed for building smart contract indexers. It allows developers to focus on implementing business logic by abstracting away the boilerplate required to store and serve blockchain data.

    Key features include:

    • Selective Indexing: Only the required data is requested, which leads to faster indexing times and reduced load on underlying blockchain APIs.
    • Business Logic Focus: Minimizes the need to write low-level data storage and serving code.
  2. Use GenQL to generate a typed SDK for DipDup

    next
    GenQL is a library and CLI tool that automatically generates a fully typed SDK with a built-in GraphQL client. It is recommended for use with DipDup on the client side, particularly when working with Hasura-based endpoints. The CLI generates a ready-to-use package, compiled and prepared for NPM publication.
  3. What is an Index in DipDup

    next

    An index is a core DipDup entity that connects your data inventory with the rules for handling blockchain data. It defines three main components:

    1. What to track: Contracts, events, operations, etc.
    2. Where to get the data: The datasource (e.g., evm, starknet, tezos).
    3. How to process it: A set of handlers.

    A handler is a callback function triggered when new data arrives from the datasource. Handlers receive the data item as an argument and can perform actions like database storage, notifications, or external API calls. Handlers are linked to specific patterns like entrypoints, events, or operations.

  4. What is a selective blockchain indexer and DipDup?

    next

    A selective blockchain indexer is an application designed to extract and organize specific blockchain data from multiple sources instead of processing the entire blockchain. This approach reduces storage and computational overhead compared to full node indexing and enables efficient querying for specific use cases.

    DipDup is a framework designed to help you implement these selective indexers by acting as a customizable filter that captures and stores only the specific blockchain data you require.

  5. What is MCP integration in DipDup?

    next

    The Model Context Protocol (MCP) integration allows LLMs (like Claude, Copilot, or Cursor) to connect directly to your DipDup indexer. This enables AI assistants to understand your indexer's configuration, query indexed blockchain data, and execute custom tools you define.

    DipDup uses three MCP primitives:

    • Resources: Application-controlled data/content that clients can read as context.
    • Tools: Model-controlled executable functions (e.g., performing computations or querying the database).
    • Prompts: User-controlled reusable prompt templates.
  6. How hooks work in DipDup

    next

    Hooks are user-defined callbacks that are not linked to any specific index. They allow you to execute logic or SQL scripts in response to system-wide events or manual triggers. There are two categories of hooks:

    1. System hooks: Reserved hooks that fire on system-wide events (e.g., process restart). They are not atomic, cannot be fired manually, and cannot be scheduled via the job scheduler.
    2. User hooks: Custom hooks defined in your configuration. They can be triggered manually using ctx.fire_hook or automatically via the job scheduler.

    By default, hooks attempt to execute SQL scripts located in a corresponding subdirectory within the sql/ directory.

    # Example of defining a user hook in dipdup.yaml
    hooks:
      calculate_stats:
        callback: calculate_stats
        atomic: False
        args:
          major: bool
          depth: int
  7. Understand DipDupContext and its variants

    next

    DipDup provides several context objects used to pass state and configuration to various callbacks during execution.

    • DipDupContext: The common execution context used for both handler and hook callbacks. It contains the global configuration, the package, available datasources, and the transaction manager.
    • HandlerContext: A specialized context for handler callbacks. It extends DipDupContext by adding handler_config, which contains the configuration specific to the current handler.
    • HookContext: A specialized context for hook callbacks. It extends DipDupContext by adding hook_config, which contains the configuration specific to the current hook.
    • McpContext: The execution context for MCP (Model Context Protocol) tools, resources, and prompts. It includes the running McpServer instance and the HttpDatasource (DipDup API).
  8. Use optional items in operation patterns

    next

    Pattern items can include an optional field. This allows the pattern to continue matching even if that specific item is not found in the operation sequence. This is useful for skipping irrelevant external or internal calls.

    Limitation: Optional items cannot be followed by operations that are ignored by the pattern.

    # dipdup.yaml
    pattern:
      # Implicit transaction
      - type: transaction
        destination: some_contract
        entrypoint: mint
      # Internal transactions
      - type: transaction
        destination: another_contract
        entrypoint: transfer
      - type: transaction
        source: some_contract
  9. Perform heavy computations in a separate process

    next
    While DipDup provides a built-in job scheduler for deferred calculations, these jobs execute within the same asyncio loop as the rest of the framework. To prevent heavy computations from impacting indexing performance, you should run these tasks in separate services. Refer to the Services documentation for details on running multiple services in DipDup.