Get a text message when your ETH2 validator stops working

Running resilient systems has two parts:

As you start running your validator, whether on a test network or the main network, things will go wrong. You’ll want to know as soon as possible.

This guide is pretty technical, if it is overwhelming I encourage you to try out beaconchain’s built-in email notifications, where you can request an email be sent to you when your validator balance decreases. I have used this for a few months and there are times when it doesn’t work well — either because gets into a bad state, or I didn’t check email regularly, or because they only send one email, no matter how long your validator balance declines.

So today I will show an alternate approach: how to get automatic text messages anytime your validator goes down. We will use a cloud function running in Google cloud, I have been running it every 15 minutes for 2 weeks and it has cost 1 penny during that time. You will also need a trial Twilio account to send the text message, which is free.

Sign up for your trial Twilio account

Go to twilio and start the sign up process. You will need to supply a valid email and phone number. When they ask if you can write code, say yes. If you don’t have a favorite language, say “Python”. That’s what we’ll be working in today.

There will be a couple of onboarding questions about your intentions: to “use Twilio in a project” to “send an SMS”, which is a text message.

Once you get through the onboarding questions, you should see a button to get a trial phone number. They will offer some choices in picking the number, but any number should do. Take note of the Account SID and the Auth Token, we will need these for the next step.

Set up a Google cloud function

If you have an active gmail account, you can use that account to access Google Cloud Platform, an amazing, flexible competitor to Amazon’s Web Services.

Start by going here. Once you have worked through the onboarding, go to “Cloud Functions” in the sidebar, and choose “Create Function”. How to name your function is up to you, mine is named something like “validator check”. You’ll also want to set a trigger. You can trigger these functions via a web call, but I want mine on a timer, so I used Cloud Pub/Sub. I created a new topic, again with a name like “validator check topic”.

When you are done setting up the pub/sub topic, you need to check the “Variables, Networking and Advanced Settings”. We want to set some variables here:

VALIDATOR_KEY: the public key of your validator
TWILIO_ACCOUNT_SID: get this value from twilio
TWILIO_AUTH_TOKEN: get this value from twilio
TARGET_PHONE: the phone number you want to send a message to. no country code, so in the US just 10 digits
VALIDATOR_NICKNAME: in case you run multiple copies of this for different validators, the message will tell you which one is down
SOURCE_PHONE: the phone number you were assigned by Twilio, no country code

Set the above values under “Runtime environment variables”

Code for Google cloud function

Use Python 3.8 for the Runtime. Update the Entry point to “check_validator”

Replace the contents of requirements.txt with this:

# Function dependencies, for example:
# package>=version

And the contents of

The code above is checking the API for your validator status. Sometimes this API goes down. An alternative approach is to have it check an available beacon node, but running a beacon node has some cost and this is incredibly inexpensive to run as is.

Also note the code above is checking medalla, you will need to modify for the chain you are targeting. I’ve also assumed US phone number format with country code “+1”.

When you save this function, you will need to enable “Cloud Build”. Once saved, you can try running it manually to see if you hit any problems. You can also temporarily modify the final if statement to make sure you get a message, even if your validator is working fine.

Set up a timer

Using the search bar at the top of the console, search for “Scheduler”. Create a job in the cloud scheduler, named whatever you like. The schedule is in cron format, so to check every 15 minutes, you would use: */15 * * * *

The “target” is Pub/Sub, the “topic” is the topic you created earlier when building your function, and the “payload” isn’t used, so we can use an empty value like “{}”

Now, with this timer set up, you should get notified within 15 minutes any time your validator goes down. Try taking it down, briefly, just to check.

Final thoughts

This system expects the chain to be up, to be up, and of course, your validator to be up. It won’t work on the mainnet before launch, but it should work on whatever testnet you want to point it at, so long as supports it.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store