> 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/clients/alloy/examples/basic-setup.md).

# Basic Setup

This example demonstrates how to create Seismic providers in both signed and unsigned variants, verify the connection, and query basic chain state.

## Prerequisites

```bash
# Install Rust 1.82+
rustup update stable

# Set environment variables
export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export RPC_URL="https://testnet-1.seismictest.net/rpc"
```

`Cargo.toml` — see [Installation](/clients/alloy/installation.md) for the full template including the required `[patch.crates-io]` block:

```toml
[package]
name = "basic-setup"
version = "0.1.0"
edition = "2021"
rust-version = "1.82"

[dependencies]
seismic-prelude        = { git = "https://github.com/SeismicSystems/seismic-alloy" }
seismic-alloy-network  = { git = "https://github.com/SeismicSystems/seismic-alloy" }
seismic-alloy-provider = { git = "https://github.com/SeismicSystems/seismic-alloy" }
alloy-provider         = "1.1"
alloy-signer-local     = "1.1"
alloy-primitives       = "1.1"
tokio                  = { version = "1", features = ["full"] }
reqwest                = "0.12"

# [patch.crates-io] block required — see Installation.
```

## Signed Provider (Full Capabilities)

A signed provider can send shielded writes, perform signed reads, and execute all standard Alloy provider operations.

```rust
use seismic_prelude::client::*;
use seismic_alloy_network::reth::SeismicReth;
use alloy_provider::Provider;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load private key from environment
    let signer: PrivateKeySigner = std::env::var("PRIVATE_KEY")?.parse()?;
    let address = signer.address();
    let wallet = SeismicWallet::<SeismicReth>::from(signer);
    let url: reqwest::Url = std::env::var("RPC_URL")?.parse()?;

    // Create signed provider (fetches TEE pubkey automatically)
    let provider = SeismicProviderBuilder::new()
        .wallet(wallet)
        .connect_http(url)
        .await?;

    // Verify connection
    let block_number = provider.get_block_number().await?;
    println!("Block number: {block_number}");

    // Get chain ID
    let chain_id = provider.get_chain_id().await?;
    println!("Chain ID: {chain_id}");

    // Get TEE public key (cached from construction)
    let tee_pubkey = provider.get_tee_pubkey().await?;
    println!("TEE public key: {:?}", tee_pubkey);

    // Check balance of the wallet address (derived from the signer)
    let balance = provider.get_balance(address).await?;
    println!("Address: {address}");
    println!("Balance: {balance} wei");

    Ok(())
}
```

## Unsigned Provider (Read-Only)

An unsigned provider does not require a private key. It can query chain state, read public data, and subscribe to events (via WebSocket), but cannot send transactions or perform signed reads.

```rust
use seismic_prelude::client::*;
use alloy_provider::Provider;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let url: reqwest::Url = std::env::var("RPC_URL")?.parse()?;

    // Create unsigned provider (no private key needed)
    // connect_http is synchronous for unsigned providers
    let provider = SeismicProviderBuilder::new().connect_http(url);

    // Verify connection
    let block_number = provider.get_block_number().await?;
    println!("Block number: {block_number}");

    // Get chain ID
    let chain_id = provider.get_chain_id().await?;
    println!("Chain ID: {chain_id}");

    // Get TEE public key
    let tee_pubkey = provider.get_tee_pubkey().await?;
    println!("TEE public key: {:?}", tee_pubkey);

    // Check any address balance
    let address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".parse()?;
    let balance = provider.get_balance(address).await?;
    println!("Balance: {balance} wei");

    Ok(())
}
```

## Network Selection

The builder defaults to `SeismicReth` (production). Use `.foundry()` for local development:

