Transaction history with bitcoinj

0

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?

ArslanAnjum

Posted 2018-02-20T08:58:00.793

Reputation: 101

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 2018-02-20T11:30:08.210

1It 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 2018-02-20T12:03:18.187

Answers

0

Create an object of wallet app kit like:

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

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

Sanjay Rao

Posted 2018-02-20T08:58:00.793

Reputation: 1

0

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());
                        i++;
                    }
                }
                else
                {
                    System.err.println("No Transaction Found");
                }
            }

Zombie

Posted 2018-02-20T08:58:00.793

Reputation: 528