What options do I have to avoid API gap limit? I am using xpub keys


I am building a app, and the design is, the "welcome page" has a qr code allowing the user to purchase a single-use of the app.

Blockchain.info conveniently allows you to use xpub to generate addresses, however, their docs mention bip 44, and the "gap limit"... This is instantly a problem as I can imagine, say 30 users simultaneously going to the app (more realistically, 30 users going to the app under the amount of time it takes a single user to purchase), 20 will be presented bitcoin addresses to purchase, 10 will not due to the api throwing gap limit errors.

What options do I have to get around this?

I've had others suggest I just manually generate a bunch of private keys and not use xpub, but manually having to consolidate all of those single-transactions-per-address just sounds like an absolute nightmare that I would like to avoid.


Is there any way at all to re-use the same address every time, but attach a guid to it so that when I see the txn broadcasted, I can link it with a given user's session? This is really all that I need. I don't need xpub.. I just need a way to identify that user A and user B both are viewing the welcome page, user A doesn't pay, user B does, user B is automatically given access, user A is not.


Posted 2018-03-19T06:51:49.397

Reputation: 173


Possible duplicate of How to solve Blockchain 20 address gap-limit problem?

– pebwindkraft – 2018-03-19T09:29:47.567

1@pebwindkraft unfortunately that post doesn't offer any sort of solution or suggestion. – patrick – 2018-03-19T17:46:51.420

Use https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#Public_parent_key_rarr_public_child_key ? Do you need an implementation?

– MCCCS – 2018-03-20T04:22:31.693



Issues related to gap limit as summarized in this blog post. Basically you have few options

  • Use wallets like electrum to increase gap limit setting
  • Automatically send small amount of funds to 20th unsued address to keep things going. This is done by services like blockonomics
  • Keep generating new address without worrying about gap limit. Later you can generate all private keys using xprv and sweep in the funds from all private keys.

dark knight

Posted 2018-03-19T06:51:49.397

Reputation: 1 631

can give me more information about the 3rd option? – patrick – 2018-06-10T16:18:55.347


Here's my solution.

When gap limit is reached, append a random and unique satoshi amount to the total bitcoin amount and associate it with the user.

For example, if your product price is BTC 0.001, then generate an amount like 0.00100001 for user A, 0.00100002 for user B, both using the same address when gap is reached.

Now for user A, you use Blockchain.info's Receive API. In the database, you record user A, price and address.

Now in the case of user B, you use the Balance Update API. In the databae, you also record user B, price and address.

So when you receive the notification, you can check which user made the payment by checking the amount paid.


Posted 2018-03-19T06:51:49.397

Reputation: 141

This is not a solution. It can make disaster. you should not give an address to two users at the same time and wait if one of them sending the amount. How about a time that two of them sent the amount?! That's not small collateral. That's very big flaw of this method. – ICE – 2018-05-29T23:37:50.357

First user send money and you return *ok* for your callback. 2nd user send money and the wallet don't do callback because you returned *ok* for that address before. so does not monitor anymore. it means you can not even know the second user paid! – ICE – 2018-05-30T03:24:36.253

Another better solution to this, you can use the "Balance Update" notification. – ethmz – 2018-05-30T10:52:01.013

Waiting for more callbacks after one paid is bad. Maybe you get the first confirmation callback for 2nd user in the 48 hours. Balance Update is not a solution for gap limit. It seems HD wallets are not for merchant. They have big flaw for online stores and they can not handle big or even small online stores. – ICE – 2018-05-30T17:29:20.567

Small or big collateral doesn't matter. both of them are equal to a faulty system. – ICE – 2018-05-30T22:23:08.507