Dappetizer 1.3.0: Hasura integration and faster contract indexing

Dappetizer 1.3.0: Hasura integration and faster contract indexing

Another month has passed, and another big update on Dappetizer is here!

You can now expose your data without writing a line of code with Hasura (since 1.2.0), and contract indexing has been made a lot faster with the new boost functionality (added in 1.3.0). Let’s go through the two new features to see what they are all about!

Exposing data with Hasura

Hasura lets you instantly create APIs for your existing database, with no coding required. This is great when you need to develop things quickly and when the database structure closely resembles the desired API. Check and check for smart contract indexers!

Step 1: Hasura comes with a neat Docker image, so we will just use that for our example. Start by running the image in your favorite terminal:

docker run -d --name dev-hasura -p 8080:8080 \
  -e HASURA_GRAPHQL_DATABASE_URL=postgres://pguser:pgpassword@pghost:5432/postgres \
  -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
  hasura/graphql-engine:latest

As you can see, this runs Hasura locally on port 8080. Don’t forget to replace pguser, pgpassword, pghost with your PostgreSQL connection details!

Step 2: We will configure our existing Dappetizer project to talk to Hasura and expose the API automatically. We will just need to add a hasura section to the configuration file:

const config: DappetizerConfigUsingDb = {
    ...
    hasura: {
        url: 'http://localhost:8080/',
        autotrackEntities: true,
        dropExistingTracking: true,
    }
};

This will connect to the Hasura instance we set up earlier, but you can connect to any instance.

Step 3: Now, we just need to run the indexer:

npx dappetizer start

The framework will automatically call Hasura to create an API based on the data entities you have registered in your indexer. Opening https://localhost:8080 will give you the Hasura UI. To test it, let’s run this query that fetches the latest indexed block:

query MyQuery {
    blocks(limit: 1, order_by: {level: desc}) {
        level
        timestamp
        hash
        predecessor
    }
}

For a full working example of Hasura integration, check out our tezos-domains-hasura example.

Contract indexing boost

Dappetizer 1.3.0 can now index contracts much faster (by a factor of 10x or 100x for some contracts) by simply fetching only the needed blocks. It uses a boost provider API behind the scenes to fetch the relevant contract operations and use them to figure out what block levels are required.

We currently support TzKT as a boost provider, with TezGraph support in the works. It’s important to note that a Tezos node is still the primary source of truth. This new feature just limits the number of fetched blocks and can always be turned off.

Newly scaffolded projects already have this functionality on by default. To enable it in an existing project, just add contractBoost to the indexing section of your config file:

contractBoost: {
    type: 'tzkt',
},

Thanks

Our many thanks go to Tezos Foundation for supporting this project and to everyone who provided feedback!

If you want to let us know your suggestions, ask a question, or want to say “hi,” come join us on our Discord server!

1 Like