Issue getting fromAddress from transaction

18 views
Skip to first unread message

Mebitek The manufactured eXPerience

unread,
May 9, 2019, 1:45:30 PM5/9/19
to bitcoinj
Hi all,
I'm trying to get the fromAddress of a given trasaction. I can calculate one but I have different values in front of the ones reported on blockchain.com explorer. Can someone help me?

bitcoinj version: 0.15.1

        Script scriptSig = inputTx.getScriptSig();
        List<ScriptChunk> chunks = scriptSig.getChunks();

        byte[] pubKey = chunks.get(chunks.size() - 1).data;
        assert pubKey != null;
        byte[] pubKeyHash = Utils.sha256hash160(pubKey);

        LegacyAddress fromAddress = LegacyAddress.fromPubKeyHash(np, pubKeyHash);
from blockchain.com explorer:

tx = f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16
fromAddress = 12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S
I get: 1N6HfR4j5dnrBPpHET9ZmSwDhLkr5hprCG

for newer transactions, the result is good: tx: 1554a02d4eb1c7a73e3736922ed99530e360784e709896c42e5756e65b2da341 

can someone point me how to fix this?
thanks
Claudio

Andreas Schildbach

unread,
May 11, 2019, 5:55:36 AM5/11/19
to bitc...@googlegroups.com
Generally it's not a good idea trying to derive a "from address".

Your code can only work in very specific cases (inputs spending P2PKH
outputs).

You should assert that chunks.size() == 2.

Also the example transaction is a BCH transaction. I'm not sure how
similar BCH is to Bitcoin these days -- better check with the BCH folks.
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bitcoinj/a490fe24-5553-4e0e-8c7e-317f8ddeac4f%40googlegroups.com
> <https://groups.google.com/d/msgid/bitcoinj/a490fe24-5553-4e0e-8c7e-317f8ddeac4f%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


Mebitek The manufactured eXPerience

unread,
May 13, 2019, 9:12:39 AM5/13/19
to bitcoinj
thanks for your answer. what other cases should I find in a blockchain analisys?
how to manage that?
Reply all
Reply to author
Forward
0 new messages