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

# Sign and Broadcast Transaction

> To complete any bonding or withdrawal operation on Polkadot, sign the unsigned transaction provided by the Staking API and broadcast it to the network.

## 1. Prepare the transaction

Retrieve an unsigned serialized transaction from the relevant API endpoint, e.g., `staking/bond`,`staking/nominate`, `staking/withdraw-unbonded`.

## 2. Sign the transaction

Use the [P2P Signer SDK](/docs/signer-sdk-overview) to sign the unsigned data following protocol specific configuration.

## 3. Send the transaction

Broadcast the transaction to the Polkadot network by sending a POST request to [/api/v1/polkadot/\{network}/tx/send](/reference/polkadot-transaction-send).

Example request (for `westend` network):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/polkadot/westend/tx/send \
       --header 'accept: application/json' \
       --header 'authorization: Bearer <token>' \
       --header 'content-type: application/json' \
       --data '
       {
         "signedTransaction": "0x450284002c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f01befdb7fa39c5a995a8d58676a0513d082be"
       }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/polkadot/westend/tx/send", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      signedTransaction: "0x450284002c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f01befdb7fa39c5a995a8d58676a0513d082be",
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.p2p.org/api/v1/polkadot/westend/tx/send",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "signedTransaction": "0x450284002c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f01befdb7fa39c5a995a8d58676a0513d082be",
      },
  )
  print(response.json())
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	payload := map[string]interface{}{
  		"signedTransaction": "0x450284002c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f01befdb7fa39c5a995a8d58676a0513d082be",
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polkadot/westend/tx/send", bytes.NewBuffer(body))
  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", "application/json")
  	resp, _ := http.DefaultClient.Do(req)
  	defer resp.Body.Close()
  	respBody, _ := io.ReadAll(resp.Body)
  	fmt.Println(string(respBody))
  }
  ```
</CodeGroup>

* `signedTransaction` — <Tooltip tip="A transaction that has been digitally signed by the sender using their private key.">signed transaction</Tooltip> in hex format.

Example response:

<CodeGroup>
  ```json theme={null}
  {
      "result": {
        "status": "success",
        "blockHash": "0x0628743b05ffb4c9d5ea2144b359af38910f0ae439a685f57d85b50b9481ba3f",
        "blockId": "17168395",
        "extrinsicId": "0xb838911d5a5f965f33b8ee134e1115b5b9902abfc567f0c3050073faf9d3c3e0",
        "transactionHash": "0x450284002c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f01befdb7fa39c5a995a8d58676a0513d082be",
        "signerAccount": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
        "createdAt": "2023-08-15T15:07:54.795Z"
      }
    }
  ```
</CodeGroup>

* `staus` — transaction status.
* `blockHash` — block hash in which the transaction was included.
* `blockId` — unique block identifier.
* `extrinsicId` — unique <Tooltip tip="On Polkadot and Avail, a SCALE encoded array consisting of a version number, signature, and varying data types indicating the resulting runtime function to be called, including the parameters required for that function to be executed. These state changes are invoked from the outside world, i.e., they are not part of the system itself. Extrinsics can take two forms, “inherents” and “transactions”.">extrinsic</Tooltip> identifier.
* `transactionHash` — signed transaction in hex format.
* `signerAccount` — account that signed the transaction.
* `createdAt` — timestamp of the transaction in the ISO 8601 format.


## Related topics

- [Getting Started](/docs/staking-polkadot.md)
- [Withdrawal](/docs/withdrawal-polkadot.md)
- [Staking API reference](/reference/polkadot-staking-bond.md)
