Skip to content

Instantly share code, notes, and snippets.

@ctibo
Last active January 16, 2023 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctibo/54c11864c6d0d0b1cb1dd328874932f6 to your computer and use it in GitHub Desktop.
Save ctibo/54c11864c6d0d0b1cb1dd328874932f6 to your computer and use it in GitHub Desktop.
Algorand Nodes Made Easy

Basic Algorand Node, just a little easier.

Copy the algo.sh file somewhere on your computer. It can be anywhere because you'll set the path to find it in the next step.

Add this to your .bashrc, .profile or .bash_profile Set some paths here so the scripts know where is the install.

# Folder where you want to install your node
export ALGORAND_FOLDER=$HOME/node
# Path for the algo.sh file
algo_commands=$HOME/algo.sh 

# Don't change  the following lines. 
export ALGORAND_DATA="$ALGORAND_FOLDER/data"
export PATH="$HOME/node:$PATH"
function algo() { 
    $algo_commands "$@"
}

Don't forget to source the your file after updating it. Also make sure the command file is executable

source ~/.bashrc
chmod u+x ~/.algo.sh

You're all set! You can use algo help if you need the list of all commands, but here's a list :

Quick functions
----------------
algo install            Install a node from scratch (uses \$ALGORAND_FOLDER variable)
algo update             Update your node to the latest version
algo catchup            Gets the latest catchpoint and start cathing up from it

algo start              Start your node
algo stop               Stop the node (also takes the accounts offline first)
algo status             Log the current state of you node, once
algo watch              Display the node status and updates it every 3.7s

algo keys list          List all the participation keys from your node
algo keys new <addr>    Generate new participation keys for a given account
algo keys renew <addr>  Regenerates the keys for an account, and push them online
algo keys online        Sets all participating accounts as online (can pass a single account too)
algo keys offline       Sets all participating accounts as offline (can pass a single account too)

algo <anything>         Alias for 'goal ...'. 



Steps to get running 
---------------------
1. algo install
2. algo start
3. algo catchup
4. algo wallet new <my wallet name>
5. algo account import -m \"my twenty five word mnemonic without commas\"
6. algo keys new <the address you just imported>
7. algo keys online

