2

Is there a way to request the date of last transaction via API? I run a request to see balance of my addresses and need to request the date of the last transaction, how would I do that?

1
  • Hey, I assume that you are using the blockchain.info api, and thus edited the question accordingly.
    – Murch
    Commented Jan 11, 2017 at 14:28

3 Answers 3

0

This is an ambiguous question as we don't know what your environment is. If you are using bitcoind, a call to gettransaction will give you a time field which is when the transaction has been seen.

Perhaps if you elaborate a bit more we would be able to answer the question more specifically.

0

If you call the address API i.e.

https://blockchain.info/address/$hash_160?format=json you will get a list of transactions.

They all have a time attribute which is the time in unix format. https://en.wikipedia.org/wiki/Unix_time

0

import requests import time

def check_address_last_transaction_dates(filename): with open(filename, 'r') as file: address_list = [line.strip() for line in file]

for address in address_list:
    url = f"https://blockchain.info/address/{address}?format=json"
    response = requests.get(url)
    
    if response.status_code == 200:
        data = response.json()

        if "txs" in data:
            # Find the most recent transaction in the list of transactions
            transactions = data["txs"]
            if transactions:
                most_recent_tx = max(transactions, key=lambda x: x["time"])
                last_tx_date = most_recent_tx["time"]
                last_tx_date_formatted = format_timestamp_to_month_year(last_tx_date)
                print(f"Address: {address}, Last Transaction Date: {last_tx_date_formatted}\n")
            else:
                print(f"Address: {address}, No last transaction data available\n")
        else:
            print(f"Address: {address}, No transaction data available\n")
    else:
        print(f"Address: {address}, Error fetching data\n")
    
    # Introduce a 1-second delay between checking addresses
    time.sleep(1)

def format_timestamp_to_month_year(timestamp): # Convert UNIX timestamp to month/year format from datetime import datetime date = datetime.utcfromtimestamp(timestamp) return date.strftime("%B %Y")

Specify the filename containing the list of Bitcoin addresses

filename = "btc500.txt"

check_address_last_transaction_dates(filename)

with this code you can check last transaction date/year only no other information.....replace your btc address list file with btc500.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.