DEV Community

loading...

How to use the Bitcoin API with Java

thatdevaaron profile image Aaron Akhtar ・2 min read

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

Discussion (0)

Forem Open with the Forem app