> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/reference/stacks.js/stacks-transactions/network/broadcasttransaction.md).

# broadcastTransaction

Broadcasts a serialized transaction to a Stacks node, which will validate and forward it to the network.

***

### Usage

```ts
import {
  makeSTXTokenTransfer,
  broadcastTransaction,
} from '@stacks/transactions';

const transaction = await makeSTXTokenTransfer({
  recipient: 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5',
  amount: 1000000n,
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144004b81874603',
  network: 'testnet',
});

const result = await broadcastTransaction({
  transaction,
  network: 'testnet',
});

if ('txid' in result) {
  console.log('Success:', result.txid);
} else {
  console.log('Rejected:', result.reason);
}
```

#### Notes

* Returns a `TxBroadcastResult` which is either a success (contains `txid`) or a rejection (contains `reason`).
* You can provide an optional `attachment` for contract deploys or other uses.
* The network is inferred from the transaction if not specified.

[**Reference Link**](https://github.com/stx-labs/stacks.js/tree/main/packages/transactions/src/fetch.ts#L36)

***

### Signature

```ts
function broadcastTransaction(opts: {
  transaction: StacksTransactionWire;
  attachment?: Uint8Array | string;
} & NetworkClientParam): Promise<TxBroadcastResult>;
```

***

### Returns

`Promise<TxBroadcastResult>`

```ts
type TxBroadcastResult = TxBroadcastResultOk | TxBroadcastResultRejected;

type TxBroadcastResultOk = { txid: string };

type TxBroadcastResultRejected = {
  error: string;
  reason: string;
  txid: string;
  // Additional reason_data depending on rejection type
};
```

***

### Parameters

#### opts.transaction (required)

* **Type**: `StacksTransactionWire`

The signed transaction to broadcast.

#### opts.attachment (optional)

* **Type**: `Uint8Array | string`

An optional attachment in bytes or as a hex string.

#### opts.network (optional)

* **Type**: `StacksNetworkName | StacksNetwork`

The network to broadcast to. Inferred from the transaction if not provided.

#### opts.client (optional)

* **Type**: `NetworkClient`

Custom client configuration (base URL, fetch function) for the API call.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.stacks.co/reference/stacks.js/stacks-transactions/network/broadcasttransaction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
