Last active
June 30, 2025 07:28
-
-
Save deividaspetraitis/8662ecaed096d6a00024730fa82820e5 to your computer and use it in GitHub Desktop.
LCD TX Pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
BASE_URL="https://lcd.archive.osmosis.zone/cosmos/tx/v1beta1/txs" | |
LIMIT=100 | |
ORDER_BY="ORDER_BY_DESC" | |
QUERY="message.sender='osmo1z89utvygweg5l56fsk8ak7t6hh88fd0au3z2n6'" | |
PAGE=1 | |
while true; do | |
URL="${BASE_URL}?limit=${LIMIT}&page=${PAGE}&order_by=${ORDER_BY}&query=$(printf "%s" "$QUERY" | jq -s -R -r @uri)" | |
echo "Fetching page ${PAGE}... URL ... ${URL}" | |
# Get response and HTTP status code | |
RESPONSE=$(curl -s -w "\n%{http_code}" "$URL") | |
BODY=$(echo "$RESPONSE" | sed '$d') | |
STATUS_CODE=$(echo "$RESPONSE" | tail -n1) | |
echo "HTTP Status: $STATUS_CODE" | |
if [[ "$STATUS_CODE" -ne 200 ]]; then | |
echo "Non-200 status, exiting." | |
exit 1 | |
fi | |
# Check if "txs" exists in the root | |
HAS_TXS=$(echo "$BODY" | jq 'has("txs")') | |
if [[ "$HAS_TXS" != "true" ]]; then | |
echo "Response does not contain 'txs' in the root:" | |
echo "$BODY" | |
fi | |
# Check if there are no txs to stop pagination | |
TXS_COUNT=$(echo "$BODY" | jq '.txs | length') | |
if [[ "$TXS_COUNT" -eq 0 ]]; then | |
echo "No more transactions found, stopping." | |
break | |
fi | |
PAGE=$((PAGE + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment