> For the complete documentation index, see [llms.txt](https://kaze-ai.gitbook.io/kaze-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kaze-ai.gitbook.io/kaze-ai/token-operations/stake-sol.md).

# Stake SOL

**Code Breakdown**

**1. Endpoint Interaction**

The staking function interacts with the Jup API to prepare a staking transaction:

Copy

```
url = f"https://worker.jup.ag/blinks/swap/So11111111111111111111111111111111111111112/jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v/{amount}"  
payload = {"account": str(agent.wallet_address)}  

async with aiohttp.ClientSession() as session:  
    async with session.post(url, json=payload) as res:  
        if res.status != 200:  
            raise Exception(f"Failed to fetch transaction: {res.status}")  
        data = await res.json()  
```

**2. Transaction Deserialization and Signing**

The API returns a serialized transaction that needs to be deserialized, updated, and signed by the user's wallet:

Copy

```
txn = VersionedTransaction.deserialize(base64.b64decode(data["transaction"]))  
latest_blockhash = await agent.connection.get_latest_blockhash()  
txn.message.recent_blockhash = latest_blockhash.value.blockhash  
txn.sign([agent.wallet])  
```

**3. Submitting and Confirming the Transaction**

The transaction is submitted to the Solana network, and its status is confirmed:

Copy

```
signature = await agent.connection.send_raw_transaction(  
    txn.serialize(),  
    opts={"skip_preflight": False, "max_retries": 3},  
)  

await agent.connection.confirm_transaction(  
    signature,  
    commitment=Confirmed,  
    last_valid_block_height=latest_blockhash.value.last_valid_block_height,  
)  
```

**4. Error Handling**

If any part of the staking process fails, meaningful exceptions are raised for debugging:

Copy

```
except Exception as e:  
    raise Exception(f"jupSOL staking failed: {str(e)}")  
```

***

**Key Features**

1. **Effortless Staking**
   * Automatically interacts with Jup API to stake SOL.
2. **Transaction Safety**
   * Ensures the transaction uses the latest blockhash and is properly signed.
3. **Error Resilience**
   * Catches and reports API or network issues to ensure reliable staking operations.
4. **Minimal Setup**
   * Only requires the agent instance and the desired staking amount.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kaze-ai.gitbook.io/kaze-ai/token-operations/stake-sol.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
