> For the complete documentation index, see [llms.txt](https://docs.luganodes.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luganodes.com/apis/staking-apis-v2/solana/staking-guide.md).

# Staking Guide

## Staking

Staking on Solana involves delegating your SOL to a validator to help secure the network and earn rewards. This is done using the **Stake API**, which returns an unsigned transaction. You must **sign and broadcast** this transaction with your wallet's private key. Once confirmed, your SOL is actively staked and starts earning rewards from the next epoch.

### Supported Environments

Luganodes supports the following environments on SOL, as defined below

<table data-header-hidden><thead><tr><th width="356">Base URL</th><th>ETH Network</th></tr></thead><tbody><tr><td><a href="https://staking.luganodes.com/solana">https://api.luganodes.com/solana</a></td><td>Solana Mainnet </td></tr></tbody></table>

{% hint style="info" %}
Please contact <hello@luganodes.com> in order to receive an API key.
{% endhint %}

**Step:**

* Call [**Stake API**](/apis/staking-apis-v2/solana/staking.md#stake-request) → sign & broadcast the transaction

#### Script for signing and broadcasting unsigned stake transaction

```javascript
import { Connection, Transaction, Keypair } from "@solana/web3.js";
import dotenv from "dotenv";
import bs58 from "bs58";

dotenv.config();

// Connect to the Solana cluster
const connection = new Connection(
  "https://api.mainnet-beta.solana.com",
  "confirmed"
);

const walletKeypair = Keypair.fromSecretKey(
  bs58.decode(process.env.SOLANA_PRIVATE_KEY)
);

const unsignedTransaction = ""; //paste unsigned transaction here

const decodedTransaction = Buffer.from(unsignedTransaction, "base64");

const transaction = Transaction.from(decodedTransaction);
transaction.partialSign(walletKeypair);

(async () => {
  const txSignature = await connection.sendRawTransaction(
    transaction.serialize()
  );
  console.log(`Transaction sent: https://solscan.io/tx/${txSignature}`);
})();
```

{% hint style="info" %}
Create a `.env` file in your project root and add your wallet's private key
{% endhint %}

## Unstaking

Unstaking is a two-step process: **Deactivation** followed by **Withdrawal**. First, use the **Deactivate API** to stop the validator from using your stake—this begins the cooldown period (typically 1 epoch). Once the stake is fully deactivated, use the **Withdraw API** to transfer your SOL back to your wallet. Both steps return unsigned transactions that must be signed and broadcasted.

**Steps:**

1. Call [**Deactivate API**](/apis/staking-apis-v2/solana/withdrawals.md#deactivate-request) → sign & broadcast
2. Wait for deactivation to complete (check with [**Balance API**](/apis/staking-apis-v2/solana/staking.md#balance)  for`status`of  stake account if needed)
3. Call [**Withdraw API**](/apis/staking-apis-v2/solana/withdrawals.md#withdraw) → sign & broadcast the transaction

#### Script for signing and broadcasting unsigned deactivate and withdraw transaction

```javascript
import { Connection, Transaction, Keypair } from "@solana/web3.js";
import dotenv from "dotenv";
import bs58 from "bs58";

dotenv.config();

// Connect to the Solana cluster
const connection = new Connection(
  "https://api.mainnet-beta.solana.com",
  "confirmed"
);

const walletKeypair = Keypair.fromSecretKey(
  bs58.decode(process.env.SOLANA_PRIVATE_KEY)
);

const unsignedTransaction = ""; //paste unsigned transaction here

const decodedTransaction = Buffer.from(unsignedTransaction, "base64");

const transaction = Transaction.from(decodedTransaction);
transaction.Sign(walletKeypair);

(async () => {
  const txSignature = await connection.sendRawTransaction(
    transaction.serialize()
  );
  console.log(`Transaction sent: https://solscan.io/tx/${txSignature}`);
})();
```
