<p>You're mostly on the right track.</p>

<p>The ideal way to build a user deposit system is to simply have a one to many <code>user-&gt;address</code> mapping.</p>

<p>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.</p>

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

<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 4.0
2018-08-12T21:24:04.573Z
2018-08-12T21:24:04.573Z
Raghav Sood
<p>Trying to create a bitcoin based webapp in python which takes BTC deposits (New to Bitcoin in general, but want to get involved). </p>

<p>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. </p>

<p>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 </p>

<ol>
<li><p>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.</p>

<pre><code>my_private_key = sha256('I guess whatever I please')
my_public_key = privtopub(my_private_key)
my_address = pubtoaddr(my_public_key)
</code></pre></li>
<li><p>Accept a Deposit into this Address. </p></li>
<li>Return the BTC value of this address.</li>
<li>When the time comes, send the balance of this address to the users own address.</li>
</ol>

<python><pybitcointools>
Trying to create a bitcoin based webapp in python which takes BTC deposits. How would I use pybitcointools to implement this?
jacobwon
# Trying to create a bitcoin based webapp in python which takes BTC deposits. How would I use pybitcointools to implement this?

(Asked by: username_0 on 2018-08-12)

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.

**Tags:** python, pybitcointools


---

## 1 answers

### Answer by username_1 on 2018-08-12. Score: 0

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.


---

