Sweeping funds from addresses generated by Extended Private Key (BIP39) I have a site that is trying to process micropayments. It uses a mnemonic / extended private key generated here to generate a new Bitcoin address for every payment.

Everything works fine except I'm realizing now that it will be expensive to recover funds from the generated addresses because it will cost a ~10,000 satoshi mining fee per address.

This is a small fee but it is too high considering the totals being extracted are only 20,000 to 30,000 satoshi.

Are there any options to solve this problem? I know Bitcoin has this concept of "sweeping" funds. Does that still involve incurring a flat fee for every address generated by the master private key?

A few other options I've been considering:


BlockCypher had a microtransactions API which seems to be shut down now
Some node APIs including BlockCypher offer payment forwarding though I don't understand the fees involved or how it works internally
Payment channels / Lightning Network
I know Bitcoin has this concept of "sweeping" funds. Does that still involve incurring a flat fee for every address generated by the master private key?


No, sweeping an address involves inputting a private key into some wallet software, and then having the wallet software initiate a tx to empty that address’ funds entirely into a new address that the wallet controls the private keys for.

While a BIP39 xpriv key can be used to derive many child keypairs, the xpriv cannot itself be used to spend the UTXOs of those child addresses. You need the private key of each address in order to spend it’s funds. The network has no way of knowing how a key pair was derived, so only the private key of each individual address can spend its funds. 

For best efficiency, you’ll want to batch all of the UTXOs into a single transaction with a single output (or maybe more than one, depending on how you want to divide and store the funds). 

A single tx with a lot of inputs will have a higher fee than any single tx, but it will be lower than the total fees paid if you send each one individually. 

I’m not familiar with blockcypher, but in general if a tx is sent on the network, and then you’d like to spend those funds again, a network fee will be incurred. So I’m not sure their service will save you money in the way you’re looking for. 

Lightning network is a potential solution for payment processing with lower fees, but the network is still young so it will take a little time for adoption to happen.