<p>This is entirely possible with an optional additon to Bitcoin called <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow noreferrer">BIP32</a>. Unfortunately, BIP32 is not implemented by the standard client, but there are other clients that do implement it.</p>

<ol>
<li><p>Ask your customer to download the latest version of <a href="https://electrum.org/" rel="nofollow noreferrer">Electrum</a>, then have them give you their <a href="https://bitcoin.stackexchange.com/questions/36957/how-do-i-view-the-extended-public-key-in-electrum/36958#36958">extended public key</a>.</p>

<p>(As I said above, there are multiple clients that can do this, I'm just most familiar with Electrum.)</p></li>
<li><p>Include this code in your BitcoinJ application:</p>

<pre><code>String serialized_xpub = "xpub.....";
unsigned int address_num = 4;
NetworkParameters params = MainNetParams.get();
DeterministicKey root_xpub = DeterministicKey.deserializeB58(null, serialized_xpub, params);

// Derive m/0/&lt;n&gt;, Electrum's BIP32 path
DeterministicKey receiving = HDKeyDerivation.deriveChildKey(root_xpub, new ChildNumber(0, false));
DeterministicKey new_address_key = HDKeyDerivation.deriveChildKey(receiving, new ChildNumber(address_num, false));
String new_address = new_address_key.toAddress().toString();
</code></pre>

<p>You will generate the same address as long as you use the same xpub and <code>address_num</code>. Make sure that you don't <a href="https://bitcoin.stackexchange.com/questions/35555/what-does-it-mean-when-addresses-are-labelled-beyond-the-gap-limit-highlighted">skip five or more addresses</a>, though. If you do end up doing this, then your customer can generate addresses until they see the new payments.</p>

<p>Also, note that you don't have the private key for this address. If your customer loses their wallet, those coins are gone.</p></li>
<li><p>Put that address on the invoice.</p></li>
<li><p>The money will show up in their wallet. </p></li>
</ol>

<p>Best of luck with your application!</p>

CC BY-SA 3.0
2015-04-16T23:01:28.213Z
Aha! I think this is just what I need. I had seen the discussion of BIP32 around, but I have installed Bitcoin-QT which didn't seem to contain any of that. That explains a lot to me. I'll check this out tomorrow as it's just hitting quitting hour for me today, and report back, but I don't suspect difficulties. Thank you.
S. Buda
CC BY-SA 3.0
2015-04-17T16:45:56.503Z
Sweet, I think I have it working, at least simplisticly. I needed to make a couple changes to your code, not sure if it was due to a change in the library or something. Anyways, I didn't add the network parameters to `root_xpub` when it was created, instead I had to change the address generator to be `new_address_key.toAddress(params)`
S. Buda
CC BY-SA 3.0
2015-04-16T22:56:21.927Z
2015-04-22T22:31:49.017Z
2017-04-13T12:47:33.743Z
Nick ODell
<p>Take a look at bitcoin payments for woocommerce plugin. It can generate unlimited addresses from a single electrum master public key. You can't spend using just the public key so it is safe too.</p>

CC BY-SA 3.0
2015-04-18T20:26:53.320Z
2015-04-18T20:26:53.320Z
coinfirmed
<p><strong>TL;DR</strong> <em>I wish to store some sort of key in my application for each vendor account that allows for my application to generate a receiving address for clients to make payments to.</em></p>

<p>I am writing some invoice software in Java that I would like to allow to use bitcoin. Basically what I want to have happen is a vendor can save some sort of key to their account details (sorta like the PayPal id and secret key) and any clients paying to that vendor via bitcoin will be given the url to pay to. I don't want this to be a middle man software in the sense that I will never have any bitcoins on my server, I won't accept payments, it only serves to give a payment address of the vendor to a client.</p>

<p>I am under the understanding that this would be possible using the receiving address, however it is not good to use one address for every payment so that is out of the question. I don't want a vendor to have to add a new address after every payment because that isn't at all user friendly.</p>

<p>So I'm wondering if there's some way I can generate addresses for the vendor on my server without holding their wallet. I have been looking at bitcoinj and it seems like there may be some way to do it, but I am quite new to bitcoin. Is that even a possibility? Is this a reasonable expectation for my application to have? If not, do I have any other options?</p>

<bitcoinj><java><receiving>
Accept payments on someone else's behalf without being able to spend them
S. Buda
# Accept payments on someone else's behalf without being able to spend them

(Asked by: username_0 on 2015-04-16)

**TL;DR** *I wish to store some sort of key in my application for each vendor account that allows for my application to generate a receiving address for clients to make payments to.*

I am writing some invoice software in Java that I would like to allow to use bitcoin. Basically what I want to have happen is a vendor can save some sort of key to their account details (sorta like the PayPal id and secret key) and any clients paying to that vendor via bitcoin will be given the url to pay to. I don't want this to be a middle man software in the sense that I will never have any bitcoins on my server, I won't accept payments, it only serves to give a payment address of the vendor to a client.

I am under the understanding that this would be possible using the receiving address, however it is not good to use one address for every payment so that is out of the question. I don't want a vendor to have to add a new address after every payment because that isn't at all user friendly.

So I'm wondering if there's some way I can generate addresses for the vendor on my server without holding their wallet. I have been looking at bitcoinj and it seems like there may be some way to do it, but I am quite new to bitcoin. Is that even a possibility? Is this a reasonable expectation for my application to have? If not, do I have any other options?

**Tags:** bitcoinj, java, receiving


---

## 2 answers

### Answer by username_1 on 2015-04-16. Score: 2 | Accepted answer

This is entirely possible with an optional additon to Bitcoin called [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki). Unfortunately, BIP32 is not implemented by the standard client, but there are other clients that do implement it.

1. Ask your customer to download the latest version of [Electrum](https://electrum.org/), then have them give you their [extended public key](https://bitcoin.stackexchange.com/questions/36957/how-do-i-view-the-extended-public-key-in-electrum/36958#36958).

   (As I said above, there are multiple clients that can do this, I'm just most familiar with Electrum.)
2. Include this code in your BitcoinJ application:

   ```
   String serialized_xpub = "xpub.....";
   unsigned int address_num = 4;
   NetworkParameters params = MainNetParams.get();
   DeterministicKey root_xpub = DeterministicKey.deserializeB58(null, serialized_xpub, params);

   // Derive m/0/<n>, Electrum's BIP32 path
   DeterministicKey receiving = HDKeyDerivation.deriveChildKey(root_xpub, new ChildNumber(0, false));
   DeterministicKey new_address_key = HDKeyDerivation.deriveChildKey(receiving, new ChildNumber(address_num, false));
   String new_address = new_address_key.toAddress().toString();

   ```

   You will generate the same address as long as you use the same xpub and `address_num`. Make sure that you don't [skip five or more addresses](https://bitcoin.stackexchange.com/questions/35555/what-does-it-mean-when-addresses-are-labelled-beyond-the-gap-limit-highlighted), though. If you do end up doing this, then your customer can generate addresses until they see the new payments.

   Also, note that you don't have the private key for this address. If your customer loses their wallet, those coins are gone.
3. Put that address on the invoice.
4. The money will show up in their wallet.

Best of luck with your application!

> **Comments:**
> **username_0**: Aha! I think this is just what I need. I had seen the discussion of BIP32 around, but I have installed Bitcoin-QT which didn't seem to contain any of that. That explains a lot to me. I'll check this out tomorrow as it's just hitting quitting hour for me today, and report back, but I don't suspect difficulties. Thank you.  
> **username_0**: Sweet, I think I have it working, at least simplisticly. I needed to make a couple changes to your code, not sure if it was due to a change in the library or something. Anyways, I didn't add the network parameters to `root_xpub` when it was created, instead I had to change the address generator to be `new_address_key.toAddress(params)`  

---

### Answer by username_2 on 2015-04-18. Score: 0

Take a look at bitcoin payments for woocommerce plugin. It can generate unlimited addresses from a single electrum master public key. You can't spend using just the public key so it is safe too.


---

