I am new to bitcoinj. I want to print out the list of transactions like as follow for a wallet:

1- Sent 1 BTC to Adress1 on 'A' Time
2- Received 5 BTC from Adress2 on 'B' time
3- Sent 2 BTC to Address 3 on 'C' time

How can I do this?

  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. – Adam Feb 20 '18 at 11:30
  • 1
    It seems clear to me!. however I am using walletappkit and I have received and sent bitcoins on testnet. Now I want to get the list of transactions and should be able to know whether this amount came into my wallet or went out. – ArslanAnjum Feb 20 '18 at 12:03

Create an object of wallet app kit like:

WalletAppKit kit = new WalletAppKit(params, new File("."), "filename");
Iterable<WalletTransaction> walletTransactions = kit.wallet().getWalletTransactions();

this walletTransactions will give you all transactions related to the wallet.


You can get transaction history of any transaction like this

 private void txHistory()
                Set<Transaction> txx = kit.wallet().getTransactions(true);
                if (!txx.isEmpty())
                    int i = 1;
                    for (Transaction tx : txx)
                        System.out.println(i + "  ________________________");
                        System.out.println("Date and Time: " + tx.getUpdateTime().toString());
                        System.out.println("From Address: " + tx.getOutput(0).getAddressFromP2PKHScript(params));
                        System.out.println("To Address: " + tx.getOutput(0).getAddressFromP2PKHScript(params));
                        System.out.println("Amount Sent to me: " + tx.getValueSentToMe(kit.wallet()).toFriendlyString());
                        System.out.println("Amount Sent from me: " + tx.getValueSentFromMe(kit.wallet()).toFriendlyString());
                        long fee = (tx.getInputSum().getValue() > 0 ? tx.getInputSum().getValue() - tx.getOutputSum().getValue() : 0);
                        System.out.println("Fee: " + Coin.valueOf(fee).toFriendlyString());
                        System.out.println("Transaction Depth: " + tx.getConfidence().getDepthInBlocks());
                        System.out.println("Transaction Blocks: " + tx.getConfidence().toString());
                        System.out.println("Tx Hex: " + tx.getHashAsString());
                        System.out.println("Tx: " + tx.toString());
                    System.err.println("No Transaction Found");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.