2

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.

  • There is no single "sender" address in Bitcoin, a transaction may be funded from balances of multiple addresses. – Murch Jun 13 '16 at 15:44
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");
            }
        }

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.