# decoderawtransaction

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://bitcoin-mainnet.g.alchemy.com/v2/{apiKey}

Decodes a serialized, hex-encoded Bitcoin transaction. Returns detailed information about inputs, outputs, size, witness data, etc.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/decoderawtransaction

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| hexstring | string | Yes | The transaction hex string to decode. |
| iswitness | boolean | No | Indicates whether the transaction includes witness data. If omitted, heuristic decoding is applied.  |

## Result

**result** (object): A JSON object representing the decoded transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "decoderawtransaction",
  "params": [
    "0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00",
    true
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "txid": "a4cf344758af60ab8d4812477a7d3eee8854595db70ab39cf68f9dc509b13929",
    "hash": "48d1de9e93391ac3d83e5e97ce94ebd1db0f88553e45a6dffad3501c82408995",
    "size": 222,
    "vsize": 141,
    "weight": 564,
    "version": 2,
    "locktime": 862954048,
    "vin": [
      {
        "txid": "b9795d456bd0cca5ce90c2621d98f9559a0f728e971c82fe75e924c407bdd642",
        "vout": 0,
        "scriptSig": {
          "asm": "",
          "hex": ""
        },
        "sequence": 4294967293,
        "txinwitness": [
          "304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091",
          "03cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316af"
        ]
      }
    ],
    "vout": [
      {
        "value": 0.1,
        "n": 0,
        "scriptPubKey": {
          "asm": "OP_DUP OP_HASH160 d3620fe180a0beb8fcc9682fe92e5a25f0feccd3 OP_EQUALVERIFY OP_CHECKSIG",
          "desc": "addr(1BM1sAcrfV6d4zPKytzziu4McLQDsFC2Qc)",
          "hex": "76a914d3620fe180a0beb8fcc9682fe92e5a25f0feccd388ac",
          "type": "pubkeyhash"
        }
      },
      {
        "value": 0.65281824,
        "n": 1,
        "scriptPubKey": {
          "asm": "OP_DUP OP_HASH160 076d998f6b12c3d1da6217d967154f42a5e0afd3 OP_EQUALVERIFY OP_CHECKSIG",
          "desc": "addr(1iPoHeR3z1EidftGXMcEppzA1UupGPs2u)",
          "hex": "76a914076d998f6b12c3d1da6217d967154f42a5e0afd388ac",
          "type": "pubkeyhash"
        }
      }
    ]
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "decoderawtransaction",
  "params": [
    "0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00",
    true
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'decoderawtransaction',
    params: [
      '0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00',
      true
    ]
  })
};

fetch('https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "decoderawtransaction",
    "params": ["0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00", True]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decoderawtransaction\",\n  \"params\": [\n    \"0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00\",\n    true\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decoderawtransaction\",\n  \"params\": [\n    \"0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00\",\n    true\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decoderawtransaction\",\n  \"params\": [\n    \"0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00\",\n    true\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: decoderawtransaction
summary: Decode a raw transaction hex string
description: |
  Decodes a serialized, hex-encoded Bitcoin transaction. Returns detailed information about inputs, outputs, size, witness data, etc.
params:
  - name: hexstring
    required: true
    description: The transaction hex string to decode.
    schema:
      title: Raw Transaction Hex
      type: string
      pattern: ^[a-fA-F0-9]+$
      description: A serialized, hex-encoded Bitcoin transaction.
  - name: iswitness
    required: false
    description: |
      Indicates whether the transaction includes witness data. If omitted, heuristic decoding is applied.
    schema:
      type: boolean
result:
  name: result
  description: A JSON object representing the decoded transaction.
  schema:
    type: object
    properties:
      txid:
        title: Bitcoin Transaction ID
        type: string
        pattern: ^[a-fA-F0-9]{64}$
        description: A 64-character hex string identifying a transaction.
      hash:
        type: string
        description: The transaction hash (differs from txid for witness transactions).
      size:
        type: integer
      vsize:
        type: integer
      weight:
        type: integer
      version:
        type: integer
      locktime:
        type: integer
      vin:
        type: array
        items:
          type: object
          properties:
            txid:
              title: Bitcoin Transaction ID
              type: string
              pattern: ^[a-fA-F0-9]{64}$
              description: A 64-character hex string identifying a transaction.
            vout:
              type: integer
            scriptSig:
              type: object
              properties:
                asm:
                  type: string
                hex:
                  type: string
            txinwitness:
              type: array
              items:
                type: string
            sequence:
              type: integer
      vout:
        type: array
        items:
          type: object
          properties:
            value:
              type: number
              format: double
            'n':
              type: integer
            scriptPubKey:
              type: object
              properties:
                asm:
                  type: string
                desc:
                  type: string
                hex:
                  type: string
                type:
                  type: string
examples:
  - name: decoderawtransaction example
    params:
      - name: hexstring
        value: 0200000000010142d6bd07c424e975fe821c978e720f9a55f9981d62c290cea5ccd06b455d79b90000000000fdffffff028096980000000000160014d3620fe180a0beb8fcc9682fe92e5a25f0feccd370cd2f0100000000160014076d998f6b12c3d1da6217d967154f42a5e0afd30247304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091012103cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316afcfa50d00
      - name: iswitness
        value: true
    result:
      name: result
      value:
        txid: a4cf344758af60ab8d4812477a7d3eee8854595db70ab39cf68f9dc509b13929
        hash: 48d1de9e93391ac3d83e5e97ce94ebd1db0f88553e45a6dffad3501c82408995
        size: 222
        vsize: 141
        weight: 564
        version: 2
        locktime: 862954048
        vin:
          - txid: b9795d456bd0cca5ce90c2621d98f9559a0f728e971c82fe75e924c407bdd642
            vout: 0
            scriptSig:
              asm: ''
              hex: ''
            sequence: 4294967293
            txinwitness:
              - 304402204549b10ea1698d4b4605be1d3bfff810f6135395386207664a66f5bb8bd1470902205fb86c95bfbe7b502195ffa65276d292fb074fe18ba171ef0a35395211384091
              - 03cb5de30b343b35cc09b50f064eb289dd3e252f6985fc4309fba795cc950316af
        vout:
          - value: 0.1
            'n': 0
            scriptPubKey:
              asm: OP_DUP OP_HASH160 d3620fe180a0beb8fcc9682fe92e5a25f0feccd3 OP_EQUALVERIFY OP_CHECKSIG
              desc: addr(1BM1sAcrfV6d4zPKytzziu4McLQDsFC2Qc)
              hex: 76a914d3620fe180a0beb8fcc9682fe92e5a25f0feccd388ac
              type: pubkeyhash
          - value: 0.65281824
            'n': 1
            scriptPubKey:
              asm: OP_DUP OP_HASH160 076d998f6b12c3d1da6217d967154f42a5e0afd3 OP_EQUALVERIFY OP_CHECKSIG
              desc: addr(1iPoHeR3z1EidftGXMcEppzA1UupGPs2u)
              hex: 76a914076d998f6b12c3d1da6217d967154f42a5e0afd388ac
              type: pubkeyhash
```
