<p>This is a known issue due to how segwit data is stored. To parse a transaction correctly, you must use either of the following:</p>

<pre><code>getrawtransaction &lt;tx_id&gt; true
decoderawtransaction &lt;txhex&gt; true
</code></pre>

<p>For the first one, the API will return a decoded, complete transaction object including witness data as a JSON object. If you are decoding raw transaction data sourced from elsewhere, you can pass the encoded hex data to <code>decoderawtransaction</code> and set the second (optional) <code>iswitness</code> parameter to true to ask the API to treat it as a segwit transaction. </p>

CC BY-SA 4.0
2019-08-19T15:34:47.120Z
And how do I decide when to put the parameter iswitness to true ?
jfjobidon
CC BY-SA 4.0
2019-08-19T15:37:58.733Z
@jfjobidon Set it to true whenever you're decoding a real transaction (one that is complete, on the chain, or could be broadcast to the nerwork). Set it to false when you have an unsigned transaction. It's a historical mistake that these two distinct use cases use the same hex raw format.
Pieter Wuille
CC BY-SA 4.0
2019-08-19T14:38:24.850Z
2019-08-19T14:38:24.850Z
Raghav Sood
<p>The problem is with <code>getrawtransaction</code> command in bitcoin core. It doesn't recognize the SegWit input which is why it decode/deserialize the transaction incorrectly (wrong input txid and negative amount in output).<br>
<a href="https://bitcointalk.org/index.php?topic=5014781.0" rel="nofollow noreferrer">https://bitcointalk.org/index.php?topic=5014781.0</a></p>

CC BY-SA 4.0
2019-08-19T14:32:35.620Z
2019-08-19T14:32:35.620Z
Coding Enthusiast
<p>In tx 
<a href="https://chain.so/tx/BTCTEST/3a4a7087d4ece4503948b33aa77c807cda770575d229cbcb7dd8336ffa77445a" rel="nofollow noreferrer">3a4a7087d4ece4503948b33aa77c807cda770575d229cbcb7dd8336ffa77445a</a>
the unique input is <a href="https://chain.so/tx/BTCTEST/1387e35f2c65f6664e15a98a43b7a70831e636635876a7154c99f38d89a9f795" rel="nofollow noreferrer">1387e35f2c65f6664e15a98a43b7a70831e636635876a7154c99f38d89a9f795</a>
with index vout = 1.
When I request this tx to Bitcoin core (version 0.17.1 for MAC)
Why do I get this result :</p>

<pre><code>{
"txid":
"eb20d4cbb350c092205e874358b1cf22195430f5516042ecc4a61ad9cbce7dce",
"hash": 
"eb20d4cbb350c092205e874358b1cf22195430f5516042ecc4a61ad9cbce7dce",
"version": 1,
"size": 258,
"vsize": 258,
"weight": 1032,
"locktime": 0,
"vin": [],
"vout": [
{
  "value": -81633158802.50592511,
  "n": 0,
  "scriptPubKey": {
    "asm": "OP_NOP4 OP_RESERVED1 fcac561ac13cb1fd797dd49f9b3bd9dee003b5cecb0100000000f0ffffff0340420f000000000017a9 46281ac9378a76b004945954e275a243171d759f OP_EQUAL OP_GREATERTHAN 1 0000000000160014a8160b1e0db3418d3592b60c1df5784f7b96f0350000000000000000196a1768747470733a2f2f746274632e6269746170732e636f6d02 3045022100e771433023daa30b7a16127ffb80b98962672fac45dfc8b34e7d0b956c31c8cd02207ce59a29138b02f58b8fb44c20e5863d915f0767441d4f8df136aaa817f12b2101 0263d53e7cabca20523a412092ccc505a259a12e2d81d06b89dc5ae20fe14a1e67",
    "hex": "b38929fcac561ac13cb1fd797dd49f9b3bd9dee003b5cecb0100000000f0ffffff0340420f000000000017a91446281ac9378a76b004945954e275a243171d759f87a0513f0000000000160014a8160b1e0db3418d3592b60c1df5784f7b96f0350000000000000000196a1768747470733a2f2f746274632e6269746170732e636f6d02483045022100e771433023daa30b7a16127ffb80b98962672fac45dfc8b34e7d0b956c31c8cd02207ce59a29138b02f58b8fb44c20e5863d915f0767441d4f8df136aaa817f12b2101210263d53e7cabca20523a412092ccc505a259a12e2d81d06b89dc5ae20fe14a1e67",
    "type": "nonstandard"
  }
}
]
}
</code></pre>

