Add bitcoin payments to the Java application using BitcoinJ

Not really for BitcoinJ, but a general approach.

You generate a new address for each user you register. Store it in your database with the user ID for future reference.

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

walletnotify=curl <your API>

If you also want to have confirmation logic, you might need another getAPI and get the endpoint. then update your bitcoin.conf file again as follows:

blocknotify=curl <your Block API> 

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

getTransaction <txHash>

You will now have the full transaction object to find which user made the deposit.

Free tip: Bitcoin node calls walletnotify twice:

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

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

If you want a practical example, you can check out my Github repository, where I did it. It’s not based on BitcoinJ but the logic remains the same:

Source Link

Please follow and like us: