Solana is currently one of the popular blockchains. Every few days, a new epoch starts at which point the staking rewards are sent to the stakers. This post’s primary focus is not a cryptocurrency; rather, it’s on a tool that monitors the Solana blockchain and sends email notifications when a new epoch starts. So I’m not going too deep into Solana terminology, but to understand the basics, here are a few definitions:

  • Solana: A Blockchain technology designed to host decentralized and scalable applications.
  • Staking: The process of locking up cryptocurrency to earn interest
  • Epoch: An epoch is the length of a certain amount of blocks. This is a variable duration, and typically it’s somewhere between 2-4 days.

If you are a Solana investor staking your Solana tokens, you earn some interest at the end of the epoch. This is where this notification tool comes in. If your wallet doesn’t have a feature of notifying you when you receive staking rewards, you can use this tool to receive email notifications when an epoch ends. This way, you can check your wallet and keep an eye on your rewards.

Implementation

If you want to check the current epoch manually, you can always go to the Solana explorer page, which shows the current epoch. However, if you look at the network traffic, it gets this data from Solana API, which seems to be public to get this basic info. So I experimented a bit and captured a query and re-sent it via Postman, and I got the following result:

Postman window showing getEpochInfo request and response

Based on this, I implemented my solution in C#, which is very simple and mainly looks like this (complete source code is here):

public async Task<GetEpochInfoResponse> GetEpochInfo()
{
    var client = new RestClient("https://explorer-api.mainnet-beta.solana.com/");
    var request = new RestRequest("/", Method.Post)
    {
        RequestFormat = DataFormat.Json,
    };
    request.AddHeader("Content-Type", "application/json");
    request.AddHeader("Accept", "application/json");
    request.AddJsonBody(new { Id = Guid.NewGuid(), Method = "getEpochInfo", Jsonrpc = "2.0", Params = new string[] {} }); 
    
    var responseRaw = await client.ExecuteAsync(request);
    return JsonConvert.DeserializeObject<GetEpochInfoResponse>(responseRaw.Content);
}

In the response, we can access the current epoch number. It then checks the previous epoch that it sent the notification for. This is to prevent duplicate notifications. Whenever it sends a notification, it writes the value to a JSON file. It’s important to mount that file with one on the host so that whenever the container restarts it doesn’t send an unnecessary notification.

Usage

  1. You can either clone the repo and build it yourself or you can pull the image from the Docker hub. In either case, you will need a copy of docker-compose-template.yaml and db.json files.

Bother methods are shown below:

a. Building From Source: Clone the repository

git clone [email protected]:Dev-Power/solana-epoch-monitor.git

b. Using the pre-built Docker image: Pull the image

docker pull devpowercouk/solana-epoch-monitor
  1. Make a copy of docker-compose-template.yaml and rename it to docker-compose.yaml
  2. Fill in the settings such as SMTP settings, db.json path etc.
  3. In a terminal, run
docker-compose up -d

Since the epoch in the db.json is a past one, it should immediately send a notification and update the db.json with the current epoch.

Conclusion

This is meant to be a quick little project that talks to Solana API and gets the epoch info. It may come in handy if such notifications are something you need. You can also use this as a starter project and implement more notification types.

I hope you found this little project useful and/or fun. Please let me know what you think in the comments below.

Resources


Volkan Paksoy

Volkan Paksoy is a software developer with more than 15 years of experience, focusing mostly on C# and AWS. He’s a home lab and self-hosting fan who loves to spend his personal time developing hobby projects with Raspberry Pi, Arduino, LEGO and everything in-between.