> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stoffelmpc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install the Stoffel CLI and add the Rust SDK to your app.

The Rust SDK is the application API for building Stoffel into your product. Its Cargo package is `stoffel-rust-sdk`; the Rust crate you import is `stoffel`.

<Note>
  **Stoffel 0.1.0 Rust SDK**

  Install the CLI for project commands. Add the Rust SDK when your app needs to compile, load, or run Stoffel programs directly.
</Note>

## Prerequisites

* Rust and Cargo, latest stable recommended
* The `stoffel` CLI
* `stoffel-rust-sdk` from crates.io
* A local checkout of [`Stoffel-Labs/stoffel`](https://github.com/Stoffel-Labs/stoffel) only when you need source examples or local crate changes

Install the CLI:

```bash theme={null}
curl -fsSL https://get.stoffelmpc.com | sh
export PATH="$HOME/.local/bin:$PATH"
stoffel --help
```

## Add the SDK from crates.io

```toml theme={null}
[dependencies]
stoffel = { package = "stoffel-rust-sdk", version = "0.1.0" }
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
```

## Optional: use a local checkout

Use a path dependency when your app needs local SDK source changes:

```toml theme={null}
[dependencies]
stoffel = { package = "stoffel-rust-sdk", path = "../stoffel/crates/stoffel-rust-sdk" }
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
```

Adjust the relative path to match your project layout.

## Verify clear execution

Create `src/main.rs`:

```rust theme={null}
use stoffel::prelude::*;

fn main() -> stoffel::Result<()> {
    let result = Stoffel::compile("def main(a: int64, b: int64) -> int64:\n  return a + b")?
        .with_inputs(&[("a", 42_i64), ("b", 58_i64)])
        .execute_clear()?;

    println!("Result: {}", result[0]);
    Ok(())
}
```

Run it:

```bash theme={null}
cargo run
```

Expected output:

```text theme={null}
Result: 100
```

## Verify local MPC execution

For an app-shaped local MPC check, build your Stoffel project first and load the bytecode from Rust:

```bash theme={null}
stoffel build
```

```rust theme={null}
use stoffel::prelude::*;

#[tokio::main]
async fn main() -> stoffel::Result<()> {
    let result = Stoffel::load_file("target/debug/hello-mpc.stflb")?
        .parties(5)
        .threshold(1)
        .with_client_input(0, &[42_i64])
        .execute_local()
        .await?;

    println!("Local MPC result: {}", result[0]);
    Ok(())
}
```

`.execute_local().await?` runs local MPC testing by spawning several MPC nodes/processes on your machine.

## Current SDK surface

The SDK currently includes:

* `Stoffel::compile(source)` and `Stoffel::compile_file(path)` for source compilation.
* `Stoffel::load(bytecode)` and `Stoffel::load_file(path)` for bytecode loading.
* `with_inputs(&[(name, value)])` for named function inputs.
* `with_client_input(slot, &[values])` for ClientStore-style local MPC programs.
* `execute_clear()` for fast local logic checks.
* `execute_local().await` and `execute_local_function(name).await` for local MPC execution.
* `parties(n)` and `threshold(t)` MPC configuration.
* bytecode save/load and summary helpers.
* network deployment/config builders for multi-node experiments.
* observability and error-category helpers.
* on-chain coordinator handles for integration experiments.

## Examples in the repository

The SDK examples live at:

```text theme={null}
crates/stoffel-rust-sdk/examples/
```

Useful starting points:

| Example                     | What it shows                                                                                                                                     |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `quickstart.rs`             | Clear local execution with named inputs.                                                                                                          |
| `local_mpc_named_inputs.rs` | Recommended local MPC smoke test using `Share` values with named inputs.                                                                          |
| `local_mpc_client_input.rs` | Recommended ClientStore smoke test using local client slots.                                                                                      |
| `quickstart_mpc.rs`         | Direct `secret int64` argument example; useful for reading, but the `Share` and `ClientStore` examples are the more reliable current smoke tests. |
| `bytecode_roundtrip.rs`     | Save bytecode, load it back, and execute.                                                                                                         |
| `network_config.rs`         | Generate and parse network deployment TOML.                                                                                                       |
| `observability.rs`          | Tracing, metrics, server health, and error categories.                                                                                            |
| `onchain.rs`                | On-chain coordinator handle setup.                                                                                                                |

Run an example from the repository:

```bash theme={null}
cd /path/to/stoffel
cargo run -p stoffel-rust-sdk --example quickstart
cargo run -p stoffel-rust-sdk --example local_mpc_named_inputs
cargo run -p stoffel-rust-sdk --example local_mpc_client_input
```

## Troubleshooting

### `use stoffel::prelude::*` cannot resolve

Confirm that your dependency renames the crates.io package to the library crate name:

```toml theme={null}
stoffel = { package = "stoffel-rust-sdk", version = "0.1.0" }
```

### Cargo builds take a while

The SDK pulls MPC, networking, and coordinator crates through Cargo. The first build can take several minutes.

## Next steps

* [Rust SDK Examples](./examples)
* [CLI Overview](../cli/overview)
* [Quick Start](../getting-started/quick-start)
