2

I want to setup a REST API service that does 3 simple things.

  1. Ask it to generate a new address (ideally from a BIP32 xpub key tree)
  2. Notify my server application when a deposit and confirmation X happens.
  3. Once the deposit is confirmed, forward the funds to another address and invoke a script in PHP or node.

I was originally going down the bitcoind walletnotify route but a few issues popped up (namely no HD support, scalability of having 10000's of addresses being monitored on a bitcoind is apparently a bad idea?? Is this true?).

I've therefore been setting up Ubuntu as a server and looking at bitcore + bitcoind with node.js to solve this which is painful on v14.04 for some reason... am I barking up the wrong tree and/or is there an easier approach? I can't believe I'm the only one who's needing this so feel like I'm missing an obvious trick here as it's like pulling teeth.

I don't want to rely on a 3rd party server because if they disappeared I don't want to risk my business collapsing overnight. I am happy using 3rd party code base or servers if they are open source though. I've used blockchain.info's API previously which was excellent but really want an in house solution.

1 Answer 1

2

I don't know of a solution that works out-of-the-box with the requirements you've set. However, you can do some of what you need using some command-line tools available on github.

Pycoin has a key utility which can be used to derive bip0032 addresses given a root. Here's a quick primer on how to use it:

$ git clone http://github.com/richardkiss/pycoin
$ cd pycoin
$ sudo make
$ ku <your xpub or xprv key> -s 0/1/2/3/4

This will show you the data on the bip0032 key at the path m/0/1/2/3/4. If you add the -a argument, you can get the address at this path. If you add the -W argument instead (using an xprv key), you get the WIF format. This WIF format can be imported to bitcoind and that in turn can be used to notify you and do what you need afterwards. You can delete that key after payment, which should generally leave the number of addresses being watched lower than it might be (though you'll want to purge every once in a while). This could work, but I would NOT recommend it as it's horrible security. Of course, that's probably why you're forwarding funds to another address right away, so that makes sense.

You're going to have to write some code regardless. bitcore is a fine library for doing HD wallet stuff, but the notification is always the tricky bit.

2
  • Many thanks, these sound like wise words. My main concern is about the notification part in that I'd like bitcoind to invoke some node to invoke a websocket layer to speak to the client. I guess I'm nervous about the scalability of this part, is it feasible for bitcoind to be monitoring 10,000 addresses?
    – sradforth
    Commented Nov 2, 2015 at 10:06
  • It's feasible. You'd have to do some testing to find out, though.
    – Jimmy Song
    Commented Nov 3, 2015 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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