> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# broadcastBitcoinP2wpkhTransaction

> Broadcasts a signed Bitcoin P2WPKH transaction to the network via the Portal backend.

## Function Signature

```dart theme={null}
Future<PortalBroadcastBitcoinP2wpkhTransactionResponse> broadcastBitcoinP2wpkhTransaction({
  required String chainId,
  required List<String> signatures,
  required String rawTxHex,
})
```

## Description

Submits a signed Bitcoin P2WPKH transaction to the network and returns its hash. This is the
final step of the Bitcoin send flow:

1. [`buildBitcoinP2wpkhTransaction`](./buildbitcoinp2wpkhtransaction) — build the PSBT.
2. [`rawSign`](./rawsign) — sign **every** entry of `transaction.signatureHashes`.
3. `broadcastBitcoinP2wpkhTransaction` — submit the signed transaction.

Pass the PSBT through from the build step unchanged, along with the signatures in the same order
as the hashes they were produced from.

If you do not need control over the individual steps, [`sendAsset`](./sendasset) performs all
three for you and returns the transaction hash directly.

## Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `chainId` | `String` | Yes | The chain ID in CAIP-2 format. Must be one of the two supported P2WPKH references (see below). |
| `signatures` | `List<String>` | Yes | One signature per input, produced by [`rawSign`](./rawsign) from `transaction.signatureHashes`, in the same order. |
| `rawTxHex` | `String` | Yes | The PSBT hex returned by [`buildBitcoinP2wpkhTransaction`](./buildbitcoinp2wpkhtransaction), passed through unchanged. |

### Supported `chainId` values

| Network | Chain ID |
| - | - |
| Bitcoin Mainnet | `bip122:000000000019d6689c085ae165831e93-p2wpkh` |
| Bitcoin Testnet | `bip122:000000000933ea01ad0ee984209779ba-p2wpkh` |

## Returns

**`PortalBroadcastBitcoinP2wpkhTransactionResponse`**

| Property | Type | Description |
| - | - | - |
| `txHash` | `String` | The broadcast transaction's hash (txid). |
| `chainId` | `String` | The chain the transaction was broadcast on. |
| `clientId` | `String` | The Portal client the transaction was broadcast for. |

## Example

The full build, sign, and broadcast flow:

```dart theme={null}
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

const chainId = 'bip122:000000000933ea01ad0ee984209779ba-p2wpkh'; // Bitcoin Testnet

// 1. Build the PSBT.
final built = await portal.buildBitcoinP2wpkhTransaction(
  chainId: chainId,
  to: 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
  token: 'NATIVE',
  amount: '0.0001',
);

if (built.error != null) {
  throw Exception('Failed to build transaction: ${built.error}');
}

// 2. Sign every signature hash, in order.
final signatures = <String>[];
for (final hash in built.transaction.signatureHashes) {
  signatures.add(await portal.rawSign(chainId: chainId, message: hash));
}

// 3. Broadcast.
final broadcast = await portal.broadcastBitcoinP2wpkhTransaction(
  chainId: chainId,
  signatures: signatures,
  rawTxHex: built.transaction.rawTxHex,
);

print('Transaction hash: ${broadcast.txHash}');
print('Chain: ${broadcast.chainId}');
```

## Errors

Throws a `PortalException` on failure:

| Code | Description |
| - | - |
| `NOT_INITIALIZED` | Portal was not initialized. |
| `BROADCAST_BITCOIN_P2WPKH_TRANSACTION_ERROR` | The broadcast failed — missing or mismatched signatures, an invalid `rawTxHex`, an unsupported chain ID, or the network rejected the transaction. |

```dart theme={null}
try {
  final broadcast = await portal.broadcastBitcoinP2wpkhTransaction(
    chainId: chainId,
    signatures: signatures,
    rawTxHex: built.transaction.rawTxHex,
  );

  print('Transaction hash: ${broadcast.txHash}');
} on PortalException catch (e) {
  print('Broadcast failed: ${e.code} - ${e.message}');
}
```

## Implementation Notes

* `signatures` must line up with `signatureHashes` one-for-one and in order. A missing or
  reordered signature fails the broadcast.
* Do not modify `rawTxHex` between the build and broadcast calls — pass the value through as-is.
* This endpoint accepts Bitcoin P2WPKH chains only. Use
  [`request`](./request) with `eth_sendTransaction` for EVM, or `sol_signAndSendTransaction`
  for Solana.
* `txHash` is a real on-chain Bitcoin txid. Account Abstraction is EVM-only, so unlike EVM sends
  this is never a UserOperation hash.

## Related

* [buildBitcoinP2wpkhTransaction](./buildbitcoinp2wpkhtransaction)
* [rawSign](./rawsign)
* [sendAsset](./sendasset)
* [getTransactionDetails](./gettransactiondetails) — look the broadcast transaction up afterwards
* [getClient](./getclient) — where the wallet's Bitcoin addresses live


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.