Monitor a XLM wallet for transactions with bash

Stellar / XLM developments
Post Reply
Styler
Posts: 5
Joined: Sun Feb 02, 2025 1:53 am

Monitor a XLM wallet for transactions with bash

Post by Styler »

Just give it +x and run it :)

Code: Select all

#!/bin/bash

# Set your Stellar wallet address (public key)
STELLAR_ADDRESS="YOUR_STELLAR_WALLET_ADDRESS"

# API endpoint for Stellar public network
STELLAR_API="https://horizon.stellar.org/accounts/$STELLAR_ADDRESS"

# Log file to track changes
LOG_FILE="stellar_wallet_monitor.log"

# Function to fetch balance
get_balance() {
    curl -s "$STELLAR_API" | jq -r '.balances[] | select(.asset_type == "native") | .balance'
}

# Get initial balance
LAST_BALANCE=$(get_balance)

echo "Monitoring Stellar wallet: $STELLAR_ADDRESS"
echo "Initial Balance: $LAST_BALANCE XLM"
echo "Monitoring started at $(date)" >> "$LOG_FILE"
echo "Initial Balance: $LAST_BALANCE XLM" >> "$LOG_FILE"

# Monitor loop
touch "$LOG_FILE"
while true; do
    CURRENT_BALANCE=$(get_balance)
    if [ "$CURRENT_BALANCE" != "$LAST_BALANCE" ]; then
        echo "Balance changed! New balance: $CURRENT_BALANCE XLM"
        echo "$(date): Balance changed from $LAST_BALANCE XLM to $CURRENT_BALANCE XLM" >> "$LOG_FILE"
        LAST_BALANCE="$CURRENT_BALANCE"
    fi
    sleep 60  # Check every 60 seconds
done
Post Reply