#!/usr/bin/env bash set -euo pipefail if [[ $# -ne 1 ]]; then echo "Usage: $0 " >&2 exit 1 fi if [[ -z "${ARBISCAN_API_KEY:-}" ]]; then echo "Error: ARBISCAN_API_KEY environment variable is required." >&2 exit 1 fi TX_HASH="$1" # Prefer the newer V2 endpoint; fall back to V1 if it fails (for backwards compatibility) response=$(curl -s "https://api.arbiscan.io/v2/api?module=proxy&action=eth_getTransactionByHash&txhash=${TX_HASH}&apikey=${ARBISCAN_API_KEY}") status=$(echo "$response" | jq -r '.status' 2>/dev/null || echo "") if [[ "$status" == "1" || "$status" == "0" && "$response" == *"result"* ]]; then echo "$response" exit 0 fi # Fallback to legacy V1 endpoint curl -s "https://api.arbiscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=${TX_HASH}&apikey=${ARBISCAN_API_KEY}"