<p>I do something similar in PHP using <a href="https://github.com/aceat64/EasyBitcoin-PHP" rel="nofollow noreferrer">https://github.com/aceat64/EasyBitcoin-PHP</a> connecting to a full bitcoind client rather than Electrum. An <em>in</em>ternal API, if you will.</p>

<p>On the downside, it will download the entire blockchain. On the upside, once up-to-date it handles almost all of the heavy lifting described in your second paragraph.</p>

<p>While I don't associate users/transactions as you describe, if I did I would investigate whether <em>accounts</em> supported in the bitcoind client would assist you: 
<pre>$address = $bitcoin->getnewaddress($user_id)</pre> looks to associate the two such that <pre>$balance = $bitcoin->getbalance($user_id, 6)</pre> will give you the balance with more than six confirmations held by that user across all his addresses.</p>

CC BY-SA 4.0
2018-12-31T09:27:22.643Z
2018-12-31T09:27:22.643Z
Alistair Mann
<p>You can do this easily using bitcoincore. Brief overview of process (Source: <a href="https://bitcointalk.org/index.php?topic=1442574.0" rel="nofollow noreferrer">bitcointalk thread</a>)</p>

<ol>
<li>Generate unique address using <em>getnewaddress</em></li>
<li>Register on <em>walletnotify</em> to get txid as notification</li>
<li>Call <em>gettransaction</em> with txid from step 2 to get details/address of payment received </li>
</ol>

CC BY-SA 4.0
2018-12-31T09:12:30.337Z
2018-12-31T09:12:30.337Z
dark knight
<p>Depends, shared or dedicated hosting? </p>

<p>With <strong>shared</strong> you really are limited to 3rd party APIs or the method you already mentioned of generating bulk keys and tracking them in a database. You could use a  client-side javascript combined with an xpub you own, but then you have the privacy issue of sharing your xpub in the source and you have to manually track payments.</p>

<p>If <strong>dedicated</strong>, you can run a pruned node <code>prune=550</code> which can be done on a relatively affordable VPS and generate addresses on the fly with <code>getnewaddress</code>  RPC calls and auto update the database with <code>walletnotify=curl https://mysite.com/callback.php?txid=%s</code> where %s is the transaction id, but you will want to use a secret parameter as well for security. Wallet notify is fired once upon the transaction entering your mempool and then once again after confirmation. <code>gettransaction &lt;txid&gt;</code> can be used to get transaction details and determine who in your database paid based on the receiving address. </p>

CC BY-SA 4.0
2019-01-04T06:18:07.187Z
2019-01-04T06:28:54.283Z
2019-01-04T06:28:54.283Z
m1xolyd1an
<p>I run an application written in PHP and need to add the option to buy services with bitcoins.
So, for each user i need to generate a unique, unused bitcoin address.</p>

<p>I could generate X number wallets with Electrum and assing 1 address to each user, but then i will have to check manually if someone send a payment, match the address with the user, wait for confirmations, import data, update the balance, every day. 
This take too much time and it's tricky. </p>

<p>What's the best and easier approach to achieve this? from where i start?
Using external api and services is not a choice, using a single shared wallet can be okay but how i associate user/transaction?</p>

<wallet><electrum><php>
Generating bitcoin wallets for my customers
im7xs
# Generating bitcoin wallets for my customers

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

I run an application written in PHP and need to add the option to buy services with bitcoins.
So, for each user i need to generate a unique, unused bitcoin address.

I could generate X number wallets with Electrum and assing 1 address to each user, but then i will have to check manually if someone send a payment, match the address with the user, wait for confirmations, import data, update the balance, every day.
This take too much time and it's tricky.

What's the best and easier approach to achieve this? from where i start?
Using external api and services is not a choice, using a single shared wallet can be okay but how i associate user/transaction?

**Tags:** wallet, electrum, php


---

## 3 answers

### Answer by username_1 on 2018-12-31. Score: 1 | Accepted answer

I do something similar in PHP using <https://github.com/aceat64/EasyBitcoin-PHP> connecting to a full bitcoind client rather than Electrum. An *in*ternal API, if you will.

On the downside, it will download the entire blockchain. On the upside, once up-to-date it handles almost all of the heavy lifting described in your second paragraph.

While I don't associate users/transactions as you describe, if I did I would investigate whether *accounts* supported in the bitcoind client would assist you:

```
$address = $bitcoin->getnewaddress($user_id)
```

looks to associate the two such that

```
$balance = $bitcoin->getbalance($user_id, 6)
```

will give you the balance with more than six confirmations held by that user across all his addresses.


---

### Answer by username_2 on 2018-12-31. Score: 1

You can do this easily using bitcoincore. Brief overview of process (Source: [bitcointalk thread](https://bitcointalk.org/index.php?topic=1442574.0))

1. Generate unique address using *getnewaddress*
2. Register on *walletnotify* to get txid as notification
3. Call *gettransaction* with txid from step 2 to get details/address of payment received


---

### Answer by username_3 on 2019-01-04. Score: 1

Depends, shared or dedicated hosting?

With **shared** you really are limited to 3rd party APIs or the method you already mentioned of generating bulk keys and tracking them in a database. You could use a client-side javascript combined with an xpub you own, but then you have the privacy issue of sharing your xpub in the source and you have to manually track payments.

If **dedicated**, you can run a pruned node `prune=550` which can be done on a relatively affordable VPS and generate addresses on the fly with `getnewaddress` RPC calls and auto update the database with `walletnotify=curl https://mysite.com/callback.php?txid=%s` where %s is the transaction id, but you will want to use a secret parameter as well for security. Wallet notify is fired once upon the transaction entering your mempool and then once again after confirmation. `gettransaction <txid>` can be used to get transaction details and determine who in your database paid based on the receiving address.


---

