The power of Yaci Store is that it can be used as a library in your own application. This allows you to build your own application on top of Yaci Store. You have full control over what data you want to index. This is achieved by using modular architecture. Not only you can include required stores in your application, you can also override the default behavior of the stores. For example, you can override the default behavior of the Utxo store to store utxos in a different database, or store only utxos specific to an address or store metadata with specific labels. This is achieved by using the spring framework's dependency injection feature.
In this guide, we will show you how to use Yaci Store as a library in your own application.
Sample applications:
- Sample Metadata Indexer project using Yaci Store as a library.
- A scoped indexer for Ada Handler
- Java 21
- Spring Boot 3.2.x (Tested with Spring Boot 3.2.0, 3.2.1, 3.2.2)
You can use the Spring Initializr to create a Spring Boot application.
Apart from standard spring boot dependencies, add the following dependency to your build.gradle
or pom.xml
file.
This will add the Yaci Store Core modules to your project as a dependency. Core modules are responsible for fetching data from the blockchain and
publishing them as events.
implementation 'com.bloxbean.cardano:yaci-store-spring-boot-starter:<version>'
For pom.xml
<dependency>
<groupId>com.bloxbean.cardano</groupId>
<artifactId>yaci-store-spring-boot-starter</artifactId>
<version>{version}</version>
</dependency>
Now you can add the required store starters to your project. For example, if you want to add the metadata store, add the following dependency.
implementation 'com.bloxbean.cardano:yaci-store-metadata-spring-boot-starter:<version>'
For pom.xml
<dependency>
<groupId>com.bloxbean.cardano</groupId>
<artifactId>yaci-store-metadata-spring-boot-starter</artifactId>
<version>{version}</version>
</dependency>
Note: You can add multiple store starters to your project. Full list of supported starters can be found here
Add following flyway configuration to your application.yml
file. (Mandatory)
spring:
flyway:
locations: classpath:db/store/{vendor}
out-of-order: true
apiPrefix: /api/v1
Note: If you are using Yaci Store 0.0.11 or earlier, use classpath:db/migration/{vendor}
as the location.
You can add your application specific flyway configuration as well. For example, you may want to add another location for your application.
Flyway location
property allows you to specify multiple locations.
Download the application.properties
file from the release section and place it in a folder named "config" in your project root directory.
The application will automatically pick up the configuration file.
Alternatively, you can add all yaci store specific configurations in application.yml
file as well.
Update configuration file with your own values. Some of the key properties are mentioned below.
store.cardano.host=preprod-node.world.dev.cardano.org
store.cardano.port=30000
store.cardano.protocol-magic=1
Uncomment and edit the following properties to configure the database connection.
spring.datasource.url=
spring.datasource.username=user
spring.datasource.password=
The followings are optional configuration. You can leave them as-is.
Configure genesis files location. This is required for few stores like Utxo store, account aggregate etc.
store.cardano.byron-genesis-file=/Users/satya/cardano-node/preprod/files/byron-genesis.json
store.cardano.shelley-genesis-file=/Users/satya/cardano-node/preprod/files/shelley-genesis.json
The following properties are required for node-to-client (n2c) communication. This is required for transaction submission, fetching protocol parameters etc. If you don't need these functionalities, you can leave them commented.
#store.cardano.n2c-node-socket-path=/Users/satya/work/cardano-node/preprod-8.1.2/db/node.socket
# If you are accessing n2c through a relay like "socat", uncomment and edit the following properties.
#store.cardano.n2c-host=<relay_host>
#store.cardano.n2c-port=<relay_port>
Now you are ready to use Yaci Store in your application. During application startup, Yaci Store will create all the required tables in the database and start syncing the blockchain data and publish them as events and process them.
Yaci Store provides a default storage implementation which stores all data in yaci store defined table. But you can override this default implementation and provide your own storage implementation. Check out sample projects mentioned above for more details.
For example: If you only want to store a specific metadata label, you can extend the default storage implementation and filter out the labels you want to store.
Ideally you don't need to have your own custom processor, but if you want to do some custom processing, you can listen to both core or derived events and do your custom processing.
If you are using default storage implementation or a custom storage by extending default storage, Yaci Store will automatically handle rollbacks.
But if you have your own custom processor or different storage implementation using separate database/table, you need to handle rollbacks in your custom processor by listening to RollbackEvent. For more details on how to handle rollbacks, check Rollback Handling and also make sure all your operations are idempotent.