<p>As a Java programmer who has dealt with BitcoinJ, I highly suggest using Jython to embed python bitcoin libraries for Bitcoin related tasks within your program. BitcoinJ is mostly unkept and is missing modern features. However, if all you want to do is generate new addresses for each user from a wallet that they own, BitcoinJ is sufficient:</p>
<p>First create a new wallet for the user:</p>
<pre><code>Boolean isTestnet = true;
NetworkParameters params = isTestnet ? TestNet3Params.get() : MainNetParams.get()
Wallet wallet = new Wallet(params);
</code></pre>
<p>Connect to the network (I believe this is optional but not 100% sure):</p>
<pre><code>BlockChain chain = new BlockChain(params, wallet, ...);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addWallet(wallet);
peerGroup.startAndWait();
</code></pre>
<p>Create new addresses:</p>
<pre><code>Address a = wallet.currentReceiveAddress();
ECKey b = wallet.currentReceiveKey();
Address c = wallet.freshReceiveAddress();

assert b.toAddress(wallet.getParams()).equals(a);
assert !c.equals(a);
</code></pre>

CC BY-SA 4.0
2024-08-15T16:58:12.033Z
2024-08-15T16:58:12.033Z
Myles Sherman
<p>Not really for BitcoinJ, but a general approach.</p>
<p>You generate new address for every user you register. Store it in your DB with the userID for future reference.</p>
<p>Create a getAPI taking a String input. use your API endpoint and open the Bitcoin.conf file.</p>
<pre><code>walletnotify=curl &lt;your API&gt;
</code></pre>
<p>If you want to have confirmation logic as well, you may need one more getAPI, and get the endpoint. then update your bitcoin.conf file again with following:</p>
<pre><code>blocknotify=curl &lt;your Block API&gt; 
</code></pre>
<p>Now when user makes the deposit to the address you generated, Bitcoin node will notify your app by calling the wallet notify API. You get the transaction hash. Use that txHash and make a Post call to your daemon with RPc command:</p>
<pre><code>getTransaction &lt;txHash&gt;
</code></pre>
<p>Now you'll have entire transaction object to find which user has made the deposit.</p>
<p>Free tip: Bitcoin node calls walletnotify two times:</p>
<ol>
<li>When a transaction is added to the chain.</li>
<li>When that transaction receives first confirmation.</li>
</ol>
<p>If you don't want more than one confirmation, then blockNotify is not needed.</p>
<p>If you want a practical example, you can check my Github repo, where I have done it. It's not based on BitcoinJ but the logic remains the same:</p>
<pre><code>https://github.com/kunalbarchha/generic-wrapper-for-bitcoinforks
</code></pre>

CC BY-SA 4.0
2021-03-30T13:01:18.950Z
2021-03-30T13:01:18.950Z
Gladiator9120
<p>I need to add Bitcoin payment to my application using the BitcoinJ library, but I'm new to using Bitcoin. I have one thought To create a new address for each new user, but I don't know if this is the right approach or not. Please tell me how to implement it correctly.</p>
<p>(I need to determine from which user the payment was received and in what amount)</p>

<bitcoin-core><bitcoinj><java>
Add bitcoin payments to java app using BitcoinJ
Oleksii Tulei
# Add bitcoin payments to java app using BitcoinJ

(Asked by: username_0 on 2021-03-29)

I need to add Bitcoin payment to my application using the BitcoinJ library, but I'm new to using Bitcoin. I have one thought To create a new address for each new user, but I don't know if this is the right approach or not. Please tell me how to implement it correctly.

(I need to determine from which user the payment was received and in what amount)

**Tags:** bitcoin-core, bitcoinj, java


---

## 2 answers

### Answer by username_1 on 2024-08-15. Score: 1

As a Java programmer who has dealt with BitcoinJ, I highly suggest using Jython to embed python bitcoin libraries for Bitcoin related tasks within your program. BitcoinJ is mostly unkept and is missing modern features. However, if all you want to do is generate new addresses for each user from a wallet that they own, BitcoinJ is sufficient:

First create a new wallet for the user:

```
Boolean isTestnet = true;
NetworkParameters params = isTestnet ? TestNet3Params.get() : MainNetParams.get()
Wallet wallet = new Wallet(params);

```

Connect to the network (I believe this is optional but not 100% sure):

```
BlockChain chain = new BlockChain(params, wallet, ...);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addWallet(wallet);
peerGroup.startAndWait();

```

Create new addresses:

```
Address a = wallet.currentReceiveAddress();
ECKey b = wallet.currentReceiveKey();
Address c = wallet.freshReceiveAddress();

assert b.toAddress(wallet.getParams()).equals(a);
assert !c.equals(a);

```


---

### Answer by username_2 on 2021-03-30. Score: 0

Not really for BitcoinJ, but a general approach.

You generate new address for every user you register. Store it in your DB with the userID for future reference.

Create a getAPI taking a String input. use your API endpoint and open the Bitcoin.conf file.

```
walletnotify=curl <your API>

```

If you want to have confirmation logic as well, you may need one more getAPI, and get the endpoint. then update your bitcoin.conf file again with following:

```
blocknotify=curl <your Block API> 

```

Now when user makes the deposit to the address you generated, Bitcoin node will notify your app by calling the wallet notify API. You get the transaction hash. Use that txHash and make a Post call to your daemon with RPc command:

```
getTransaction <txHash>

```

Now you'll have entire transaction object to find which user has made the deposit.

Free tip: Bitcoin node calls walletnotify two times:

1. When a transaction is added to the chain.
2. When that transaction receives first confirmation.

If you don't want more than one confirmation, then blockNotify is not needed.

If you want a practical example, you can check my Github repo, where I have done it. It's not based on BitcoinJ but the logic remains the same:

```
https://github.com/kunalbarchha/generic-wrapper-for-bitcoinforks

```


---

