Get transaction details using bitcoinj library

2

1

I am trying to develop an application using bitcoinj library. I want to get the bitcoin transaction details.

The details, that I want to extract from a transaction includes the following.

1) Who send me the transaction (Address and Public Key of the sender).

2) The amount that I received.

3) When was the transaction issued.

4) Get the data stored in the transaction in OP_RETURN.

jgm

Posted 2016-05-22T22:07:22.353

Reputation: 748

There is no single "sender" address in Bitcoin, a transaction may be funded from balances of multiple addresses.Murch 2016-06-13T15:44:59.223

Answers

2

maybe this helps

private void txHistory()
        {
            List<Transaction> txx = kit.wallet().getTransactionsByTime();
            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(1).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 2016-05-22T22:07:22.353

Reputation: 528