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

# Quickstart

> Run a Stellarium node, register a resource, and call it with RequestScript.

`stellarium-ts` is the TypeScript implementation of a Stellarium node. You embed it in a [Fastify](https://fastify.dev/) server, register the resources that live in your process, and optionally bootstrap peers and resources from a node that is already running.

## Prerequisites

* Node.js 20+
* [Fastify](https://fastify.dev/) 5, which you create and pass to the node
* [RequestScript](https://www.npmjs.com/package/requestscript), the language your resources and requests use

<Steps>
  <Step title="Install the packages">
    ```bash theme={null}
    npm install stellarium-ts fastify requestscript
    ```
  </Step>

  <Step title="Generate signing keys">
    Nodes sign the data they publish to peers with an Ed25519 key pair. Generate one:

    ```bash theme={null}
    node --input-type=module -e '
    import { generateKeyPairSync } from "node:crypto";

    const { publicKey, privateKey } = generateKeyPairSync("ed25519", {
      publicKeyEncoding: { type: "spki", format: "der" },
      privateKeyEncoding: { type: "pkcs8", format: "der" },
    });

    console.log(JSON.stringify({
      publicKey: publicKey.toString("base64url"),
      privateKey: privateKey.toString("base64url"),
    }, null, 2));
    '
    ```
  </Step>

  <Step title="Create a .env file">
    Importing `StellariumNode` loads [dotenv](https://github.com/motdotla/dotenv), so a `.env` file in the working directory is applied automatically.

    ```bash .env theme={null}
    BASE_URL=http://127.0.0.1:3000
    SIGNING_PUBLIC_KEY=<publicKey from the previous step>
    SIGNING_PRIVATE_KEY=<privateKey from the previous step>
    API_KEY=<any secret string>
    ```

    See [Configuration](/node/configuration) for every variable.
  </Step>

  <Step title="Register a resource and start">
    A resource is a host object scripts can call. `path` and `name` form its fully qualified name (`com.example.Weather`). Each function declares RequestScript parameter and return types, and `exec` runs in your process.

    Call `register` before `start`. `start` creates the SQLite database, mounts the HTTP API under `/v1`, and listens.

    ```typescript server.ts theme={null}
    import Fastify from "fastify";
    import { StellariumNode } from "stellarium-ts";
    import type { StellariumResource } from "stellarium-ts";

    const weather: StellariumResource = {
      id: 1,
      baseUrl: process.env.BASE_URL!,
      metadata: {},
      path: "com.example",
      name: "Weather",
      functions: [
        {
          name: "temperature",
          parameters: [{ name: "city", type: "string" }],
          returnType: "int32",
          exec: async (args) => {
            const city = args.find((arg) => arg.name === "city")?.value;
            return city === "Oslo" ? 12 : 20;
          },
        },
      ],
    };

    const node = new StellariumNode();
    await node.register(weather);

    const fastify = Fastify({ logger: true });
    await node.start(fastify, {
      port: 3000,
      // Omit to run standalone. Set to copy peers and resources
      // from a node that is already up (no /v1 suffix).
      // startingPeer: "http://127.0.0.1:3001",
    });
    ```
  </Step>

  <Step title="Run a request">
    Send a RequestScript `request` to your node's `/v1/run` endpoint, authenticated with your `API_KEY`:

    ```bash theme={null}
    curl -X POST http://127.0.0.1:3000/v1/run \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $API_KEY" \
      -d '{"source":"request GetTemperature {\n  const weather: com.example.Weather\n  return weather.temperature(city: \"Oslo\")\n}"}'
    ```

    ```json Response theme={null}
    { "returnValue": 12 }
    ```
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Join a network" icon="network-wired" href="/concepts/network#joining-a-network">
    Bootstrap from an existing node with `startingPeer`.
  </Card>

  <Card title="Charge for a resource" icon="coins" href="/concepts/payments">
    Add a payment manifest to a function.
  </Card>

  <Card title="HTTP API" icon="code" href="/node/http-api">
    Every route a node exposes.
  </Card>

  <Card title="Run a local network" icon="docker" href="/node/local-network">
    Operator, escrow program, and two nodes on localnet.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.