Configure and run CryptoGirls automatic payments script for TRX rewards

Dear community,

Over the past few weeks many candidates, elected SRs and voters have been asking details about how do we calculate and broadcast the daily payments to our voters. As some of you probably know, we implemented, tested and adapted an automatic script for TRX and we are giving back to our voters 70% of our total rewards through daily payments.

Lately, more and more candidates and SRs showed their willing to use our script and have been asking for details about server configuration, settings in configuration files and other technical questions. As the number of voters is increasing more and more every 6 hours (We all thank you to our voters for this immense support!), it’s getting harder to do the calculations and payments manually. This is why we decided to make a step-by-step tutorial for everyone to learn how to use our script for distributing rewards among their voters!

Our script is fully open-source for everyone to use, change or personalize!
For any other questions please join our telegram group. We are always here ready to help!

How does the script work?

The script takes snapshots of the voters’ data every 6 hours, calculates a % of the rewards produced by a SR and saves pending amounts for every voter based on his weight in the total votes cast for that SR. After 3 complete cycles of calculating and adding pending amounts for each voter, at the end of the 4th cycle of the day the script prepares a file with payments commands and broadcast the payments to the network.

Server Configuration

Our script is written in python and javascript and it is compatible with Linux servers.
We successfully tested our script on fresh Linux servers (Ubuntu 16.04 and 18.04) with various configurations from 1 core and 2GB RAM to 4 cores and 8GB RAM.
We strongly recommend to add a set of security settings to the payments server like creating a sudo user with private key authentication method, change the default SSH port and so on.

Install the dependencies

After installing and preparing the server, the next step is to install the dependencies and clone our repo from github.

Install python

sudo apt install python3-pip
sudo pip3 install python-dateutil
sudo pip3 install python-dateutil --upgrade

Clone the repo

git clone https://github.com/CryptoGirls/trx-pool
cd trx-pool

Install nodejs

sudo apt install nodejs
sudo apt install npm
npm install axios
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Install docker containers

apt install docker docker-compose
git clone https://github.com/tronscan/tronscan-docker

In docker-compose.yml file put your SR IP in full and solidity IPs

NODE_FULL_IP: "YOUR_SR_IP_HERE"
NODE_FULL_PORT: "50051"
NODE_SOLIDITY_IP: "YOUR_SR_IP_HERE"
NODE_SOLIDITY_PORT: "50051"
ENABLE_SYNC: "false"
ENABLE_NETWORK_SCANNER: "false"
SECRET_KEY: "aSLtAkzrIY9pTPyboOih"

Run the docker in screen or when making the payments:
./start.sh

Set configurations for your SR

Edit config.json, config_snapshot.json, poollogs.json and votes.js and modify the following lines with your settings. All the other lines must be left as they are, with the default values.

nano config.json
- sraddress: your SR address — this address will be used when getting voters’ data from the API
-
nodepay: node used for payments. It’s recommended to install the docker containers and to change nodepay to http://127.0.0.1:9000
-
percentage: percentage from the total rewards to distribute
-
minpayout: the minimum amount for a payment (NOTICE: in config_snapshot.json DO NOT modify minpayout)
-
pk: the private key of the wallet from which the payments will be broadcasted
-
skip: a list of addresses to skip (example: [“address1”,”address2”])
nano config_snapshot.json
- make the same configurations as above, except the minpayout. DO NOT modify the minpayout field in this file.
nano poollogs.json
- lastpayout: the unixtimestamp of your last payments or the unixtimestamp from which you want to calculate and distribute rewards
-
totalwithdraw: total of the TRX claimed from tronscan.org. After every claim rewards, the new value claimed must be added here
nano votes.js
- put your SR address in the following line
const CANDIDATE_ADDRESS = '';

Run it

  • At the beginning of each round — 4 times a day
node votes.js
OR
bash voters.sh
  • At the end of each round — 3 times a day (the script will calculate pending amounts)
python3 trxpool.py -c config_snapshot.json
OR
bash trx.sh
  • At the end of the 4th round — once a day (the script will create payments.sh file and will broadcast the payments)
python3 trxpool.py
OR
bash trx24.sh
bash payments.sh

The payments will be broadcasted every second.

Run it in crontab

The scripts are also runnable by cron.

  • give rights to execute
chmod +x voters.sh
chmod +x trx.sh
chmod +x trx24.sh
  • set separate crontab jobs for the following scripts
./voters.sh
./trx.sh
./trx24.sh

This is it! Now you can use our script and pay your voters way easier!!!

And last but not the least, we want to thank to those who have developed, contributed or advised us to improve our script: MANY THANKS to LISK delegate dakk who created the open-source payments script for LISK, to Rovak who made the docker containers and developed votes.js script, to CryptoChain and CryptoGuyInZA who answered us to any security-related question and helped us to set the docker containers for the payments!

Any feedback or ideas of improvements are very welcomed!

Thank you to ALL,

Irina and CryptoGirls