Last updated
Last updated
is a framework for building indexer apps using TypeScript (or JavaScript). Its main strength is its versatility - it can be used to rapidly develop a simple smart contract indexer or collect particular block data, but also to index data from the entire blockchain or compose multiple indexers.
Before you start, you will need the following:
16 or higher
(to check the stored data). If you want to use Dappetizer with PostgreSQL, please also check our to learn more.
For this example, we will create a simple app that tracks registrations of new domain names in . Start by creating a new folder:
Install Dappetizer itself:
To initialize a new indexer for our registration contract, run Dappetizer with the command:
An consists of:
Indexers which can act on new contract calls or whole blocks. An indexer is automatically created for you when you run dappetizer init
The database entities that will be used by the indexers to store data.
To add the Registration
entity to the module, you will need to edit the index.ts
file and add Registration
to the dbEntities
property:
The smart contract we are going to index has a fairly simple structure. The buy
entrypoint accepts a few parameters, like the label (i.e. the domain name without .tez
), the new owner and the registration duration in days.
If you wish to learn more details about this particular contract, you can check:
The final file will look like this:
All we need to do now is compiling the source code...
... and running the indexer app.
If everything works, you should see a console output showing the indexing progress with each individual block. For now, let's kill the process by Ctrl+C after letting it run for a short while.
To select what registrations have been saved by the indexer, we will run a short SELECT query:
And get the following as a result:
As you can see, the indexer is saving successful registrations. If you run the indexer again it will pick up from the last indexed block and continue on until it reaches the latest block. After that, it will wait for each new block and index it as well.
We will have one that represents a successful domain registration:
Our generated indexer module already has an indexer for the contract in tezos-domains-indexer.ts
. It contains an empty method called indexBuy
where we can put the code that will take care of saving the parameters of each call to the database using . We can get rid of the remaining indexing methods which we won't need for this example.
To check the generated data, we can use the :