> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/getting-started/rust-quick-start.md).

# Rust quick start

Encrypt a first confidential contract input from Rust with the Zama SDK daemon.

{% hint style="warning" %}
The daemon and its Go and Rust clients are experimental. The wire protocol can change between minor versions, so upgrade the daemon image and the clients together.
{% endhint %}

We'll encrypt `1000` as an `euint64` for a confidential contract on Sepolia and print the encrypted value and the size of its input proof. You don't sign or broadcast anything.

The Rust client talks to a local SDK daemon over a private Unix socket. The daemon runs the Zama SDK, so your application stays in Rust.

You need Rust 1.94.1 or later, Docker Compose on Linux or Docker Desktop, a Sepolia RPC URL, the address of your confidential contract, and the address of the user who will submit the input.

## Authentication

The Sepolia testnet relayer needs no API key, so this quick start leaves authentication unset. The Zama-hosted mainnet relayer requires a key. When you move to mainnet, set it on the chain configuration:

```rust
let chain = ChainConfig::new(1, rpc_url).with_auth(RelayerAuth::api_key(env::var("RELAYER_API_KEY")?));
let config = SdkConfig::from_chains(1, vec![chain]);
```

See [Authentication](https://docs.zama.org/protocol/sdk/guides/authentication.md) and [Relayer API keys](https://docs.zama.org/protocol/sdk/guides/relayer-api-keys.md) to get a key and keep it out of your logs.

## Install

Create a binary project and add the client with the runtime this example uses:

```sh
export ZAMA_SDK_VERSION=3.8.0
cargo new encrypt-input
cd encrypt-input
cargo add zama_sdk@=$ZAMA_SDK_VERSION
cargo add anyhow
cargo add tokio --features macros,rt
```

The client runs on Tokio. You can use your application's existing runtime and error type instead of `#[tokio::main]` and `anyhow`.

`ZAMA_SDK_VERSION` pins the client here and the daemon image that Compose starts later: both must run the same version. See [Client and daemon compatibility](https://docs.zama.org/protocol/sdk/api-references/client-and-daemon-compatibility.md).

## Set up the SDK

Download the daemon's [Compose file](https://docs.zama.org/protocol/sdk/go-and-rust-guide/operations/run-in-production.md#run-with-docker-compose):

```sh
curl -fsSL -o zama-sdk-daemon.yaml "https://raw.githubusercontent.com/zama-ai/sdk/v${ZAMA_SDK_VERSION}/packages/sdk-daemon/deploy/compose.yaml"
```

Save this as `compose.yaml`. It runs your program in a Rust container next to the daemon. Both run as UID 10000 and GID 10001, the daemon image's user, and share the daemon's socket volume:

```yaml
include:
  - zama-sdk-daemon.yaml

services:
  app:
    image: rust:1.94.1
    user: "10000:10001"
    working_dir: /src
    environment:
      - DAEMON_SOCKET=/run/zama/sdk.sock
      - CARGO_HOME=/tmp/cargo
      - CARGO_TARGET_DIR=/tmp/target
      - SEPOLIA_RPC_URL
      - CONTRACT_ADDRESS
      - USER_ADDRESS
    volumes:
      - .:/src:ro
      - socket:/run/zama:ro
    depends_on:
      daemon:
        condition: service_healthy
    command: ["cargo", "run", "--locked"]
```

The daemon needs outbound access to your RPC endpoint and to the Sepolia relayer. Your application connects with `Client::connect` and builds an `Sdk` from a chain configuration. The SDK context lives in the daemon until you close it.

## Your first encrypted input

Replace `src/main.rs` with:

```rust
use anyhow::Result;
use std::{env, time::Duration};
use zama_sdk::{Address, Client, EncryptInput, EncryptOptions, EncryptParams, SdkConfig};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
    let socket = env::var("DAEMON_SOCKET")?;
    let rpc_url = env::var("SEPOLIA_RPC_URL")?;
    let contract_address: Address = env::var("CONTRACT_ADDRESS")?.parse()?;
    let user_address: Address = env::var("USER_ADDRESS")?.parse()?;

    let client = Client::connect(socket)
        .await?
        .with_timeout(Duration::from_secs(120));
    let sdk = client.sdk(SdkConfig::new(11155111, rpc_url)).build().await?;

    let inputs = [EncryptInput::Uint64(1000.into())];
    let result = sdk
        .encrypt(
            EncryptParams {
                values: &inputs,
                contract_address,
                user_address,
            },
            EncryptOptions::default(),
        )
        .await;
    let closed = sdk.close().await;
    let encrypted = result?;
    closed?;

    println!("Encrypted value: {}", encrypted.encrypted_values[0]);
    println!("Input proof: {} bytes", encrypted.input_proof.len());
    Ok(())
}
```

Set your values and run it:

```sh
export SEPOLIA_RPC_URL=https://your-sepolia-rpc.example
export CONTRACT_ADDRESS=0xYourConfidentialContract
export USER_ADDRESS=0xYourUserAddress
cargo generate-lockfile
docker compose run --rm app
```

`docker compose run` starts the daemon, waits for its healthcheck, then runs the program. Each run builds the program in a fresh container, so it takes a few minutes. It prints one encrypted value and a nonzero proof size. Pass both to your confidential contract call. They change on every run.

When you're done, stop the daemon. Add `-v` to also delete its volumes, including stored credentials:

```sh
docker compose down
```

## Next steps

* [Configuration](https://docs.zama.org/protocol/sdk/guides/configuration.md) -- chains, relayers, provider options, storage, and the daemon connection
* [Encrypt & decrypt](https://docs.zama.org/protocol/sdk/guides/encrypt-decrypt.md) -- submit encrypted inputs and decrypt contract results
* [Attach a wallet](https://docs.zama.org/protocol/sdk/go-and-rust-guide/guides/attach-wallet.md) -- signatures for private decryption and transaction writes
* [Rust client API](https://docs.zama.org/protocol/sdk/api-references/rust-client.md) -- generated crate reference
* [Deploy in production](https://docs.zama.org/protocol/sdk/go-and-rust-guide/operations/run-in-production.md) -- run the daemon on your infrastructure


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/getting-started/rust-quick-start.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
