# Raw Transactions

Once a transaction is created using the /send endpoint and broadcasted to the network, there may be situations where access to the raw transaction data before broadcasting is necessary. To address this use case, the /rawtx endpoint becomes relevant. By utilizing the /rawtx endpoint, you can generate one or multiple transactions and retrieve the un-broadcasted raw transaction data. This data can be employed for alternative processes as needed.

The transactions generated through the /rawtx endpoint are constructed in their pure form, devoid of any change outputs that might be required for subsequent transactions. It's important to understand that any change outputs included in the transactions are not considered valid on the network until the previous transaction has been successfully broadcasted.

Similar to the [/send](/payments/transactions.md) endpoint, the /rawtx endpoint allows you to create transactions using the same input parameters in the request body. This facilitates consistency and familiarity in the process of generating transactions between the two endpoints.\ <br>

{% tabs %}
{% tab title="BSV" %}

```javascript
var parameters = {
    serviceId: 'optional',
    walletID: 'optional',
    data: {
      dataArray: [
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          amount: 0.0001
        }
      ]
    },
}
const response = await relysia.transaction.v1.rawtx(parameters);
```

{% endtab %}

{% tab title="Token" %}

```javascript
var parameters = {
    serviceId: 'optional',
    walletID: 'optional',
    data: {
      dataArray: [
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          tokenId: "1SJDKAS34DKSDKD1OD-SBD",
          amount: 2
        }
      ]
    },
}
const response = await relysia.transaction.v1.rawtx(parameters);
```

{% endtab %}

{% tab title="NFT" %}

```javascript
var parameters = {
    serviceId: 'optional',
    walletID: 'optional',
    data: {
      dataArray: [
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          tokenId: "1SJDKAS34DKSDKD1OD-SBD",
          amount: 1,
          sn: 1 //optional
        }
      ]
    },
}
const response = await relysia.transaction.v1.rawtx(parameters);
```

{% endtab %}

{% tab title="Multi Output" %}

```javascript
var parameters = {
    serviceId: 'optional',
    walletID: 'optional',
    data: {
      dataArray: [
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          amount: 0.00001
        },
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          amount: 0.00001
        },
        {
          to: "17n2JVhrCf1oYSMkZtZNjcf1deteUEKQsH",
          amount: 0.0005
        }
      ]
    },
}
const response = await relysia.transaction.v1.rawtx(parameters);
```

{% endtab %}
{% endtabs %}

## Build and return a raw transaction

<mark style="color:blue;">`GET`</mark> `https://api.relysia.com/v1/rawtx`

Use the /rawtx endpoint containing a single input and output. Transactions can be held and the utxo that is used will be blocked from the user access.

#### Headers

| Name     | Type   | Description          |
| -------- | ------ | -------------------- |
| walletID | String | Wallet Id (Optional) |

#### Request Body

| Name                                        | Type  | Description  |
| ------------------------------------------- | ----- | ------------ |
| dataArray<mark style="color:red;">\*</mark> | array | As per above |

{% tabs %}
{% tab title="200: OK Succuss" %}

```json
{
  "statusCode": 200,
  "data": {
    "status": "success",
    "msg": "Operation completed successfully",
    "rawTxs": [
      "0100000002e36d2003986bc84d1dec875ed686960e3794334c2e53bd8ee0d7897e4bf3f521000000006a4730440220063953703f06f9557691dba7b0424b9a1ca6dba2ec35bae7dd41e7b15fd38f1d0220439c01459709def5c824ded74102f4170ab3cee9ba7ab9f3b92dc80d7fcecf74412103c63be73d975c3f6274539704e27b2cb811bcc80dc11e95157cef3df8a5b3ac36ffffffffe36d2003986bc84d1dec875ed686960e3794334c2e53bd8ee0d7897e4bf3f521010000006b483045022100e5e0b6e4a61b7bad5c69a5b83032d6a48bb5976d582d52c881db2910ad79bb58022040a10e7dd9cde95c3756c63f33d6b5c119f35dcb4cedd29cc4424bf01e3548ed4121020824bb65d1cc92de2a37410e4279211a0d53788140a528b17f7ada7f4ad8a9a9ffffffff0101000000000000001976a91447431db9649fd75c28834cb152f17cc8ea7fa11f88ac00000000"
    ]
  }
}
```

{% endtab %}
{% endtabs %}

The rawtx response is a valid signed transaction that can be used in conjunction with paying invoices or awaiting other logic before broadcasting it to the network.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.relysia.com/payments/raw-transactions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
