<p>Bitcoin wallet accounts are designed for personal use, so your use case requires to develop on a different layer, as explained by G. Maxwell here: <a href="https://github.com/bitcoin/bitcoin/issues/3816#issuecomment-37052569" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/issues/3816#issuecomment-37052569</a></p>

CC BY-SA 4.0
2019-09-02T13:36:18.610Z
Also this comment is appropriate, IMHO: https://github.com/bitcoin/bitcoin/issues/3816#issuecomment-37097158
cisba
CC BY-SA 4.0
2019-09-02T13:31:54.750Z
2019-09-02T13:31:54.750Z
cisba
<p>It is possible to mimic the same functionality of getaccountaddress using a label.</p>

<p>This is an example in python:</p>

<pre><code>#!/usr/bin/env python3

import bitcoin.rpc

bitcoin.SelectParams('regtest')
proxy = bitcoin.rpc.Proxy()

def get_unused_address():
    label = 'donations'
    unused = None
    try:
        addr_list = proxy.call('getaddressesbylabel', label)
    except bitcoin.rpc.JSONRPCError as err: 
        if err.error['code'] == -11:
            # No addresses with label
            addr_list = None
    if addr_list:
        # Addresses with label found
        for addr in list(addr_list.keys()):
            # Check for tx received
            r = proxy.call('listreceivedbyaddress', 0, True, False, addr)
            if not len(r[0]['txids']):
                # Unused address found!
                unused = addr
                break
            else:
                # Used address found, remove label
                proxy.call('setlabel', addr, '')
    if not unused:
        # Address with label not found, generate a new one
        unused = proxy.getnewaddress(label)
    return unused

print("Unused address is: %s" % get_unused_address())
</code></pre>

CC BY-SA 4.0
2019-08-30T04:38:26.950Z
sorry, I cannot accept this answer. this is exactly what I'm describing in the question and the problem with scalability it has is what's important. just imagine `getaddressesbylabel` returning 1 mln of addresses…
ConstB
CC BY-SA 4.0
2019-09-02T13:12:03.513Z
Sorry, I missed your problem of scalability... 
In your case I think the answer is very similar to this:
https://bitcoin.stackexchange.com/a/70595/47356
cisba
CC BY-SA 4.0
2019-08-26T12:13:00.170Z
2019-08-26T12:13:00.170Z
cisba
<p>The problem is <code>getaccountaddress</code> is getting deprecated and it has specific behaviour (not related to accounts) I'm relying heavily on. It gives you <strong>the same address between multiple calls</strong> as long as there are no incoming transactions…</p>

<p>What I'm doing essentially is calling <code>getaccountaddress ""</code> every time an address needs to be displayed.</p>

<p>The problem is <code>getnewaddress</code> is designed to always provide you with a new address, so I end up flooding wallet with meaningless amount of addresses that never receive anything.</p>

<p>I'm trying to replicate that old behaviour using labels API, but the best I've come up with is to combine <code>getaddressesbylabel</code> and parsing everything <code>listtransactions</code> outputs to find if there's an unused receive-typed address, and to generate new one if none found.</p>

<p>This seems both error prone and hardly scalable, because the number of addresses will potentially grow and may become very large very fast.</p>

<p>What are my options? Is there an API call that can be used as a replacement for <code>getaccountaddress ""</code> or a combination of calls?</p>

<bitcoind><bitcoin-core-accounts>
How to replicate getaccountaddress behaviour using getnewaddress and labels api
ConstB
# How to replicate getaccountaddress behaviour using getnewaddress and labels api

(Asked by: username_0 on 2019-05-17)

The problem is `getaccountaddress` is getting deprecated and it has specific behaviour (not related to accounts) I'm relying heavily on. It gives you **the same address between multiple calls** as long as there are no incoming transactions…

What I'm doing essentially is calling `getaccountaddress ""` every time an address needs to be displayed.

The problem is `getnewaddress` is designed to always provide you with a new address, so I end up flooding wallet with meaningless amount of addresses that never receive anything.

I'm trying to replicate that old behaviour using labels API, but the best I've come up with is to combine `getaddressesbylabel` and parsing everything `listtransactions` outputs to find if there's an unused receive-typed address, and to generate new one if none found.

This seems both error prone and hardly scalable, because the number of addresses will potentially grow and may become very large very fast.

What are my options? Is there an API call that can be used as a replacement for `getaccountaddress ""` or a combination of calls?

**Tags:** bitcoind, bitcoin-core-accounts


---

## 2 answers

### Answer by username_1 on 2019-09-02. Score: 1

Bitcoin wallet accounts are designed for personal use, so your use case requires to develop on a different layer, as explained by G. Maxwell here: <https://github.com/bitcoin/bitcoin/issues/3816#issuecomment-37052569>

> **Comments:**
> **username_1**: Also this comment is appropriate, IMHO: https://github.com/bitcoin/bitcoin/issues/3816#issuecomment-37097158  

---

### Answer by username_1 on 2019-08-26. Score: 0

It is possible to mimic the same functionality of getaccountaddress using a label.
This is an example in python:
#!/usr/bin/env python3

import bitcoin.rpc

bitcoin.SelectParams('regtest')
proxy = bitcoin.rpc.Proxy()

def get_unused_address():
    label = 'donations'
    unused = None
    try:
        addr_list = proxy.call('getaddressesbylabel', label)
    except bitcoin.rpc.JSONRPCError as err: 
        if err.error['code'] == -11:
            # No addresses with label
            addr_list = None
    if addr_list:
        # Addresses with label found
        for addr in list(addr_list.keys()):
            # Check for tx received
            r = proxy.call('listreceivedbyaddress', 0, True, False, addr)
            if not len(r[0]['txids']):
                # Unused address found!
                unused = addr
                break
            else:
                # Used address found, remove label
                proxy.call('setlabel', addr, '')
    if not unused:
        # Address with label not found, generate a new one
        unused = proxy.getnewaddress(label)
    return unused

print("Unused address is: %s" % get_unused_address())

> **Comments:**
> **username_0**: sorry, I cannot accept this answer. this is exactly what I'm describing in the question and the problem with scalability it has is what's important. just imagine `getaddressesbylabel` returning 1 mln of addresses…  
> **username_1**: Sorry, I missed your problem of scalability...  In your case I think the answer is very similar to this: https://bitcoin.stackexchange.com/a/70595/47356  

---

