Skip to content

BitcoinDevelopersAcademy/assignment-week-1-bitcoin-transaction-visualizer-diop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Open in Visual Studio Code

Assignment Week 1: Bitcoin Transaction Visualizer

Objective: Create a simple Streamlit-based dashboard that allows users to visualize basic information about Bitcoin transactions, such as inputs, outputs, and transaction fees.

Instructions:

  1. Please read the instructions!

  2. Install the required libraries: Install Python libraries, such as requests, pandas, and streamlit.

  3. Familiarize yourself with the Blockchair API documentation: Review the API documentation at https://blockchair.com/api/docs to understand the available endpoints, request parameters, and response formats.

  4. Create a new Python file (e.g., app.py) and import the necessary libraries.

import streamlit as st
import requests
import pandas as pd
  1. Set up the Blockchair API key and base URL:
blockchair_base_url = "https://api.blockchair.com/bitcoin"
  1. Create a function to fetch transaction data using the Blockchair API:
def fetch_transaction_data(tx_hash):
    url = f"{blockchair_base_url}/dashboards/transaction/{tx_hash}"
    response = requests.get(url)

    if response.status_code == 200:
        data = response.json()
        return data
    else:
        return None
  1. Set up the Streamlit user interface:
st.title("Bitcoin Transaction Visualizer")

tx_hash_input = st.text_input("Enter a Bitcoin transaction hash:")
  1. Fetch and display transaction data:
if tx_hash_input:
    tx_data = fetch_transaction_data(tx_hash_input)

    if tx_data:
        st.subheader("Transaction Details")
        st.write(f"Transaction hash: {tx_data['data'][tx_hash_input]['transaction']['hash']}")
        st.write(f"Size: {tx_data['data'][tx_hash_input]['transaction']['size']} bytes")
        st.write(f"Fee: {tx_data['data'][tx_hash_input]['transaction']['fee']} satoshis")

        st.subheader("Inputs")
        inputs_df = pd.DataFrame(tx_data['data'][tx_hash_input]['inputs'])
        if not inputs_df.empty:
            st.dataframe(inputs_df[['recipient', 'value']])
        else:
            st.write("No inputs data available")

        st.subheader("Outputs")
        outputs_df = pd.DataFrame(tx_data['data'][tx_hash_input]['outputs'])
        if not outputs_df.empty:
            st.dataframe(outputs_df[['recipient', 'value']])
        else:
            st.write("No outputs data available")
    else:
        st.error("Error fetching transaction data. Please check the transaction hash and try again.")
  1. Run the Streamlit application:
streamlit run app.py

About

assignment-week-1-bitcoin-transaction-visualizer-diop created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published