> ## 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.

# Getting Started

> Stake on Celestia programmatically with the P2P.org Staking API.

Staking in Celestia using the Staking API consists of several main steps:

1. Create a staking request.
2. Sign and send the transaction to the network.

[Get an authentication token](/docs/authentication) to start using Staking API.

Request examples are provided using [cURL](https://curl.se/).

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant P2P API
    participant Blockchain
    Client->>P2P API: Create stake transaction
    P2P API-->>Client: Unsigned transaction
    Client->>Client: Sign transaction locally
    Client->>P2P API: Broadcast signed transaction
    P2P API->>Blockchain: Submit transaction
    Blockchain-->>P2P API: Transaction hash
    P2P API-->>Client: Transaction status
```

<Steps>
  <Step title="Create staking transaction">
    Send a POST request to [/api/v1/celestia/\{network}/staking/stake](/reference/create-celestia-stake-transaction).

    Example request (for `celestia-mainnet-beta` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
           --url https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/staking/stake \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json' \
           --data '
           {
           "stashAccountAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
           "memo": "This is your memo message",
           "amount": 0.00420
           }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/staking/stake",
        {
          method: "POST",
          headers: {
            "accept": "application/json",
            "authorization": "Bearer <token>",
            "content-type": "application/json",
          },
          body: JSON.stringify({
            stashAccountAddress: "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
            memo: "This is your memo message",
            amount: 0.00420,
          }),
        }
      );
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/staking/stake",
          headers={
              "accept": "application/json",
              "authorization": "Bearer <token>",
              "content-type": "application/json",
          },
          json={
              "stashAccountAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
              "memo": "This is your memo message",
              "amount": 0.00420,
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"stashAccountAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
      		"memo":                "This is your memo message",
      		"amount":              0.00420,
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/staking/stake", bytes.NewBuffer(body))
      	req.Header.Set("accept", "application/json")
      	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>

    * `stashAccountAddress` — <Tooltip tip="A participant in a Proof-of-Stake network who delegates their tokens to a validator. Delegators share in the rewards and risks associated with the validator's performance in the consensus process.">delegator</Tooltip> stash account address which keeps tokens.
    * `memo` — arbitrary text data to add to the transactions.
    * `amount` — amount of tokens to stake in TIA.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "error": null,
          "result": {
            "amount": 0.0042,
            "currency": "tia",
            "validatorAddress": "celestiavaloper1r4kqtye4dzacmrwnh6f057p50pdjm8g59tlhhg",
            "stashAccountAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
            "rewardDestinationAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
            "transactionData": {
              "messages": [
                {
                  "typeUrl": "/cosmos.staking.v1beta1.MsgDelegate",
                  "value": {
                    "delegatorAddress": "celestia1yknsyf9ws4ugtv3r9g43kwqkne4zmrupae4xb2",
                    "validatorAddress": "celestiavaloper1r4kqtye4dzacmrwnh6f057p50pdjm8g59tlhhg",
                    "amount": {
                      "denom": "utia",
                      "amount": "4200"
                    }
                  }
                }
              ],
              "fee": {
                "amount": [
                  {
                    "amount": "5953",
                    "denom": "utia"
                  }
                ],
                "gas": "238098"
              },
              "memo": "The message",
              "encodedBody": "0a9b010a232f636f736d6f732e7374616b696e672e763162657461312e4d736744656c656761746512740a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f70657231376c676730337a65397836786b613032667330686877346164347777673035686571723279381a0d0a057561746f6d120434323030120b546865206d657373616765",
              "encodedAuthInfo": "0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801182312130a0d0a057561746f6d1204353935331092c40e"
            },
            "createdAt": "2024-02-12T11:21:40.810Z"
          }
        }
      ```
    </CodeGroup>

    * `amount` — amount of tokens to stake.

    * `currency` — currency of tokens:

      * <Tooltip tip="A participant in a Proof-of-Stake network who delegates their tokens to a validator. Delegators share in the rewards and risks associated with the validator's performance in the consensus process.">`tia` — T</Tooltip>IA, Celestia native staking token.
      * `utia` — 1 TIA = 10⁶ uTIA,
      * `mtia` — 1 TIA = 10³ mTIA.

    * `validatorAddress` — <Tooltip tip="A network participant responsible for proposing new blocks under a Proof-of-Stake consensus model, validating transactions, and securing a blockchain through staking tokens. Validators play a crucial role in maintaining the security and integrity of the network.">validator</Tooltip> address to which tokens are delegated.

    * `stashAccountAddress` — delegator stash account address which keeps tokens.

    * `rewardDestinationAddress` — reward destination account address.

    * `createdAt` — timestamp of th<Tooltip tip="A network participant responsible for proposing new blocks under a Proof-of-Stake consensus model, validating transactions, and securing a blockchain through staking tokens. Validators play a crucial role in maintaining the security and integrity of the network.">e transac</Tooltip>tion in the ISO 8601 format.

    `transactionData` is the list of data fields to be used to construct the staking transactions:

    * `messages`:

      * `typeUrl` — Celestia network operation type.
      * `delegatorAddress` — delegator address.
      * `validatorAddress` — validator address.
      * `amount` — amount of tokens to stake.
      * `currency` — currency of tokens.

    * `fee` — fee charged for the transaction.

      * `amount` — amount of tokens.
      * `denom` — currency of tokens: `tia`, `utia`, or `mtia`.
      * `gas` — amount of <Tooltip tip="A measure of computational effort required to execute a transaction or smart contract on a blockchain. Users must pay a gas fee, usually in the native token, to have their transactions processed by the network.">gas</Tooltip> spent for the transaction.

    * `memo` — arbitrary text data to add to the transactions.

    * `encodedBody` — processable transaction data encoded in the hexadecimal format.

    * `encodedAuthInfo` — authorization data, including fee, encoded in the hexadecimal format.
  </Step>

  <Step title="Sign and send transaction">
    Use `transactionData` to [sign and send](/docs/signing-transaction-celestia) the signed transaction to the Celestia network.

    To check the transaction status, send a GET request to [/api/v1/celestia/\{network}/transaction/status/\{transactionHash}](/reference/get-celestia-transaction-status).

    Example request (for `celestia-mainnet-beta` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request GET \
           --url https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47 \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47",
        {
          method: "GET",
          headers: {
            "accept": "application/json",
            "authorization": "Bearer <token>",
            "content-type": "application/json",
          },
        }
      );
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.get(
          "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47",
          headers={
              "accept": "application/json",
              "authorization": "Bearer <token>",
              "content-type": "application/json",
          },
      )
      print(response.json())
      ```

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

      import (
      	"fmt"
      	"io"
      	"net/http"
      )

      func main() {
      	req, _ := http.NewRequest("GET", "https://api-test.p2p.org/api/v1/celestia/celestia-mainnet-beta/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47", nil)
      	req.Header.Set("accept", "application/json")
      	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>

    * `transactionHash` — hash of the transaction.

    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 TIA 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.
  </Step>
</Steps>


## Related topics

- [Sign and Send Transaction](/docs/signing-transaction-celestia.md)
- [Withdrawal](/docs/withdrawal-celestia.md)
- [Staking API reference](/reference/create-celestia-stake-transaction.md)
