If you are one of the crypto, early adopters, the chances are that you’ve heard about a new cryptocurrency called Chia. In this post, we will develop a simple monitoring tool to send alerts if Chia farming stops. We are going to use SpacePool’s Developer API to achieve this.

Getting Started

The best resource to get started is SpacePool’s blog post

First of all, we will need an API key and as of this writing, obtaining a key is a manual process. You have to explain your use case on their Discord server by answering a list of fixed questions (listed in the blog post), and you’ll get a private message with your key.

Testing the key

The easiest way to test your setup is to visit the API reference

Enter your launcher id, API key and some value for User-Agent. Then, when you click the Try It Out button, you should be able to see some results, as shown in the screenshot below:

SpacePool API reference page showing get recent partials endpoint

Developing a custom application

It’s a REST API with OpenAPI specs at https://developer.pool.space/api/v1/docs/openapi.json. I used this to generate my C# client:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate `
    -i https://developer.pool.space/api/v1/docs/openapi.json `
    -g csharp-netcore `
    -o /local/csharp-netcore

The generated project has the API clients for the endpoints:

Auto-generated API client project structure is shown in Rider IDE.

For monitoring purposes, we are interested in the GetFarmPartialsV1Api endpoint.

Here’s my simple console application that calls the endpoint and checks if the latest verified submission happened within an expected timeframe:

const string launcherId = "{launcher id}";
const string apiKey = "{api key}";
const string userAgent = "{custom user agent}";

var apiClient = new GetFarmPartialsV1Api();
var response = await apiClient.ApiV1FarmsLauncherIdOrAliasPartialsGetAsync(launcherId, apiKey, userAgent);

var latestSuccessfulSubmission = response.Results
    .OrderByDescending(r => r.SubmissionDateTimeUtc)
    .FirstOrDefault(r => r.State.Description == "Verified");

if (latestSuccessfulSubmission == null)
{
    Console.WriteLine("No verified partials");
    // Send an alert somewhere 
    return;
}

var timeElapsedSinceLastVerifiedPartial =
    DateTime.UtcNow - DateTime.Parse(latestSuccessfulSubmission.SubmissionDateTimeUtc);

var interval = 10;
if (timeElapsedSinceLastVerifiedPartial.TotalMinutes >= interval)
{
    Console.WriteLine($"No verified partials in the last {interval} minutes"); // Send an alert somewhere 
}
else
{
    Console.WriteLine($"Last verified partial received {Math.Floor(timeElapsedSinceLastVerifiedPartial.TotalMinutes)} minutes ago. All looking good.");
}

and after we run the application, we can see it checks the results:

A terminal output shows the last verified partials were received and there is no alarm.

Conclusion

In this post, we looked into generating API clients automatically from an OpenAPI spec. Then, the client talked to the SpacePool API and got some information about our Chia farm.

I left out sending the actual alerts as they are open-ended, and anyone can customize them to fit their system. In the future, I might post a complete Dockerized solution so that the deployment can be as simple as running a container and providing it with the launcher id and API key.

Let me know if this is of any interest to you to prioritize it over other content.

Happy farming!

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.