This script is an all-in-one solution for monitoring, maintaining, and managing a PWR Validator node. It automates common tasks such as checking validator status, handling updates, restarting on standby, and sending detailed notifications to your Telegram.
- Automatic Restart: 🔄 Proactively restarts the validator if it enters
standbymode or appears stalled. - Version Management: ⬆️ Automatically checks for new
validator.jarversions and performs updates. - Network Reset Detection: 🌐 Identifies potential network resets by comparing local block height with the network's and triggers a full data reset and update.
- Telegram Notifications: 📢 Sends detailed status reports, update notifications, and error alerts directly to your Telegram chat.
- Dependency Management: 📦 Checks for and attempts to install required system packages like Java, JQ, and Curl.
- Corrupt JAR Detection: 🔍 Identifies a corrupted
validator.jarfile from logs and automatically re-downloads it. - Automatic Faucet Claim: 🚰 If a
DISCORD_TOKENis provided, it will automatically claim from the faucet after a network reset. - Dynamic Bash Aliases: 🪄 Creates and manages a set of helpful command-line aliases for easy node management.
- Full Guide: PWR-Validator official repository.
- OS: A Debian-based Linux distribution (like Ubuntu) is recommended, as the script uses
apt-getfor dependency installation. - Shell:
bash - Required Packages:
curlwgetjqbtop(optional, for system monitoring)vnstat(optional, for network monitoring)openjdk-21-jdk(or newer)nodejsandnpm(only required if using the Discord faucet claim feature)
The script will attempt to automatically install these dependencies if they are not found.
For the script to function correctly, you must place its files inside your main PWR validator directory. The final structure should look like this:
/your/pwr/directory/
├── wallet # <-- Your validator wallet file
├── password # <-- Your validator password file
├── validator.jar # (Will be downloaded by the script)
├── config.json # (Will be downloaded by the script)
├── blocks/ # (Created automatically)
├── merkleTree/ # (Created automatically)
├── log.out # (Created automatically)
├── pwr.sh # The main monitoring script
├── .env # (You will create this file)
└── faucet/ # <-- Directory for the faucet claimer script
├── faucet.js
├── package.json
└── session.json
This script operates through a sequence of checks and actions to ensure your validator node is always online and up-to-date. The entire process is kicked off from the main function.
-
🚀 Initialization:
- The script first determines its own location to dynamically set paths for all necessary files like
wallet,password,validator.jar, andlog.out. - It detects the server's public IP address, which is crucial for the validator to announce itself correctly on the network.
- It loads all necessary configurations (like your
VALIDATOR_ADDRESSandTELEGRAM_TOKEN) from the.envfile.
- The script first determines its own location to dynamically set paths for all necessary files like
-
🔧 Dependency & Environment Setup:
check_and_install_dependencies: The script checks if essential tools likejava,curl, andjqare installed. If they are missing, it attempts to install them usingapt-get. It will also install Node.js if aDISCORD_TOKENis provided for the faucet.manage_bash_aliases: It automatically creates or updates a set of helpful command-line shortcuts (e.g.,pwrlogs,pwrstop) in your~/.bash_aliasesfile for easier manual management.
-
🔎 Main Status Check (
check_validator_status): This is the core logic loop of the script.- Network Reset Detection: It first fetches the latest block height from both your local node and the public network explorer. If your local node is significantly ahead of the network, it assumes a network reset has occurred. It then triggers
perform_updatewith a special flag to delete old blockchain data (/blocksand/merkleTree) before downloading the new version. - New or Syncing Node: If the PWR RPC reports that your address is "not a validator," the script assumes the node is new or syncing. It checks if the process is actively syncing blocks by comparing the latest block number over a 5-second interval. If it's not making progress, it restarts the validator process to kickstart it.
- Active/Standby Validator: If the node is a recognized validator, the script fetches detailed status information, including its status (
activeorstandby), total blocks created, and version information. - Version Check: It compares your local
validator.jarversion against the latest release on GitHub. If a new version is available, it automatically triggers theperform_updatefunction. - Proactive Restart: If the validator's status is
standby, the script initiates a proactive restart to try and get it back into anactivestate.
- Network Reset Detection: It first fetches the latest block height from both your local node and the public network explorer. If your local node is significantly ahead of the network, it assumes a network reset has occurred. It then triggers
-
🔔 Notifications:
- Throughout this entire process, the
send_telegramfunction is called to send detailed, formatted messages to your configured Telegram chat. This ensures you are always aware of the node's status, any actions being taken (like updates or restarts), and any errors that occur.
- Throughout this entire process, the
-
🚰 Faucet Claim Process (
faucet.js):- This process is only triggered automatically after a network reset is detected and only if you have provided your
DISCORD_TOKENin the.envfile. - The
pwr.shscript calls thefaucet/faucet.jsNode.js script. - First, it checks your validator's balance. If you have a balance greater than 0, the process stops to avoid unnecessary claims.
- To communicate with Discord's API, it needs a temporary
session_id. It connects to Discord's real-time Gateway (via WebSocket) and identifies itself using your token to receive this ID. The ID is then cached infaucet/session.jsonfor future use. - Finally, it sends an HTTP POST request to Discord's API, simulating the
/claimslash command in the official PWR Discord channel, which requests faucet funds for your validator address.⚠️ Important:
I take no responsibility for any actions taken against your account for using these script or how users use my open-source code.
Using this on a user account is prohibited by the Discord TOS and can lead to your account getting banned in very rare cases.
- This process is only triggered automatically after a network reset is detected and only if you have provided your
Follow these steps to set up the monitor.
Move the pwr.sh script and the entire faucet directory into the same directory where your validator.jar, wallet, and password files are located.
The script uses a .env file to store your sensitive information. The first time you run pwr.sh, it will create this file for you if it doesn't exist.
-
Run the script once:
./pwr.sh -
It will create a
.envfile. Open it with a text editor:nano .env -
Fill in the required details:
# --- PWR Validator Configuration --- # The address of the validator you are monitoring. VALIDATOR_ADDRESS=0xYourValidatorAddressHere # --- Telegram Bot Configuration --- # Your Telegram bot token from BotFather. TELEGRAM_TOKEN=your_telegram_bot_token_here # Your personal or group chat ID. CHAT_ID=your_telegram_chat_id_here # --- (Optional) Discord Faucet Configuration --- # Your Discord authorization token for the faucet. # This is only needed for automatic faucet claims after a network reset. DISCORD_TOKEN=your_discord_auth_token_here
To have the script run automatically at regular intervals (e.g., every 5 minutes), you need to add it to your crontab.
-
Open the crontab editor:
crontab -e
-
Add the following line to the end of the file. Make sure to replace
/path/to/your/pwr.shwith the actual, full path to the script.*/5 * * * * /path/to/your/pwr.sh
This configuration will execute the script every 5 minutes.
-
Save and exit the editor.
For a better management experience, this script automatically adds a set of useful aliases to your ~/.bash_aliases file.
To start using them, you must either restart your terminal session or run:
source ~/.bash_aliasesHere are the aliases that will be available:
| Alias | Description |
|---|---|
pwrlogs |
View the live validator logs (tail -f /your/pwr/directory/log.out). |
pwrstop |
Forcefully stops the validator Java process. |
pwrrestart |
Manually runs the pwr.sh script to check status and restart if needed. |
pwrblock |
Shows only the "Block created" lines from the log. |
pwraddress |
Displays your validator's public address. |
pwrmnemonic |
Displays your validator's seed phrase. |
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this project better, please fork the repository and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! ⭐ Thanks again!
This bot is provided "as is", without any warranties.
You're fully responsible for any actions taken using this tool. Understand the risks before proceeding.
This project is licensed under the MIT License.
Enjoy your automated and smoothly running PWR Validator! 🎉