> ## 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 staking or withdrawal operation on Cosmos Hub, 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/stake`, `staking/redelegate/from`, `staking/unstake`.

## 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 signed transaction to the Cosmos network by making a POST request to [/api/v1/cosmos/\{network}/transaction/send](/reference/broadcast-cosmos-transaction).

Example request:

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
       --url https://api-test.p2p.org/api/v1/cosmos/cosmoshub-4/transaction/send \
       --header 'accept: application/json' \
       --header 'authorization: Bearer <token>' \
       --header 'content-type: application/json' \
       --data '
       {
       "signedTransaction": "0aab010a9b010a232f636f736d6f732e7374616b696e672e763162657461312e4d736744656c656761746512740a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f70657231376c676730337a65397836786b613032667330686877346164347777673035686571723279381a0d0a057561746f6d120434323030120b546865206d65737361676512670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801181312130a0d0a057561746f6d12043539353210dfc30e1a4026d73408f2f516a2a26604cb5a63f3d57262a4462d10931c21d36c1ce9d73d8f7d051f1c4aabc2e3142c7f01a4935b85c5c7d3854e8a3c41f0c218daf2a7b5ef"
       }'
  ```

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

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

  response = requests.post(
      "https://api-test.p2p.org/api/v1/cosmos/cosmoshub-4/transaction/send",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "signedTransaction": "0aab010a9b010a232f636f736d6f732e7374616b696e672e763162657461312e4d736744656c656761746512740a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f70657231376c676730337a65397836786b613032667330686877346164347777673035686571723279381a0d0a057561746f6d120434323030120b546865206d65737361676512670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801181312130a0d0a057561746f6d12043539353210dfc30e1a4026d73408f2f516a2a26604cb5a63f3d57262a4462d10931c21d36c1ce9d73d8f7d051f1c4aabc2e3142c7f01a4935b85c5c7d3854e8a3c41f0c218daf2a7b5ef",
      },
  )
  print(response.json())
  ```

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

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

  func main() {
  	payload := map[string]interface{}{
  		"signedTransaction": "0aab010a9b010a232f636f736d6f732e7374616b696e672e763162657461312e4d736744656c656761746512740a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f70657231376c676730337a65397836786b613032667330686877346164347777673035686571723279381a0d0a057561746f6d120434323030120b546865206d65737361676512670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801181312130a0d0a057561746f6d12043539353210dfc30e1a4026d73408f2f516a2a26604cb5a63f3d57262a4462d10931c21d36c1ce9d73d8f7d051f1c4aabc2e3142c7f01a4935b85c5c7d3854e8a3c41f0c218daf2a7b5ef",
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/cosmos/cosmoshub-4/transaction/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` — signed transaction which needs to be broadcast to the network.

Example response:

<CodeGroup>
  ```json theme={null}
  {
        "error": null,
        "result": {
            "status": "success",
            "blockId": 18575267,
            "fee": 0.005952,
            "gas": {
                "used": 202947,
                "wanted": 238047
            },
            "transactionHash": "ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47"
        }
    }
  ```
</CodeGroup>

* `status` — transaction status: `success`, `failed`.

* `blockId` — unique identifier of the block in which the transaction has been included.

* `fee` — total fee in ATOM charged for processing the transaction.

* `gas` — computational effort required to execute the transaction, measured in gas units.

  * `used` — amount of gas spent for the transaction.
  * `wanted` — maximum gas limit that the transaction initiator was willing to consume for the transaction.

* `transactionHash` — hash of the transaction.


## Related topics

- [Getting Started](/docs/staking-cosmos.md)
- [Withdrawal](/docs/withdrawal-cosmos.md)
- [Staking API reference](/reference/create-cosmos-stake-transaction.md)
