> ## 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.

# Standard library

> Free, general-purpose resources under sh.stellarium.stdlib that any request can call.

The Stellarium standard library is a set of general-purpose resources published under the `sh.stellarium.stdlib` path. They cover small tasks that RequestScript doesn't do on its own, such as measuring a string, generating a UUID, or reading the current time.

The resources are hosted by a node running [`stellarium-stdlib`](https://github.com/qualletio/stellarium-stdlib). Its functions have no payment manifest and aren't restricted, so any request can call them for free.

## Resources

> **[Strings](/stdlib/strings)**
>
> `sh.stellarium.stdlib.Strings`

> **[Uuid](/stdlib/uuid)**
>
> `sh.stellarium.stdlib.Uuid`

> **[Datetime](/stdlib/datetime)**
>
> `sh.stellarium.stdlib.Datetime`

| Resource | Function | Parameters | Returns |
| - | - | - | - |
| `Strings` | [`length`](/stdlib/strings#length) | `of: string` | `int32` |
| `Uuid` | [`new`](/stdlib/uuid#new) | none | `string` |
| `Datetime` | [`now`](/stdlib/datetime#now) | none | `string` |

## Calling the standard library

Bind a resource with its fully qualified name, then call its functions with named arguments. You can bind several standard library resources in one request:

```requestscript theme={null}
request NameLengthOrId {
  const strings: sh.stellarium.stdlib.Strings
  const uuid: sh.stellarium.stdlib.Uuid

  const nameLength = strings.length(of: "Ada Lovelace")
  if (nameLength.error == null) {
    return nameLength.value
  }

  const id = uuid.new()
  return id.value
}
```

Like every resource call, each call evaluates to a result object with either `value` or `error` set. Check `error` before you use `value`. See [Requests](/concepts/network#requests).

> [!NOTE]
>
> Your node can only call the standard library if it knows about the node that hosts it. If your node joined through a [starting peer](/concepts/network#joining-a-network) that already knows the `sh.stellarium.stdlib` resources, it copies them on startup. Run `GET /v1/resources` on your node to check.

## Running a stdlib node

You can host the standard library yourself, for example on a [local network](/node/local-network).

**1. Clone and install**

```bash theme={null}
git clone https://github.com/qualletio/stellarium-stdlib.git
cd stellarium-stdlib
pnpm install
```

**2. Create a .env file**

The stdlib server reads three variables of its own. The node also needs the standard `stellarium-ts` variables, such as its signing keys. See [Configuration](/node/configuration).

```bash .env theme={null}
PORT=3200
BASE_URL=http://127.0.0.1:3200
STARTING_PEER=http://127.0.0.1:3000
SIGNING_PUBLIC_KEY=<your public key>
SIGNING_PRIVATE_KEY=<your private key>
API_KEY=<any secret string>
```

| Variable | Default | Description |
| - | - | - |
| `PORT` | `3200` | Port the server listens on. |
| `BASE_URL` | `http://0.0.0.0:{PORT}` | URL peers use to reach this node. |
| `STARTING_PEER` | `http://127.0.0.1:3200` | Node to bootstrap peers and resources from. |

> [!WARNING]
>
> The `STARTING_PEER` default points at the stdlib node's own default address. Set it to another node so the stdlib node joins a network.

**3. Build and start**

```bash theme={null}
pnpm build
pnpm start
```

On startup the node registers `Strings`, `Uuid` and `Datetime`, then announces itself and broadcasts the resources to every known peer.


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