# Coding Verifiable Components

Proven Network uses a virtual machine which can run code targeting the WASM Component Model. Let's look at an example component!

{% code title="wit/rock-paper-scissors.wit" %}

```
package component:rps-example;

world rps-example {
  import @proven-network:storage/identity-kv;
  
  enum move {
    rock,
    paper,
    scissors,
  }

  enum outcome {
    win,
    loss,
    draw,
  }

  record metrics {
    played: u32,
    won: u32,
    lost: u32,
    drawn: u32,
  }

  export play: func(move: move) -> outcome;
  export score: func() -> metrics;
}
```

{% endcode %}

Here we're defining a simple rock-paper-scissors games which allows player to call a play function with their selected move and get an outcome in return.

WIT files are used by language-specific build tools to automatically handle all required codegen. Let's implement the play function in Rust using the cargo-component tooling.

{% code title="src/lib.rs" fullWidth="false" %}

```rust
mod bindings; // This module is automatically generated by cargo-component

use bindings::{
    Guest, Metrics, Move,
    Move::{Paper, Rock, Scissors},
    Outcome,
    Outcome::{Draw, Loss, Win}
};

use rand::Rng;

struct Component;

impl Guest for Component {
    fn play(input: Move) -> Outcome {
        let server_selection = [Rock, Paper, Scissors][rand::thread_rng().gen_range(0..3)];

        match (input, server_selection) {
            (Rock, Scissors) | (Scissors, Paper) | (Paper, Rock) => Win,
            (Rock, Rock) | (Scissors, Scissors) | (Paper, Paper) => Draw,
            _ => Loss,
        }
    }
}

bindings::export!(Component with_types_in bindings);
```

{% endcode %}

### Accessing persistent storage

Coming soon

### Further reading on the Webassembly Component Model

Further documentation on the WA Component Model can be found on the Bytecode Alliance documentation site: [https://component-model.bytecodealliance.org/](https://component-model.bytecodealliance.org/introduction.html)


---

# Agent Instructions: 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:

```
GET https://docs.proven.network/coding-verifiable-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
