Skip to content
For the complete documentation index optimized for AI agents, see llms.txt or llms-full.txt. A markdown version of this page is available by appending .md to the URL or sending Accept: text/markdown.

Connect to a Stack

For AI agents: the documentation index is at llms.txt (full corpus: llms-full.txt). A markdown source for this page is /using-stacks/connect.md.

This page shows how to add Arete to an existing project and connect to a deployed stack. It uses the hosted ORE mining stack as the example. Browser clients must authenticate with a publishable key; read-only viewing does not require a wallet.


Terminal window
npm install @usearete/react @usearete/sdk zod
a4 install ore --ts \
--output ./src/generated/ore-stack.ts \
--package-name @usearete/react

Create .env.local:

Terminal window
VITE_ARETE_PUBLISHABLE_KEY=hspk_...
App.tsx
import { AreteProvider, useArete } from "@usearete/react";
import { ORE_STREAM_STACK } from "./generated/ore-stack";
const publishableKey = import.meta.env.VITE_ARETE_PUBLISHABLE_KEY;
if (!publishableKey) throw new Error("VITE_ARETE_PUBLISHABLE_KEY is required");
function CurrentOreRound() {
const arete = useArete(ORE_STREAM_STACK);
const board = arete.views.OreBoard.state.use({
address: arete.addresses.board(),
});
const roundId = board.data?.state.roundId;
const round = arete.views.OreRound.state.use(
roundId == null ? undefined : { roundId },
);
if (arete.status === "error") {
return <button onClick={() => void arete.retry()}>Reconnect</button>;
}
if (board.status !== "ready" || round.status !== "ready") {
return <div>Connecting...</div>;
}
return (
<div>
<h1>Live ORE Mining Round</h1>
<p>{arete.status === "connected" ? "Live" : arete.status}</p>
{arete.socketIssue && <p>{arete.socketIssue.message}</p>}
<p>
Round #{round.data?.id.roundId?.toString() ?? "..."} - Motherlode:{" "}
{round.data?.state.motherlode?.toString() ?? "..."}
</p>
</div>
);
}
export default function App() {
return (
<AreteProvider stack={ORE_STREAM_STACK} auth={{ publishableKey }}>
<CurrentOreRound />
</AreteProvider>
);
}
Terminal window
npm run dev

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.

1

Solana

ORE program on-chain

2

Arete

ORE stack (deployed)

3

Your App

Typed live stream

The generated ORE definition contains the WebSocket and HTTP endpoints. The endpoint is publicly discoverable, but hosted connections still require authentication.


A generated stack is like a cartridge: it packages a domain’s typed data and operations. An Arete session is the console that connects one or more of those cartridges and supplies shared session.chain reads and session.execute(...) execution. These terms are a mental model only; generated stacks keep their existing API names and types.

Insert cartridges under names you choose, then access them through session.stacks.<name>. A connected stack has stable views, queries, programs, addresses, constants, defaults, math, read, and flows namespaces when those capabilities are defined. Programs packaged by stacks are automatically promoted by reference to the canonical session.programs.<name> surface; owner-scoped stack paths remain available for disambiguation. Programs use programId, schemas, pdas, addresses, accounts, queries, raw, instructions, transactions, flows, constants, defaults, and math.

There are two ways to get a generated stack:

Install a publicly deployed stack (like ORE) - The CLI generates a deployment-pinned SDK and records its provenance:

Terminal window
a4 install ore --ts \
--output ./src/generated/ore-stack.ts \
--package-name @usearete/sdk
import { ORE_STREAM_STACK } from "./generated/ore-stack";
# Rust — add to Cargo.toml
[dependencies]
a4-stacks = "0.3.0"
use a4_stacks::ore::{OreStack, OreRound};

Generated from your own stack - Build the stack AST first, then use the CLI to generate an SDK for any language:

Terminal window
cargo build
a4 sdk create my-stack --ts
a4 sdk create my-stack --rust

Both approaches produce a generated stack definition that can be inserted into an Arete session. Generated directories are output boundaries: edit the stack, IDL, or extension source and regenerate instead of hand-editing core, entry, extension copies, or sdk-provenance.json.

For writes, prefer semantic .prepare(...) operations. They accept normal camelCase objects and derive or normalize protocol details before you call session.execute(prepared). Use program.raw.<idlInstruction>.build(...) only as the exact IDL escape hatch; raw instruction names, account names, argument names, and nested objects preserve the IDL shape, including snake_case.


StackWebSocket URLData
ORE Mining Roundswss://ore.stack.arete.runLive ORE mining round updates

Each OreRound update has this structure:

{
"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
}
}
SectionDescription
idPrimary key (round_id) and lookup index (round_address)
stateCurrent round state from on-chain account
resultsRound outcome including computed fields
metricsAggregated counts and sums from instructions