DEV Community

Aaron Akhtar
Aaron Akhtar

Posted on

1 1

How to use the Bitcoin API with Java

This library can be used to:

  • Generate new Bitcoin Addresses;
  • Check the status of a payment and get a transaction receipt;
  • Check the balance of a Bitcoin Address (Unconfirmed and Confirmed);
  • And more.

GitHub Repository: https://github.com/Aaron-Akhtar/Blockonomics-Java-Wrapper
Blockonomics: https://www.blockonomics.co/
API Documentation: https://www.blockonomics.co/views/api.html

Hello, my name is Aaron, today I will be showcasing how my Java Wrapper of the Blockonomics API works and how you can use it. I am assuming you are an experienced developer so please do not expect a walkthrough of everything.

When you add the wrapper library to your workspace you will be required to set your authorization key for the Blockonomics API, this can be found over at the link below.
https://www.blockonomics.co/merchants#/page3

import me.aaronakhtar.blockonomics_wrapper.Blockonomics;

Blockonomics.setApiKey("YOUR_API_KEY_HERE");
Enter fullscreen mode Exit fullscreen mode

Now that we've set our API Authorization Key, we can move on to the integration part of things.

The Blockonomics API allows you to execute a variety of functions, and a large portion of those functions are available in this wrapper, below is some example integration:

    public static void main(String[] args) {
        Blockonomics.setApiKey("YOUR_API_KEY_HERE");

        BitcoinAddressHistory bitcoinAddressHistory = Blockonomics.getBitcoinAddressHistory(new String[]{"1JJ5taVeiHcD6DXNkLLfocbHcE9Nzio1qV"});
        for (ConfirmedTransaction confirmedTransaction : bitcoinAddressHistory.getHistory()){
            System.out.println(Arrays.toString(confirmedTransaction.getAddr()));
            System.out.println(confirmedTransaction.getTime());
            System.out.println(confirmedTransaction.getTxid());
            System.out.println(confirmedTransaction.getValue());
        }

        for (PendingTransaction pendingTransaction : bitcoinAddressHistory.getPendingTransactions()){
            System.out.println(Arrays.toString(pendingTransaction.getAddr()));
            System.out.println(pendingTransaction.getTime());
            System.out.println(pendingTransaction.getTxid());
            System.out.println(pendingTransaction.getValue());
            System.out.println(pendingTransaction.getStatus());
        }
    }
Enter fullscreen mode Exit fullscreen mode
String btc_address = Blockonomics.newAddress(false);
System.out.println(Please send 0.001 BTC to \""+btc_address+"\");
Enter fullscreen mode Exit fullscreen mode

Thank you for taking the time to read, I hope this was of good use to you all.

  • Aaron Akhtar.

Twitter: https://twitter.com/D3vAaron

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay