Customize Rewards Logic
In this guide, we will walk through two different methods of customizing rewards logic within your metagraph.
Understanding Rewards
Rewards are emitted on every timed snapshot of the metagraph and increase the circulating supply of the metagraph token beyond the initial balances defined in genesis.csv. These special transaction types can be used to distribute your currency to fund node operators, or create fixed pools of tokens over time.
By default, no rewards are distributed by a metagraph using the Metagraph Framework which results in a static circulating supply. The rewards customizations described below create inflationary currencies - the rate of which can be controlled by the specific logic introduced. Similarly, a maximum token supply can easily be introduced if desired to prevent unlimited inflation.
The Rewards Function
The rewards function includes contextual information from the prior incremental update, including any data produced. Additionally, this function can include customized code capable of invoking any library function of your choice, allowing you to support truly custom use cases and advanced tokenomics structures. The following examples serve as a foundation for typical use cases, which you can expand upon and tailor to your project's needs.
Before You Start
This guide assumes that you have configured your local environment based on the Quick Start Guide and have at least your global-l0, currency-l0, currency-l1 clusters configured.
We will be updating the code within your project in the L0 module. This can be found in:
source/project/<project_name>/modules/l0/src/main/Main.scalaPlease note, the examples below show all logic within a single file to make copy/pasting the code as simple as possible. In a production application you would most likely want to split the code into multiple files.
Examples
These examples show different ways that rewards logic can be customized within your metagraph. The concepts displayed can be used independently or combined for further customization based on the business logic of your project.
Example: Distribute Rewards to Fixed Addresses
Add the following code to your L0 Main.scala file.
The code distributes 5.55 token rewards on each timed snapshot to two hardcoded addresses:
DAG8pkb7EhCkT3yU87B2yPBunSCPnEdmX2Wv24sZ
DAG4o41NzhfX6DyYBTTXu6sJa6awm36abJpv89jB
These addresses could represent treasury wallets or manually distributed rewards pools. Update the number of wallets and amounts to match your use-case.
Rebuild Clusters
Run the following commands to rebuild your clusters with the new code:
Once built, run hydra start to see your changes take effect.
View Changes
Using the Developer Dashboard you should see the balances of the two wallets above increase by 5.5 tokens after each snapshot.
Inspecting the snapshot body, you should also see an array of "rewards" transactions present.

Example: Distribute Rewards to Validator Nodes
Add the following code to your L0 Main.scala file.
The code distributes 1 token reward on each timed snapshot to each validator node that participated in the most recent round of consensus.
Rebuild Clusters
Run the following commands to rebuild your clusters with the new code:
Once built, run hydra start to see your changes take effect.
View Changes
Using the Developer Dashboard you should see the balances of the wallets in each node in your L0 cluster above increase by 1 token after each snapshot.
Inspecting the snapshot body, you should also see an array of "rewards" transactions present.
Example: Distribute Rewards Based on API Data
Add the following code to your L0 Main.scala file.
The code distributes token rewards on each timed snapshot to each address that is returned from a custom API.
On this Repository you can take a better look at the template example and the custom API.
In the repository, the code will distribute the amount of 100 tokens between the number of returned wallets (in this case the maximum of 20 latest wallets)
Rebuild Clusters
Run the following commands to rebuild your clusters with the new code:
Once built, run hydra start to see your changes take effect.
View Changes
Using the Developer Dashboard you should see the balances of the wallets in each node in your L0 cluster above increase by ( 100 / :number_of_wallets ) tokens after each snapshot.
Inspecting the snapshot body, you should also see an array of "rewards" transactions present.
Last updated
Was this helpful?