> For the complete documentation index, see [llms.txt](https://docs.seismic.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seismic.systems/tutorials/understanding-the-clown-beatdown-contract/writing-the-contract.md).

# Writing the Contract

This section dives into the heart of Clown Beatdown — the **shielded smart contract** that powers its functionality. You'll start by building the secrets pool using shielded storage, then implement the stamina system and the robbery mechanic, before adding rounds, resets, and contributor-based access control. By the end of this section, you'll have a fully functional, round-based ClownBeatdown contract that is secure, fair, and replayable.

### What You'll Learn

In this section, you'll:

* Define a pool of **shielded secrets** using `sbytes` and a shielded index using `suint256`.
* Build the **stamina bar**, the protective layer that guards the secrets, and implement a `hit()` function to reduce it.
* Add a `rob()` function to reveal a randomly selected secret to authorized contributors.
* Implement a reset mechanism to restart the game for multiple rounds.
* Track player contributions in each round, ensuring that only contributors can rob the clown.

### Overview of Chapters

* [**Chapter 1: The Secrets Pool**](/tutorials/understanding-the-clown-beatdown-contract/writing-the-contract/chapter-1-the-secrets-pool.md)

You'll define the secrets pool using shielded storage (`sbytes`) and a shielded index (`suint256`), and implement an `addSecret()` function to populate it. This chapter introduces **shielded writes.**

* [**Chapter 2: The Stamina Bar and Robbing Secrets**](/tutorials/understanding-the-clown-beatdown-contract/writing-the-contract/chapter-2-the-stamina-bar-and-robbing-secrets.md)

Learn how to build the stamina system, which protects the secrets from being accessed prematurely. You'll implement the `hit()` function to reduce stamina and the `rob()` function to reveal a secret once conditions are met.

* [**Chapter 3: Reset Mechanism, Rounds, and Contributor Access**](/tutorials/understanding-the-clown-beatdown-contract/writing-the-contract/chapter-3-reset-mechanism-rounds-and-contributor-access.md)

This chapter introduces a reset mechanism to enable multiple rounds of gameplay. You'll track contributions per round and ensure that only players who helped knock out the clown in a specific round can rob it. This chapter introduces **signed reads.**


---

# 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://docs.seismic.systems/tutorials/understanding-the-clown-beatdown-contract/writing-the-contract.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.
