> ## 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 TON, sign the unsigned transaction provided by the Staking API and broadcast it to the network.

## 1. Prepare the transaction

Retrieve an unserialized transaction data from the relevant API endpoint, e.g., `single-nominator/stake`, `ton-whales/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 transaction to the network by sending a POST request to [/api/v1/ton/\{network}/transactions/broadcast](/reference/ton-staking-broadcast).

Example request (for the `testnet` network):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/ton/testnet/transactions/broadcast \
       --header 'accept: application/json' \
       --header 'content-type: application/json' \
       --data '
  {
    "walletVersion": "V4",
    "unsignedTransaction": "te6ccgEBAQEABgAACCiAmCM=",
    "signature": "te6ccgEBAQEABgAACCiAmCM=",
    "publicKey": "7031f1dcbe0f670daf4094d04ff9a7947bc4ac9174a7d470255d1a664e20b7c6"
  }
  '
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/ton/testnet/transactions/broadcast", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      walletVersion: "V4",
      unsignedTransaction: "te6ccgEBAQEABgAACCiAmCM=",
      signature: "te6ccgEBAQEABgAACCiAmCM=",
      publicKey: "7031f1dcbe0f670daf4094d04ff9a7947bc4ac9174a7d470255d1a664e20b7c6",
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

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

  response = requests.post(
      "https://api.p2p.org/api/v1/ton/testnet/transactions/broadcast",
      headers={
          "Content-Type": "application/json",
      },
      json={
          "walletVersion": "V4",
          "unsignedTransaction": "te6ccgEBAQEABgAACCiAmCM=",
          "signature": "te6ccgEBAQEABgAACCiAmCM=",
          "publicKey": "7031f1dcbe0f670daf4094d04ff9a7947bc4ac9174a7d470255d1a664e20b7c6",
      },
  )
  print(response.json())
  ```

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

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

  func main() {
  	payload := map[string]interface{}{
  		"walletVersion":       "V4",
  		"unsignedTransaction": "te6ccgEBAQEABgAACCiAmCM=",
  		"signature":           "te6ccgEBAQEABgAACCiAmCM=",
  		"publicKey":           "7031f1dcbe0f670daf4094d04ff9a7947bc4ac9174a7d470255d1a664e20b7c6",
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/ton/testnet/transactions/broadcast", bytes.NewBuffer(body))
  	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 the hexadecimal format which needs to be broadcasted to the network.
* `signature` — external message signature, which has to be signed with the private key.
* `publicKey` — public key of the nominator for the TON network.
* `walletVersion` — [version of the smart contract](https://docs.ton.org/participate/wallets/contracts) used by the wallet in the TON blockchain.

Example response:

<CodeGroup>
  ```json theme={null}
  {
        "error": null,
        "result": {
            "extraData": {
                "messageHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
            }
        }
    }
  ```
</CodeGroup>

* `messageHash` — hash of the transaction.


## Related topics

- [Getting Started](/docs/staking-ton.md)
- [Withdrawal](/docs/withdrawal-ton.md)
- [Staking API reference](/reference/ton-staking-single-nominator-stake.md)
