<p>Looking at the transaction in raw (serialized) format, neither inputs nor outputs have their own type. In other words, it is not indicated anywhere what type they are. However, there are certain standard output formats such as P2PKH, P2SH, P2WPKH etc. You can see the complete list of all standard formats at the following <a href="https://bitcoin.stackexchange.com/a/107873/140802">link</a>. What <code>getrawtransaction</code> (like many other functions within Bitcoin RPC) does is generate additional fields in the JSON result based on the actual content of the transaction to make it easier for end users. Unfortunately, one of those additional fields is not an input type.</p>
<p>The way to see what type of output a certain input unlocks (and therefore implicitly <strong>what type that input is</strong>) is to look at a pair of transaction-output referenced by a certain input and based on the content/format of that referenced output (link above) determine the type of input.</p>

CC BY-SA 4.0
2023-09-28T09:02:41.680Z
Thank you very much for your answer, Filip, it will be very useful to me.
However, one of the additional JSON fields in the outputs of a transaction is `type`, and after testing with a few transactions, using the table you provided me, this field seems accurate (e.g., a P2WSH output will have the type `witness_v0_scripthash` and the format is the one from the table).
Do you know how this `type` field is generated? Would the other fields be parsed to deduce the type?
Lev
CC BY-SA 4.0
2023-09-28T09:19:13.990Z
@Lev The `type` field is not an actual part of the transaction, Bitcoin RPC determined this field based on the content of the output script (`scriptPubKey`). For example, if it sees the content `OP_HASH160` `OP_PUSHBYTES_20` `32-bytes` `OP_EQUAL` in the output script (`scriptPubKey`), it knows that the type is `P2SH`, etc. No, it is only necessary to read the content of the output script, ie. the content of `scriptPubKey` inside the output, to determine its type.
dassd
CC BY-SA 4.0
2023-09-27T09:29:51.020Z
2023-09-27T09:37:27.247Z
2023-09-27T09:37:27.247Z
dassd
<p>I am currently working on a tool parsing every transaction of the bitcoin blockchain, using <a href="https://developer.bitcoin.org/reference/rpc/getrawtransaction.html" rel="nofollow noreferrer">the <code>getrawtransaction</code> RPC call in verbose mode</a>.
My goal is to store them all in a database, while keeping some useful information about them (i.e., not everything that is given by the RPC call).</p>
<p>Something I am having trouble to understand though is <strong>how to precisely &quot;tag&quot; an input with a type?</strong> The outputs all have a &quot;type&quot; string that allows me to tag them as P2SH, P2PK, P2WSH, etc, but the inputs don't.</p>
<p>What I tried up to now is to parse the content of the scriptSig attribute of the inputs. For example, to know if an input is P2PK, I read somewhere that the ASM code of the scriptSig of the input should start with 30. When I compare with some online tools that have already tagged every transaction inputs/outputs, it looks like it's accurate, but I don't have any proof that what I am doing is right.</p>
<p>Is there some kind of <strong>online resources</strong> with precise specifications allowing me to identify an input? I cannot manage to find any.</p>
<p>Another idea I had is that each output is, obviously, linked to an output.
Could I suppose that the type of input is the same as the one of the output it is linked to?</p>
<p>It would make sense to me, but I would rather not jump to conclusions; I still have a lot to learn about Bitcoin.</p>
<p>Thank you very much!</p>

<transactions><output><input>
How to identify a transaction input type?
Lev
# How to identify a transaction input type?

(Asked by: username_0 on 2023-09-27)

I am currently working on a tool parsing every transaction of the bitcoin blockchain, using [the `getrawtransaction` RPC call in verbose mode](https://developer.bitcoin.org/reference/rpc/getrawtransaction.html).
My goal is to store them all in a database, while keeping some useful information about them (i.e., not everything that is given by the RPC call).

Something I am having trouble to understand though is **how to precisely "tag" an input with a type?** The outputs all have a "type" string that allows me to tag them as P2SH, P2PK, P2WSH, etc, but the inputs don't.

What I tried up to now is to parse the content of the scriptSig attribute of the inputs. For example, to know if an input is P2PK, I read somewhere that the ASM code of the scriptSig of the input should start with 30. When I compare with some online tools that have already tagged every transaction inputs/outputs, it looks like it's accurate, but I don't have any proof that what I am doing is right.

Is there some kind of **online resources** with precise specifications allowing me to identify an input? I cannot manage to find any.

Another idea I had is that each output is, obviously, linked to an output.
Could I suppose that the type of input is the same as the one of the output it is linked to?

It would make sense to me, but I would rather not jump to conclusions; I still have a lot to learn about Bitcoin.

Thank you very much!

**Tags:** transactions, output, input


---

## 1 answers

### Answer by username_1 on 2023-09-27. Score: 3 | Accepted answer

Looking at the transaction in raw (serialized) format, neither inputs nor outputs have their own type. In other words, it is not indicated anywhere what type they are. However, there are certain standard output formats such as P2PKH, P2SH, P2WPKH etc. You can see the complete list of all standard formats at the following [link](https://bitcoin.stackexchange.com/a/107873/140802). What `getrawtransaction` (like many other functions within Bitcoin RPC) does is generate additional fields in the JSON result based on the actual content of the transaction to make it easier for end users. Unfortunately, one of those additional fields is not an input type.

The way to see what type of output a certain input unlocks (and therefore implicitly **what type that input is**) is to look at a pair of transaction-output referenced by a certain input and based on the content/format of that referenced output (link above) determine the type of input.

> **Comments:**
> **username_0**: Thank you very much for your answer, Filip, it will be very useful to me. However, one of the additional JSON fields in the outputs of a transaction is `type`, and after testing with a few transactions, using the table you provided me, this field seems accurate (e.g., a P2WSH output will have the type `witness_v0_scripthash` and the format is the one from the table). Do you know how this `type` field is generated? Would the other fields be parsed to deduce the type?  
> **username_1**: @username_0 The `type` field is not an actual part of the transaction, Bitcoin RPC determined this field based on the content of the output script (`scriptPubKey`). For example, if it sees the content `OP_HASH160` `OP_PUSHBYTES_20` `32-bytes` `OP_EQUAL` in the output script (`scriptPubKey`), it knows that the type is `P2SH`, etc. No, it is only necessary to read the content of the output script, ie. the content of `scriptPubKey` inside the output, to determine its type.  

---

