# createrawtransaction

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

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

Creates a transaction spending the given inputs and creating new outputs. Outputs can be addresses or data. Returns hex-encoded raw transaction. Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.


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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| inputs | object[] | Yes | An array of transaction inputs. |
| outputs | object[] or object | Yes | An array or object with outputs (key-value pairs, where keys are addresses or 'data', and values are BTC amounts or hex). |
| locktime | integer | No | Raw locktime. Non-0 value also activates inputs. |
| replaceable | boolean | No | Whether to mark transaction as BIP125 replaceable. Allows this transaction to be replaced by a transaction with higher fees. |

## Result

**result** (string): Hex-encoded raw transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "createrawtransaction",
  "params": [
    [
      {
        "txid": "546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b",
        "vout": 0
      }
    ],
    [
      {
        "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 0.01
      }
    ],
    0,
    false
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": "0200000001546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b0000000000fdffffff01c0c62d000000000017a914751e76e8199196d454941c45d1b3a323f1433bd68700000000",
  "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": "createrawtransaction",
  "params": [
    [
      {
        "txid": "546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b",
        "vout": 0
      }
    ],
    [
      {
        "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 0.01
      }
    ],
    0,
    false
  ]
}'
```

### JavaScript

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

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": "createrawtransaction",
    "params": [[
            {
                "txid": "546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b",
                "vout": 0
            }
        ], [{ "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 0.01 }], 0, False]
}
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\": \"createrawtransaction\",\n  \"params\": [\n    [\n      {\n        \"txid\": \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n        \"vout\": 0\n      }\n    ],\n    [\n      {\n        \"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa\": 0.01\n      }\n    ],\n    0,\n    false\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\": \"createrawtransaction\",\n  \"params\": [\n    [\n      {\n        \"txid\": \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n        \"vout\": 0\n      }\n    ],\n    [\n      {\n        \"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa\": 0.01\n      }\n    ],\n    0,\n    false\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\": \"createrawtransaction\",\n  \"params\": [\n    [\n      {\n        \"txid\": \"546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b\",\n        \"vout\": 0\n      }\n    ],\n    [\n      {\n        \"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa\": 0.01\n      }\n    ],\n    0,\n    false\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: createrawtransaction
summary: Create a raw transaction from inputs and outputs
description: |
  Creates a transaction spending the given inputs and creating new outputs. Outputs can be addresses or data. Returns hex-encoded raw transaction. Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.
params:
  - name: inputs
    required: true
    description: An array of transaction inputs.
    schema:
      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
            description: The output number.
          sequence:
            type: integer
            description: The sequence number.
  - name: outputs
    required: true
    description: An array or object with outputs (key-value pairs, where keys are addresses or 'data', and values are BTC amounts or hex).
    schema:
      oneOf:
        - type: array
          items:
            type: object
            additionalProperties:
              oneOf:
                - type: number
                - type: string
        - type: object
          additionalProperties:
            oneOf:
              - type: number
              - type: string
  - name: locktime
    required: false
    description: Raw locktime. Non-0 value also activates inputs.
    schema:
      type: integer
      default: 0
  - name: replaceable
    required: false
    description: Whether to mark transaction as BIP125 replaceable. Allows this transaction to be replaced by a transaction with higher fees.
    schema:
      type: boolean
      default: false
result:
  name: result
  description: Hex-encoded raw transaction.
  schema:
    title: Raw Transaction Hex
    type: string
    pattern: ^[a-fA-F0-9]+$
    description: A serialized, hex-encoded Bitcoin transaction.
examples:
  - name: createrawtransaction example
    params:
      - name: inputs
        value:
          - txid: 546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b
            vout: 0
      - name: outputs
        value:
          - 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa: 0.01
      - name: locktime
        value: 0
      - name: replaceable
        value: false
    result:
      name: result
      value: 0200000001546263a196ce5cf674d5002afc0231ab417c2e971fd4ed1735c7a4c63f44720b0000000000fdffffff01c0c62d000000000017a914751e76e8199196d454941c45d1b3a323f1433bd68700000000
```