<p>which is totally different form the result given by the explorer.</p>

<bitcoin-core>
Transaction from bitcoin core is different from the explorer
jfjobidon
# Transaction from bitcoin core is different from the explorer

(Asked by: username_0 on 2019-08-19)

In tx
[3a4a7087d4ece4503948b33aa77c807cda770575d229cbcb7dd8336ffa77445a](https://chain.so/tx/BTCTEST/3a4a7087d4ece4503948b33aa77c807cda770575d229cbcb7dd8336ffa77445a)
the unique input is [1387e35f2c65f6664e15a98a43b7a70831e636635876a7154c99f38d89a9f795](https://chain.so/tx/BTCTEST/1387e35f2c65f6664e15a98a43b7a70831e636635876a7154c99f38d89a9f795)
with index vout = 1.
When I request this tx to Bitcoin core (version 0.17.1 for MAC)
Why do I get this result :

```
{
"txid":
"eb20d4cbb350c092205e874358b1cf22195430f5516042ecc4a61ad9cbce7dce",
"hash": 
"eb20d4cbb350c092205e874358b1cf22195430f5516042ecc4a61ad9cbce7dce",
"version": 1,
"size": 258,
"vsize": 258,
"weight": 1032,
"locktime": 0,
"vin": [],
"vout": [
{
  "value": -81633158802.50592511,
  "n": 0,
  "scriptPubKey": {
    "asm": "OP_NOP4 OP_RESERVED1 fcac561ac13cb1fd797dd49f9b3bd9dee003b5cecb0100000000f0ffffff0340420f000000000017a9 46281ac9378a76b004945954e275a243171d759f OP_EQUAL OP_GREATERTHAN 1 0000000000160014a8160b1e0db3418d3592b60c1df5784f7b96f0350000000000000000196a1768747470733a2f2f746274632e6269746170732e636f6d02 3045022100e771433023daa30b7a16127ffb80b98962672fac45dfc8b34e7d0b956c31c8cd02207ce59a29138b02f58b8fb44c20e5863d915f0767441d4f8df136aaa817f12b2101 0263d53e7cabca20523a412092ccc505a259a12e2d81d06b89dc5ae20fe14a1e67",
    "hex": "b38929fcac561ac13cb1fd797dd49f9b3bd9dee003b5cecb0100000000f0ffffff0340420f000000000017a91446281ac9378a76b004945954e275a243171d759f87a0513f0000000000160014a8160b1e0db3418d3592b60c1df5784f7b96f0350000000000000000196a1768747470733a2f2f746274632e6269746170732e636f6d02483045022100e771433023daa30b7a16127ffb80b98962672fac45dfc8b34e7d0b956c31c8cd02207ce59a29138b02f58b8fb44c20e5863d915f0767441d4f8df136aaa817f12b2101210263d53e7cabca20523a412092ccc505a259a12e2d81d06b89dc5ae20fe14a1e67",
    "type": "nonstandard"
  }
}
]
}

```

which is totally different form the result given by the explorer.

**Tags:** bitcoin-core


---

## 2 answers

### Answer by username_1 on 2019-08-19. Score: 1 | Accepted answer

This is a known issue due to how segwit data is stored. To parse a transaction correctly, you must use either of the following:

```
getrawtransaction <tx_id> true
decoderawtransaction <txhex> true

```

For the first one, the API will return a decoded, complete transaction object including witness data as a JSON object. If you are decoding raw transaction data sourced from elsewhere, you can pass the encoded hex data to `decoderawtransaction` and set the second (optional) `iswitness` parameter to true to ask the API to treat it as a segwit transaction.

> **Comments:**
> **username_0**: And how do I decide when to put the parameter iswitness to true ?  
> **username_2**: @username_0 Set it to true whenever you're decoding a real transaction (one that is complete, on the chain, or could be broadcast to the nerwork). Set it to false when you have an unsigned transaction. It's a historical mistake that these two distinct use cases use the same hex raw format.  

---

### Answer by username_3 on 2019-08-19. Score: 1

The problem is with `getrawtransaction` command in bitcoin core. It doesn't recognize the SegWit input which is why it decode/deserialize the transaction incorrectly (wrong input txid and negative amount in output).  
<https://bitcointalk.org/index.php?topic=5014781.0>


---

