Trying to create a bitcoin based webapp in python which takes BTC deposits (New to Bitcoin in general, but want to get involved).

Although I would preferably want to use a different address for each deposit, (I read the docs and found out how this could be done, but still slightly confused), I would want to allow for users to deposit back into their own wallets. Though I think I got withdrawals figured out.

I tried to understand the (Now unsupported docs) but decided to come here for help because I was still confused. How would I use pybitcointools to

  1. Generate an BTC Address. (New address for each user). I believe I could do the below for each user. So this would generate a unique address upon the creation of each user for them to deposit to.

    my_private_key = sha256('I guess whatever I please')
    my_public_key = privtopub(my_private_key)
    my_address = pubtoaddr(my_public_key)
  2. Accept a Deposit into this Address.

  3. Return the BTC value of this address.
  4. When the time comes, send the balance of this address to the users own address.

1 Answer 1


You're mostly on the right track.

The ideal way to build a user deposit system is to simply have a one to many user->address mapping.

By default, when a user deposits BTC to an address, you automatically generate a new address for them. However, you don't delete the previous address, or the fact that it is linked to that user.

This way, even if a user sends BTC to an older address, you are able to receive it for them.

Additionally, how you process withdrawals depends on what kind of system you are building. If it is simply a straightforward wallet system, then the process you described of sending the BTC out when the user asks from the user's address will be fine.

If you are building a platform where the user exchanges BTC for goods, services, or other coins, and then makes withdrawals based on their remaining balance, you may want to consider a hot/cold wallet system.

In such a system, when users deposit coins, you provide no guarantee that the same coins will be used to process their withdrawals. You either use all users' coins to process each others withdrawals, or you move them into a handful of addresses, and process all withdrawals from their.

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.