Chain-Maind Auto-Compound (Linux)

Auto-Compound your staking rewards on the Crypto.org chain!
LINUX (UNIX) Edition



Prerequisites

This guide is purposely not going into details to keep it short and (hopefully) simple. I am assuming that you know how to work with a terminal.


Get Chain-Maind

Note: as of writing, the script is only compatible with version 2.1.2. Newer releases supporting croeseid (version 3.0.0 and higher) are not working yet!

Download the latest stable release from GitHub:
https://github.com/crypto-org-chain/chain-main/releases
Please make sure you get the correct URL from the Releases page as this one may be outdated in the future!

Version 2.1.2

wget https://github.com/crypto-org-chain/chain-main/releases/download/v2.1.2/chain-main_2.1.2_Linux_x86_64.tar.gz
tar -xvf chain-main_2.1.2_Linux_x86_64.tar.gz

Now there should be a directory called bin in the current directory. In this directory is the main executable chain-maind. To make sure that we can interact with it, modify the permissions of the binary to make it executable:

// 755 == rwxr-xr-x (owner has full access, others can only read and execute)
// Note: this is just access to chain-maind, NOT your wallet keys!
chmod 755 bin/chain-maind

Configure Chain-Maind

Now we have chain-maind available and ready to use. Next is configuring it by adding your wallet. You can change the name of your wallet, I’ve chosen “DeFiWallet” in this example, but the name really doesn’t matter honestly.

./bin/chain-maind keys add DeFiWallet --interactive

This command will now prompt you to enter your mnemonic phrase. Make sure you only separate the words by a blank space and not a comma or anything else, otherwise the command will fail.

The result should look something like this:

- name: DeFiWallet
  type: local
  address: cro1ecwcn9tnla7tuzruhfc67z2ulvtl3340227a3w
  pubkey: cropub1addwnpepqvdajxswcsnfhj9j08key8xagauendryg840en76xtsmnxtmcqhrvvy6h8r
  mnemonic: ""
  threshold: 0
  pubkeys: []

With this being done, you can now already interact with the Crypto.org chain and execute transactions from your wallet.


Setup Python

In order to run the script provided by Samuel, we must make sure that Python3 and all required dependencies are installed:

apt install python3
pip3 install pexpect

Download & Configuration of the script

Next, you have to download the script and modify all required parameters.
This is a modified version which fixes a few issues/bugs that were not covered in the original script.

wget https://gitlab.com/-/snippets/2174060/raw/main/withdrawdelegateshare.py
chmod 700 withdrawdelegateshare.py
nano withdrawdelegateshare.py

With the chmod 700 command, you make sure that only you, the owner, can read the contents of the file. This is important as this file contains the password to your keyring in plain text!

The nano command should have opened a text editor. Now it’s time to personalize the script:
Press CTRL+X to save your changes

# Address of the validator
# this is the address of X Staking
validator = 'crocncl14vxzdsxtmat7hvz58trk823adg3pjh4xh6ghm6'

# Your own CRO Address
own_address = 'cro1ecwcn9tnla7tuzruhfc67z2ulvtl3340227a3w'

# Password of your keyring
password = 'HiI!mP4ssw0rd'

# Folder in which the chain-maind executable is
# Use the full path and don't use relative paths!
chain_maind_directory = '/home/simon/bin'

Note: If you have questions about the default validator X Staking, you can find more information about him below (here).

Everything is set up now. Every time you want to compound your stake just call the script and all your CRO from your wallet (and staking rewards) will be staked.

python3 withdrawdelegateshare.py

Example Output:

> python3 withdrawdelegateshare.py

Claiming rewards from crocncl14vxzdsxtmat7hvz58trk823adg3pjh4xh6ghm6 ... [OK]
Waiting 7sec for the transaction to be processed ... [OK]
Querying wallet balance ... [OK]
Staking 2cro with crocncl14vxzdsxtmat7hvz58trk823adg3pjh4xh6ghm6 ... [OK]

Automation

Instead of running this command always manually, it’s way easier to let your computer automatically execute the script at a specified time. To achieve this, I’m going to use cron (crontab).

Open the crontab editor:
(If you’ve never modified it, it will ask you which editor you want to use)

crontab -e

Next, you have to decide how often you want the script to run. My suggestion is that once per day should be enough, but everyone can decide on their own.

Here are a few example time codes/intervals in the “cron format”:

Time CodeDescription
0 */1 * * *Hourly (“at minute 0 past every hour”)
0 0 */1 * *Daily (“at 00:00 on every day-of-month”)
0 0 * * 1Weekly (“at 00:00 on Monday“)

Feel free to use them or create your own according to your need. For creating your own timecode, I can recommend using https://crontab.guru/ as they offer an easily understandable editor.

After having decided on a time code/interval, simply add a new line at the bottom of the already opened editor and add the following line. Make sure to replace the curly brackets with our values!

{code} python3 {script_path}/withdrawdelegateshare.py
  • {code} must be replaced by the time code you have chosen.
  • {script_path} is the absolute path to the folder in which your script is located. (Do NOT use relative paths!)

I’m using the following code myself:

0 0 * * 1 python /home/simon/withdrawdelegateshare.py

Security Note

We’ve already set file permissions so that nobody else can get the password from the python script. But what about your system, especially if you’re running it on a server?

Assuming you have this running on a server, the chances are high that you’re using SSH to access the terminal of your server. Make sure that you’re using a strong password or preferably deny password login in general and only use SSH-Keys.

If somebody gets access to your user account, they have full access to your wallet and thus full access to all your coins!

There are many sources on the internet on how you can set this up. If you do, most of them are older, but in general, please keep the following points in mind:

  • Do NOT generate a key using the RSA algorithm, go for ED25519 instead
  • If you have to generate an RSA key make sure it’s at least 4096 bits long
  • NEVER share the generated private key with anyone else

Credits

A huge thanks to Samuel (X Staking) for doing the hard work and providing this script!
You can find more information about him here:


Disclaimer

Future updates of the Crypto.org Chain can and will modify chain-maind. Make sure you are always running the same version that all validators are using.

The software is provided “AS IS” and the author disclaims all warranties with regard to this software including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, direct, indirect, or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software.


If you have any further questions, feel free to ask on Telegram.