Api call blockchain


SUBMITTED BY: XGrats

DATE: Sept. 30, 2023, 7:03 a.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 20

  1. import requests
  2. # Define the base URL for the Blockchain.com API
  3. base_url = "https://api.blockchain.com/v3"
  4. # Transaction ID you want to retrieve
  5. transaction_id = "your_transaction_id_here"
  6. # Create the API endpoint URL for fetching transaction data
  7. endpoint = f"{base_url}/rawtx/{transaction_id}"
  8. try:
  9. # Make the API request to fetch transaction data
  10. response = requests.get(endpoint)
  11. # Check if the request was successful (status code 200)
  12. if response.status_code == 200:
  13. transaction_data = response.json()
  14. # Print or process the transaction data as needed
  15. print("Transaction Data:")
  16. print(transaction_data)
  17. else:
  18. print(f"Error: Unable to fetch transaction data. Status code: {response.status_code}")
  19. except requests.exceptions.RequestException as e:
  20. print(f"Error: {e}")
  21. _____________________________________________
  22. Note ;
  23. 1 Replace "your_transaction_id_here"
  24. with the actual transaction ID you want to retrieve.
  25. 2 You will need the "requests" library in Python to make HTTP requests. You can install it using " pip install requests ".

comments powered by Disqus