I made a small webapplication to keep track of my wallets. So I want to grab everything i have, using my xpub. Looping through every adress. On the Internet I could find diffrent scripts, but I could none of them getting to work.

I am using python, and tried pycoin.

A script that looks fine, but I couldn't get to work.

from pycoin.key import Key
import sys
import requests
import json
import datetime

def getbalance(address):
  response = requests.get("https://bitaps.com/api/address/%s" % address)
  if response.status_code != 200:
    return None
  return response.json()
def listtransactions(address):
  response = requests.get("https://bitaps.com/api/address/transactions/%s" % address)
  if response.status_code != 200:
    return None
  return response.json()

def probe_used_addresses(xpub, account_type):
  xpub_subkey = xpub.subkey(account_type)
  index = 0
  while True:
    addr = xpub_subkey.subkey(index).bitcoin_address()
    print("Type %d (%d): %s" % (account_type, index, addr))
    # Report balance data
    balancedata = getbalance(addr)
    balance = balancedata['confirmed_balance']
    balance_btc = balance # satoshis_to_btc(balance)
    print("  Balance: %s" % balance_btc)
    # List transactions, if any...
    transactions = listtransactions(addr)
    if transactions != None:
      for tx in transactions:
        tx_time = datetime.datetime.fromtimestamp(float(tx[0]))
        tx_hash = tx[1]
        tx_data = tx[2]
        tx_type = tx[3]
        tx_status = tx[4]
        tx_confirmations = tx[5]
        tx_block = tx[6]
        tx_amount = tx[7]
        tx_timestr = tx_time.isoformat()
        print("    Transaction (%s): %s %s" % (tx_timestr, tx_type, tx_amount))

    if transactions == None:
    index += 1

def main():

  xpub = Key.from_text('xpub')
  probe_used_addresses(xpub, 0)
  probe_used_addresses(xpub, 1)


This script refuses to read my xpub, first I gonna use some block explorer and in a next step I want to use the data from my node.

Edit I have an xpub, what are the necessary steps to get all transactions?

  • Does this answer your question? bitcoin address from xpub key Commented Nov 6, 2023 at 9:27
  • Not teally. I want to get all my adress belonging to a key, and loop through all of them to check the funds
    – donbolli
    Commented Nov 6, 2023 at 10:40
  • I believe you can achieve that by iterating the code in that answer over the corresponding values of the appropriate derivation path. Commented Nov 6, 2023 at 14:00
  • 1
    When you are clarifying your question in response to comments, please also edit your question instead of just leaving the additional information in a comment.
    – Murch
    Commented Nov 6, 2023 at 14:53
  • I hope the updated question is better
    – donbolli
    Commented Nov 6, 2023 at 15:22

1 Answer 1


This script refuses to read my xpub,

 xpub = Key.from_text('xpub')

Other examples I have seen show the argument to from_text() as expecting a key in wallet interchange format (WIF). I don't know whether you have "xpub" as a placeholder for that, a filename, or if that is a literal value of 4 ASCII bytes - which would be invalid as a key

However that API seems to be obsolete, according to


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.