<blockquote>
<p><strong>This script refuses to read my xpub,</strong></p>
</blockquote>
<blockquote>
<pre><code> xpub = Key.from_text('xpub')
</code></pre>
</blockquote>
<p>Other examples I have seen show the argument to <code>from_text()</code> as expecting a key in wallet interchange format (WIF). I don't know whether you have &quot;xpub&quot; 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</p>
<p>However that API seems to be obsolete, according to</p>
<p><a href="https://github.com/richardkiss/pycoin/issues/316" rel="nofollow noreferrer">https://github.com/richardkiss/pycoin/issues/316</a></p>

CC BY-SA 4.0
2023-11-10T14:08:29.870Z
2023-11-10T14:08:29.870Z
RedGrittyBrick
<p>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.</p>
<p>I am using python, and tried pycoin.</p>
<p>A script that looks fine, but I couldn't get to work.</p>
<pre class="lang-python prettyprint-override"><code>from pycoin.key import Key
import sys
import requests
import json
import datetime

def getbalance(address):
  response = requests.get(&quot;https://bitaps.com/api/address/%s&quot; % address)
  if response.status_code != 200:
    return None
  return response.json()
  
def listtransactions(address):
  response = requests.get(&quot;https://bitaps.com/api/address/transactions/%s&quot; % 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(&quot;Type %d (%d): %s&quot; % (account_type, index, addr))
    
    # Report balance data
    balancedata = getbalance(addr)
    balance = balancedata['confirmed_balance']
    balance_btc = balance # satoshis_to_btc(balance)
    print(&quot;  Balance: %s&quot; % 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(&quot;    Transaction (%s): %s %s&quot; % (tx_timestr, tx_type, tx_amount))

    print(&quot;&quot;)
    
    if transactions == None:
        break
    index += 1

def main():

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

main()
</code></pre>
<p>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.</p>
<p><strong>Edit</strong>
I have an xpub, what are the necessary steps to get all transactions?</p>

CC BY-SA 4.0
2023-11-06T09:27:46.343Z
Does this answer your question? [bitcoin address from xpub key](https://bitcoin.stackexchange.com/questions/77539/bitcoin-address-from-xpub-key)
RedGrittyBrick
CC BY-SA 4.0
2023-11-06T10:40:22.150Z
Not teally. I want to get all my adress belonging to a key, and loop through all of them to check the funds
donbolli
CC BY-SA 4.0
2023-11-06T14:00:58.297Z
I believe you can achieve that by iterating the code in that answer over the corresponding values of the appropriate derivation path.
RedGrittyBrick
CC BY-SA 4.0
2023-11-06T14:53:09.993Z
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
CC BY-SA 4.0
2023-11-06T15:22:07.360Z
I hope the updated question is better
donbolli
<python><address-generation><xpub>
Python Script not working / From Xpub to everything
donbolli
# Python Script not working / From Xpub to everything

(Asked by: username_0 on 2023-11-06)

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.

```python
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))

    print("")
    
    if transactions == None:
        break
    index += 1

def main():

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

main()

```

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?

**Tags:** python, address-generation, xpub

> **Comments:**
> **username_1**: Does this answer your question? [bitcoin address from xpub key](https://bitcoin.stackexchange.com/questions/77539/bitcoin-address-from-xpub-key)  
> **username_0**: Not teally. I want to get all my adress belonging to a key, and loop through all of them to check the funds  
> **username_1**: I believe you can achieve that by iterating the code in that answer over the corresponding values of the appropriate derivation path.  
> **username_2**: 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.  
> **username_0**: I hope the updated question is better  

---

## 1 answers

### Answer by username_1 on 2023-11-10. Score: 1 | Accepted answer

> **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

<https://github.com/richardkiss/pycoin/issues/316>


---

