<p>This works for P2PK, and P2PKH, but multisig will not work.</p>

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

<p>If you want a TransactionSignature object instead of raw bytes:</p>

<pre><code>TransactionSignature ts = TransactionSignature.decodeFromBitcoin(sig_bytes, false)
</code></pre>

CC BY-SA 3.0
2015-02-23T18:16:58.227Z
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
CC BY-SA 3.0
2015-02-23T18:20:52.080Z
@Jus12 RuntimeError or VerificationError?
Nick ODell
CC BY-SA 3.0
2015-02-23T18:23:25.300Z
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
CC BY-SA 3.0
2015-02-23T18:04:02.033Z
2015-02-23T18:20:00.413Z
2015-02-23T18:20:00.413Z
Nick ODell
<p>I am trying to extract the signatures from a transaction. What is the best way to do this given a <code>com.google.bitcoin.core.Transaction</code> object I just received from the network?</p>

<transactions><signature><bitcoinj>
How to extract the signature of a transaction using bitcoinj
Jus12
# How to extract the signature of a transaction using bitcoinj

(Asked by: username_0 on 2015-02-23)

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?

**Tags:** transactions, signature, bitcoinj


---

## 1 answers

### Answer by username_1 on 2015-02-23. Score: 1 | Accepted answer

This works for P2PK, and P2PKH, but multisig will not work.
int index = (the index you want);
List inputs = Transaction.getInputs()
TransactionInput input = inputs.get(index);
Script scriptSig = input.getScriptSig();
List 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)

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0 RuntimeError or VerificationError?  
> **username_0**: 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)`  

---