```rust
use seismic_prelude::client::*;
use seismic_alloy_network::foundry::SeismicFoundry;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let signer: PrivateKeySigner = std::env::var("PRIVATE_KEY")?.parse()?;

    // For production / testnet (SeismicReth — default)
    let wallet = SeismicWallet::from(signer.clone());
    let url: reqwest::Url = std::env::var("RPC_URL")?.parse()?;
    let provider = SeismicProviderBuilder::new()
        .wallet(wallet)
        .connect_http(url)
        .await?;
    println!("Production block: {}", provider.get_block_number().await?);

    // For local development (SeismicFoundry)
    // let local_wallet = SeismicWallet::<SeismicFoundry>::from(signer);
    // let provider = SeismicProviderBuilder::new()
    //     .foundry()
    //     .wallet(local_wallet)
    //     .connect_http("http://127.0.0.1:8545".parse()?)
    //     .await?;

    Ok(())
}
```

## Local Development with Sanvil

For local testing using Sanvil (Seismic Anvil):

```rust
use seismic_prelude::client::*;
use seismic_alloy_network::foundry::SeismicFoundry;
use alloy_node_bindings::Anvil;
use alloy_provider::Provider;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Spawn a local Sanvil instance
    let anvil = Anvil::at("sanvil").spawn();

    // Use one of the pre-funded accounts
    let signer: PrivateKeySigner = anvil.keys()[0].clone().into();
    let wallet = SeismicWallet::<SeismicFoundry>::from(signer);

    // Connect to the local instance
    let provider = SeismicProviderBuilder::new()
        .foundry()
        .wallet(wallet)
        .connect_http(anvil.endpoint_url())
        .await?;

    let block = provider.get_block_number().await?;
    println!("Local Sanvil block: {block}");

    let chain_id = provider.get_chain_id().await?;
    println!("Chain ID: {chain_id}");

    Ok(())
}
```

{% hint style="info" %}
`Anvil::at("sanvil")` requires `sanvil` to be installed and available on your `PATH`. See the Seismic Foundry documentation for installation instructions.
{% endhint %}

## Error Handling

```rust
use seismic_prelude::client::*;
use seismic_alloy_network::reth::SeismicReth;
use alloy_provider::Provider;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let signer: PrivateKeySigner = std::env::var("PRIVATE_KEY")?.parse()?;
    let wallet = SeismicWallet::<SeismicReth>::from(signer);
    let url: reqwest::Url = std::env::var("RPC_URL")?.parse()?;

    // Provider creation can fail if the node is unreachable
    // or the TEE pubkey fetch times out
    let provider = match SeismicProviderBuilder::new()
        .wallet(wallet)
        .connect_http(url)
        .await
    {
        Ok(p) => {
            println!("Provider created successfully");
            p
        }
        Err(e) => {
            eprintln!("Failed to create provider: {e}");
            eprintln!("Check that RPC_URL is reachable and the node is running");
            return Err(e.into());
        }
    };

    // Verify the connection is healthy
    match provider.get_block_number().await {
        Ok(block) => println!("Connected. Block number: {block}"),
        Err(e) => {
            eprintln!("Connection check failed: {e}");
            return Err(e.into());
        }
    }

    Ok(())
}
```

## Expected Output

```
Block number: 12345
Chain ID: 5124
TEE public key: PublicKey(028e76821eb4d77fd30223ca971c49738eb5b5b71eabe93f96b348fdce788ae5a0)
Address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Balance: 10000000000000000000 wei
```

## Next Steps

* [Shielded Write Complete](/clients/alloy/examples/shielded-write-complete.md) - Send encrypted transactions
* [Signed Read Pattern](/clients/alloy/examples/signed-read-pattern.md) - Execute authenticated calls
* [Contract Deployment](/clients/alloy/examples/contract-deployment.md) - Deploy and interact with contracts

## See Also

* [SeismicSignedProvider](/clients/alloy/provider/seismic-signed-provider.md) - Full-featured provider API
* [SeismicUnsignedProvider](/clients/alloy/provider/seismic-unsigned-provider.md) - Read-only provider API
* [Installation](/clients/alloy/installation.md) - Cargo setup and dependencies
* [Provider Overview](/clients/alloy/provider.md) - Provider comparison and filler pipeline


---

# 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/clients/alloy/examples/basic-setup.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.
