---
title: "Connect to a Stack"
description: "Add Arete to an existing project and stream live Solana data."
editUrl: true
head: []
template: "doc"
sidebar: {"order":2,"hidden":false,"attrs":{}}
pagefind: true
draft: false
---

This page shows how to add Arete to an existing project and connect to a deployed stack. It uses the public **ORE mining stack** as the example — no account or API key required.

:::note[Does a stack exist for your program?]
This guide is for connecting to a stack that's already deployed. If you want to stream data from your **own on-chain program**, you'll need to build a stack for it first — see [Build Your Own Stack](/building-stacks/workflow/).

Deploying custom stacks is currently in closed beta. [Get in touch](https://arete.run) if you'd like early access.
:::

:::tip[Starting from scratch?]
If you're creating a new project and just want to see Arete working with the ORE demo, the [Quickstart](/using-stacks/quickstart/) scaffolds everything automatically.
:::

---

## Install & Connect

### React: Install

```bash
npm install arete-react zustand
```

### React: Add to your app

```tsx
// App.tsx
import { AreteProvider, useArete } from "arete-react";
import { ORE_STREAM_STACK } from "arete-stacks/ore";

function OreRounds() {
  const { views, isConnected } = useArete(ORE_STREAM_STACK);
  const { data: rounds, isLoading } = views.OreRound.latest.use({
    take: 5,
  });

  if (isLoading) return <div>Connecting...</div>;

  return (
    <div>
      <h1>Live ORE Mining Rounds {isConnected && "🟢"}</h1>
      {rounds?.map((round) => (
        <div key={round.id?.round_id}>
          Round #{round.id?.round_id} — Motherlode: {round.state?.motherlode}
        </div>
      ))}
    </div>
  );
}

export default function App() {
  return (
    <AreteProvider websocketUrl="wss://ore.stack.arete.run">
      <OreRounds />
    </AreteProvider>
  );
}
```

### React: Run it

```bash
npm run dev
```

### TypeScript: Install

```bash
npm install arete-typescript
```

### TypeScript: Create a script

```typescript
// stream.ts
import { Arete } from "arete-typescript";
import { ORE_STREAM_STACK, type OreRound } from "arete-stacks/ore";

async function main() {
  const a4 = await Arete.connect("wss://ore.stack.arete.run", {
    stack: ORE_STREAM_STACK,
  });

  for await (const update of a4.views.OreRound.latest.watch()) {
    if (update.type === "upsert") {
      const round = update.data;
      console.log(`Round #${round.id?.round_id}`);
      console.log(`  Motherlode: ${round.state?.motherlode}`);
    }
  }
}

main().catch(console.error);
```

### TypeScript: Run it

```bash
npx tsx stream.ts
```

### Rust: Add to Cargo.toml

```toml
[dependencies]
a4-sdk = "{{VERSION}}"
a4-stacks = "{{VERSION}}"
```

### Rust: Write the code

```rust
// src/main.rs
use a4_sdk::prelude::*;
use a4_stacks::ore::{OreStack, OreRound};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let a4 = Arete::<OreStack>::connect().await?;

    let mut stream = a4.views.ore_round.latest().listen();

    while let Some(round) = stream.next().await {
        println!("Round #{:?}", round.id.round_id);
        println!("  Motherlode: {:?}", round.state.motherlode);
    }

    Ok(())
}
```

### Rust: Run it

```bash
cargo run
```

For quick inspection without any SDK, open your browser console and paste:

```javascript
const ws = new WebSocket("wss://ore.stack.arete.run");

ws.onopen = () => {
  ws.send(JSON.stringify({ type: "subscribe", view: "OreRound/latest" }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  if (data.type === "upsert") console.log("Round update:", data.data);
};
```

---

## How it Works

You connected to a deployed Arete stack. The ORE stack watches the Solana blockchain, extracts round data from on-chain transactions, and pushes typed updates to your app via WebSocket as they happen — no polling, no RPC calls, no indexer to run.

The stack is public — just point your SDK at the WebSocket URL.

---

## About Stack SDKs

A stack SDK tells the Arete client what entities and views are available, and provides the types for each. There are two ways to get one:

**Pre-built for publicly deployed stacks (like ORE)** — We publish ready-to-use SDKs for both TypeScript and Rust:

```bash
# TypeScript / React
npm install arete-stacks
```

```typescript
import { ORE_STREAM_STACK } from "arete-stacks/ore";
```

```toml
# Rust — add to Cargo.toml
[dependencies]
a4-stacks = "{{VERSION}}"
```

```rust
use a4_stacks::ore::{OreStack, OreRound};
```

**Generated from your own stack** — When you build a custom stack, use the CLI to generate an SDK for any language:

```bash
a4 sdk create typescript my-stack
a4 sdk create rust my-stack
```

Both approaches produce the same result: a typed SDK that works identically with the Arete client.

---

## Available Public Stacks

| Stack                 | WebSocket URL               | Data                          |
| --------------------- | --------------------------- | ----------------------------- |
| **ORE Mining Rounds** | `wss://ore.stack.arete.run` | Live ORE mining round updates |

---

## ORE Data Shape

Each `OreRound` update has this structure:

```json
{
  "id": {
    "round_id": 142857,
    "round_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
  },
  "state": {
    "expires_at": 312645000,
    "motherlode": 5000000000,
    "total_deployed": 125000000000,
    "total_vaulted": 12500000000,
    "total_winnings": 98500000000
  },
  "results": {
    "top_miner": "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
    "top_miner_reward": 2500000000,
    "winning_square": 18,
    "did_hit_motherlode": false
  },
  "metrics": {
    "deploy_count": 1847,
    "total_deployed_sol": 125000000000,
    "checkpoint_count": 423
  }
}
```

| Section   | Description                                                 |
| --------- | ----------------------------------------------------------- |
| `id`      | Primary key (`round_id`) and lookup index (`round_address`) |
| `state`   | Current round state from on-chain account                   |
| `results` | Round outcome including computed fields                     |
| `metrics` | Aggregated counts and sums from instructions                |

:::tip[View the source]
The full ORE stack definition is on GitHub: [stacks/ore/src/stack.rs](https://github.com/AreteA4/arete/blob/main/stacks/ore/src/stack.rs)
:::

---

## Next Steps

- [How It Works](/using-stacks/how-it-works/) — Understand Stacks, Views, and how the stream model works
- [React SDK](/sdks/react/) — React hooks and patterns in depth
- [TypeScript SDK](/sdks/typescript/) — Use with Node.js, Vue, Svelte, or vanilla JS
- [Rust SDK](/sdks/rust/) — Native Rust client
- [Build Your Own Stack](/building-stacks/workflow/) — Stream data from your own on-chain program
