Skip to content

Instantly share code, notes, and snippets.

@ankh2054
Forked from michaeljyeates/eos-vanity.sh
Last active November 13, 2024 09:09
Show Gist options
  • Save ankh2054/5ee7795413e84a2c34a3167dcceee94c to your computer and use it in GitHub Desktop.
Save ankh2054/5ee7795413e84a2c34a3167dcceee94c to your computer and use it in GitHub Desktop.
#!/bin/bash
trap "echo 'Terminating all processes...'; pkill -P $$; exit 1" SIGINT SIGTERM
# Check for input argument
if [[ -z "$1" ]]; then
echo "Search for vanity keys - Usage: ./vanity.sh STRING [NUM_PROCESSES]"
exit 1
fi
VANITY_STRING=$(echo "$1" | tr '[:upper:]' '[:lower:]')
NUM_PROCESSES=${2:-$(nproc)}
LOG_FILE="vanity_key_generation.log"
echo "Finding keys containing: $VANITY_STRING using $NUM_PROCESSES parallel processes."
echo "Logging progress to $LOG_FILE."
# Function to generate and check keys
generate_and_check() {
while true; do
# Generate key pair using cleos
output=$(cleos create key --to-console 2>> "$LOG_FILE")
# Extract the public key (assuming it's the 5th field)
pub=$(echo "$output" | grep "Public" | awk '{print $3}' | tr '[:upper:]' '[:lower:]')
# Log the generated public key
echo "$(date '+%Y-%m-%d %H:%M:%S') - Process $$ generated public key: $pub" >> "$LOG_FILE"
# Check if the public key contains the vanity string
if [[ $pub == *"$VANITY_STRING"* ]]; then
{
echo "-------------------------------"
echo "Found matching key!"
echo "$output"
echo "Process $$ exiting."
} | tee -a "$LOG_FILE"
# Terminate all other background processes
pkill -P $$
exit 0
fi
done
}
# Start background processes
for i in $(seq 1 "$NUM_PROCESSES"); do
generate_and_check &
done
# Wait for all background processes to finish
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment