I am trying to extract the signatures from a transaction. What is the best way to do this given a com.google.bitcoin.core.Transaction object I just received from the network?

1 Answer 1


This works for P2PK, and P2PKH, but multisig will not work.

int index = (the index you want);
List<TransactionInput> inputs = Transaction.getInputs()
TransactionInput input = inputs.get(index);
Script scriptSig = input.getScriptSig();
List<ScriptChunk> signature_and_pubkey = scriptSig.getChunks();
ScriptChunk sig_chunk = signature_and_pubkey.get(0);
bytes[] sig_bytes = sig_chunk.data;

If you want a TransactionSignature object instead of raw bytes:

TransactionSignature ts = TransactionSignature.decodeFromBitcoin(sig_bytes, false)
  • how can I get a TransactionSignature object from this? I tried com.google.bitcoin.crypto.TransactionSignature.decodeFromBitcoin(sig_chunk.data, false) but sometimes it gives an error.
    – Jus12
    Feb 23, 2015 at 18:16
  • @Jus12 RuntimeError or VerificationError?
    – Nick ODell
    Feb 23, 2015 at 18:20
  • Here is the error I got (happens in few cases only): java.lang.RuntimeException: java.io.IOException: DER length more than 4 bytes: 112 at com.google.bitcoin.core.ECKey$ECDSASignature.decodeFromDER(ECKey.java:358)
    – Jus12
    Feb 23, 2015 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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