<p>You may have already read this, but make sure you read this if you want to know about how the accounts feature of the core client works: <a href="https://en.bitcoin.it/wiki/Accounts_explained" rel="noreferrer">https://en.bitcoin.it/wiki/Accounts_explained</a>. (It's somewhat of a legacy feature.)</p>

<p>Are you looking to be able to do this manually with the RPC methods, or automated? </p>

<p>For manually, do:</p>

<pre><code>bitcoin-cli getaddressesbyaccount "donations"
</code></pre>

<p>If the JSON array returned is empty, then no address is associated. To create a new bitcoin address with that label, do:</p>

<pre><code>bitcoin-cli getnewaddress "donations"
</code></pre>

<p>To get an address for the "donations" account, do:</p>

<pre><code>bitcoin-cli getaccountaddress "donations"
</code></pre>

CC BY-SA 4.0
2020-01-06T12:05:24.297Z
`bitcoin-cli getaccountaddress "..."` has been deprecated. It would be nice if this answer were updated
Robert Johnstone
CC BY-SA 3.0
2015-01-03T01:47:34.017Z
2015-01-03T01:47:34.017Z
morsecoder
<p>I'm familiar with the basic RPC commands, but I'm having trouble retrieving/adding an address to a wallet, using purely RPC calls (i.e. bitcoind only, not bitcoin-qt).</p>

<p>My understanding is that addresses are associated with accounts, but I'm unsure what role "accounts" play, and how to create new ones etc.</p>

<p>In pseudocode, this is what I want to be able to do:</p>

<pre><code>if (count(getAddressesByLabel("donations")) == 0) {
    address = wallet.createBitcoinAddress();
    address.setLabel("donations");
}

donationAddress = getAddressesByLabel("donations"))
</code></pre>

CC BY-SA 3.0
2015-01-03T18:57:14.447Z
@GeorgeKimionis - do you have any documentation for those changes and views? Surely labels are backed up with the wallet?
Craig Watson
<wallet><bitcoind><address><json-rpc><address-generation>
How to get a wallet address and set label via RPC?
Craig Watson
# How to get a wallet address and set label via RPC?

(Asked by: username_0 on 2015-01-03)

I'm familiar with the basic RPC commands, but I'm having trouble retrieving/adding an address to a wallet, using purely RPC calls (i.e. bitcoind only, not bitcoin-qt).

My understanding is that addresses are associated with accounts, but I'm unsure what role "accounts" play, and how to create new ones etc.

In pseudocode, this is what I want to be able to do:

```
if (count(getAddressesByLabel("donations")) == 0) {
    address = wallet.createBitcoinAddress();
    address.setLabel("donations");
}

donationAddress = getAddressesByLabel("donations"))

```

**Tags:** wallet, bitcoind, address, json-rpc, address-generation

> **Comments:**
> **username_0**: @GeorgeKimionis - do you have any documentation for those changes and views? Surely labels are backed up with the wallet?  

---

## 1 answers

### Answer by username_1 on 2015-01-03. Score: 6 | Accepted answer

You may have already read this, but make sure you read this if you want to know about how the accounts feature of the core client works: <https://en.bitcoin.it/wiki/Accounts_explained>. (It's somewhat of a legacy feature.)

Are you looking to be able to do this manually with the RPC methods, or automated?

For manually, do:

```
bitcoin-cli getaddressesbyaccount "donations"

```

If the JSON array returned is empty, then no address is associated. To create a new bitcoin address with that label, do:

```
bitcoin-cli getnewaddress "donations"

```

To get an address for the "donations" account, do:

```
bitcoin-cli getaccountaddress "donations"

```

> **Comments:**
> **username_2**: `bitcoin-cli getaccountaddress "..."` has been deprecated. It would be nice if this answer were updated  

---

