3

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?

2

This is entirely possible with an optional additon to Bitcoin called BIP32. 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, then have them give you their extended public key.

    (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, 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!

  • 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 Apr 16 '15 at 23:01
  • 1
    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 Apr 17 '15 at 16:45
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.