#!/bin/bash
# 💡 TAKE ACCOUNTS ONLINE
# inspired by https://epocks.com/onlinenode.html
# =================================================
declare -a offline_accounts
get_offline_accounts() {
echo "👤 Getting accounts in wallet..."
tmp=$(mktemp) #create temp file
trap 'rm -f -- "$tmp"' EXIT # make sure we delete temp files on crash
(goal account list | tee /dev/tty) > $tmp # save account list in file
sed -i '/^Please enter the password/d' $tmp # remove password prompt line
offline_accounts=( $( grep "[offline]" $tmp | tr -s ' ' | cut -d ' ' -f3 ) )
rm $tmp # delete temp file
echo ''
}
take_account_online() {
echo "💡 Taking account $1 online..."
raw=$(mktemp); signed=$(mktemp) #create temp file for raw + signed txns
trap 'rm -f -- "$raw"' EXIT; trap 'rm -f -- "$signed"' EXIT # make sure we delete temp files on crash
firstValid=$(goal node lastround)
goal account changeonlinestatus \
--address=$1 \
--fee=2000 \
--firstvalid=$firstValid \
--lastvalid=$(expr $firstValid + 100) \
--online=true \
--txfile=$raw
goal clerk sign --infile=$raw --outfile=$signed
goal clerk rawsend --filename=$signed
rm $raw; rm $signed # delete temp files
echo ''
}
take_all_accounts_online() {
# get account list
get_offline_accounts
echo '🔌 All offline accounts: '
printf -v var "%s\n" "${offline_accounts[@]}"
# take each account offline
for address in "${offline_accounts[@]}"; do
take_account_online $address
done
echo '💡 All accounts are online!'
}
# 🔌 TAKE ACCOUNTS OFFLINE
# inspired by https://epocks.com/onlinenode.html
# =================================================
declare -a online_accounts
get_online_accounts() {
echo "👤 Getting accounts in wallet..."
tmp=$(mktemp) #create temp file
trap 'rm -f -- "$tmp"' EXIT # make sure we delete temp files on crash
(goal account list | tee /dev/tty) > $tmp # save account list in file
sed -i '/^Please enter the password/d' $tmp # remove password prompt line
online_accounts=( $( grep "[online]" $tmp | tr -s ' ' | cut -d ' ' -f3 ) )
rm $tmp # delete temp file
echo ''
}
take_account_offline() {
echo "🔌 Taking account $1 offline..."
raw=$(mktemp); signed=$(mktemp) #create temp file for raw + signed txns
trap 'rm -f -- "$raw"' EXIT; trap 'rm -f -- "$signed"' EXIT # make sure we delete temp files on crash
firstValid=$(goal node lastround)
goal account changeonlinestatus \
--address=$1 \
--fee=2000 \
--firstvalid=$firstValid \
--lastvalid=$(expr $firstValid + 100) \
--online=false \
--txfile=$raw
goal clerk sign --infile=$raw --outfile=$signed
goal clerk rawsend --filename=$signed
rm $raw; rm $signed # delete temp file
echo ''
}
take_all_accounts_offline() {
# get account list
get_online_accounts
echo '💡 Online Accounts: '
printf -v var "%s\n" "${online_accounts[@]}"
# take each account offline
for address in "${online_accounts[@]}"; do
take_account_offline $address
done
echo '🔌 All accounts are offline. Node can be stopped safely...'
}
# COMMANDS
# =================================================
case $1 in
# HELP
# =================================================
"help")
echo "
Quick functions
----------------
algo install Install a node from scratch (uses \$ALGORAND_FOLDER variable)
algo update Update your node to the latest version
algo catchup Gets the latest catchpoint and start cathing up from it
algo start Start your node
algo stop Stop the node (also takes the accounts offline first)
algo status Log the current state of you node, once
algo watch Display the node status and updates it every 3.7s
algo keys list List all the participation keys from your node
algo keys new <addr> Generate new participation keys for a given account
algo keys renew <addr> Regenerates the keys for an account, and push them online
algo keys online Sets all participating accounts as online (can pass a single account too)
algo keys offline Sets all participating accounts as offline (can pass a single account too)
algo <anything> Alias for 'goal ...'.
Steps to get running
---------------------
1. algo install
2. algo start
3. algo catchup
4. algo wallet new <my wallet name>
5. algo account import -m \"my twenty five word mnemonic without commas\"
6. algo keys new <the address you just imported>
7. algo keys online
"
;;
# START / STOP NODE
# =================================================
# > algo start
"start")
goal node start
;;
# > algo stop
"stop")
# take all account offline before stopping node
echo '🛑 Taking all accounts offline...'
take_all_accounts_offline
# stop the node
echo '🛑 Stopping node...'
goal node stop
;;
# NODE STATUS
# =================================================
# > algo status
"status")
goal node status
;;
# > algo watch
# updates every 3.7s :)
"watch")
goal node status -w 3700
;;
# PARTICIPATION KEYS
# https://epocks.com/onlinenode.html
# =================================================
"keys")
case $2 in
# > algo keys list
# List current keys in your node
"list")
goal account listpartkeys
;;
# > algo keys new <AAAAA...AAAAA>
# Generate new participation keys for a given account
"new")
firstValid=$(goal node lastround)
lastValid=$(expr $firstValid + 3000000)
goal account addpartkey \
--address=$3 \
--roundFirstValid=$firstValid \
--roundLastValid=$lastValid
;;
# > algo keys renew <AAAAA...AAAAA>
# Renew participation keys for a given account
"renew")
firstValid=$(goal node lastround)
lastValid=$(expr $firstValid + 3000000)
goal account renewpartkey \
--address=$3 \
--roundLastValid=$lastValid
;;
# > algo keys online <AAAAA...AAAAA>
# Set online status for a given account
"online")
if [ -z "$3" ]; then
take_all_accounts_online
else
take_account_online $3
fi
;;
# > algo keys offline <AAAAA...AAAAA>
# take an account offline
"offline")
if [ -z "$3" ]; then
take_all_accounts_offline
else
take_account_offline $3
fi
;;
esac
;;
# INSTALL IN $ALGORAND_FOLDER
# https://developer.algorand.org/docs/run-a-node/setup/install/#installation-with-the-updater-script
# =================================================
"install")
if [ -d $ALGORAND_DATA ]; then
echo "❌ Looks like a node is already installed."
exit;
fi
current_folder=$PWD
mkdir $ALGORAND_FOLDER
cd $ALGORAND_FOLDER
curl https://raw.githubusercontent.com/algorand/go-algorand/rel/stable/cmd/updater/update.sh -O
chmod 744 update.sh
./update.sh -i -c stable -p $ALGORAND_FOLDER -d $ALGORAND_DATA -n
cd $current_folder
;;
# UPDATE NODE
# https://developer.algorand.org/docs/run-a-node/setup/install/#updating-node
# =================================================
"update")
if [ ! -f $ALGORAND_FOLDER/update.sh ]; then
echo "❌ Can't find updater script."
exit;
fi
$ALGORAND_FOLDER/update.sh -d $ALGORAND_DATA
;;
# SYNC NODE USING CATCHUP
# https://developer.algorand.org/docs/run-a-node/setup/install/#sync-node-network-using-fast-catchup
# =================================================
"catchup")
catchpoint=$(curl https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint)
goal node catchup $catchpoint
goal node status -w 1000
;;
# EVERYTHING ELSE
# =================================================
*)
goal "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment