# getrawtransaction

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

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

Returns the raw transaction representation for a given transaction ID (`txid`).  If `verbose` is true, returns a JSON object with detailed information;  otherwise, returns a serialized hex-encoded string.


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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| txid | string | Yes | The transaction ID to fetch. |
| verbose | boolean | No | Return verbose JSON or just the raw hex string. |
| blockhash | string | No | The block in which to look for the transaction (if not in the mempool). |

## Result

**result** (string or object): Raw transaction data.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getrawtransaction",
  "params": [
    "546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b",
    false,
    "000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": "0100000001d074a22eedb6e7258c15368988826e6c73c6577fff490f42afeb8cd7be858032010000006b48304502210084689df7816df6f8a85c72a8cf4d52c2957657d619f5d126dbfc5f866d7561e80220415f8fbd095f53f0a8a4aa11496b126bc87dd020771d3d30c58f374a0f02bf420121024a42999af129d16c92bc0a0b18b39e2550769711845817d1f69932762d431ebcffffffff02ab6502000000000017a91453ca847feb3986cf2be405429e7e513484e0bc938780c6b001000000001976a914ebbfc363611943f588194465c1febdba9bf3883988ac00000000",
  "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": "getrawtransaction",
  "params": [
    "546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b",
    false,
    "000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getrawtransaction',
    params: [
      '546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b',
      false,
      '000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b'
    ]
  })
};

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": "getrawtransaction",
    "params": ["546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b", False, "000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b"]
}
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\": \"getrawtransaction\",\n  \"params\": [\n    \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n    false,\n    \"000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b\"\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\": \"getrawtransaction\",\n  \"params\": [\n    \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n    false,\n    \"000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b\"\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\": \"getrawtransaction\",\n  \"params\": [\n    \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n    false,\n    \"000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getrawtransaction
summary: Retrieve raw transaction data by txid
description: |
  Returns the raw transaction representation for a given transaction ID (`txid`).  If `verbose` is true, returns a JSON object with detailed information;  otherwise, returns a serialized hex-encoded string.
params:
  - name: txid
    required: true
    description: The transaction ID to fetch.
    schema:
      title: Bitcoin Transaction ID
      type: string
      pattern: ^[a-fA-F0-9]{64}$
      description: A 64-character hex string identifying a transaction.
  - name: verbose
    required: false
    description: Return verbose JSON or just the raw hex string.
    schema:
      type: boolean
      default: false
  - name: blockhash
    required: false
    description: The block in which to look for the transaction (if not in the mempool).
    schema:
      title: Bitcoin Block Hash
      type: string
      pattern: ^[a-fA-F0-9]{64}$
      description: A 64-character hex string representing the block hash.
result:
  name: result
  description: Raw transaction data.
  schema:
    oneOf:
      - type: string
        description: Raw transaction as hex string.
      - 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:
            title: Bitcoin Block Hash
            type: string
            pattern: ^[a-fA-F0-9]{64}$
            description: A 64-character hex string representing the block hash.
          size:
            type: integer
          vsize:
            type: integer
          weight:
            type: integer
          locktime:
            type: integer
          blockhash:
            title: Bitcoin Block Hash
            type: string
            pattern: ^[a-fA-F0-9]{64}$
            description: A 64-character hex string representing the block hash.
          confirmations:
            type: integer
          time:
            type: integer
          blocktime:
            type: integer
examples:
  - name: getrawtransaction example
    params:
      - name: txid
        value: 546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b
      - name: verbose
        value: false
      - name: blockhash
        value: 000000000000000000013c7104486ef1aa53e8ac99b8a8ac02a113b58457ed8b
    result:
      name: result
      value: 0100000001d074a22eedb6e7258c15368988826e6c73c6577fff490f42afeb8cd7be858032010000006b48304502210084689df7816df6f8a85c72a8cf4d52c2957657d619f5d126dbfc5f866d7561e80220415f8fbd095f53f0a8a4aa11496b126bc87dd020771d3d30c58f374a0f02bf420121024a42999af129d16c92bc0a0b18b39e2550769711845817d1f69932762d431ebcffffffff02ab6502000000000017a91453ca847feb3986cf2be405429e7e513484e0bc938780c6b001000000001976a914ebbfc363611943f588194465c1febdba9bf3883988ac00000000
```
