> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-sdk/quickstart.md).

# Quickstart

This guide takes you from an empty project to a signed-in user. It should take just a few minutes.

{% hint style="info" %}
The SDK runs in the **browser** and needs **HTTPS** (`localhost` is exempt). See the [Introduction](/baas-sdk/sdk.md) for the full prerequisites.
{% endhint %}

{% stepper %}
{% step %}

### Install the SDK

{% tabs %}
{% tab title="npm" %}

```bash
npm install @baas/sdk
```

{% endtab %}

{% tab title="pnpm" %}

```bash
pnpm add @baas/sdk
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add @baas/sdk
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Get your credentials

You need three values to connect the SDK to your project:

* `projectId` and `apiUrl` — from your **BaaS Dashboard**
* `publishableKey` (starts with `sb_publishable_`) and `apiUrl` — from your project's **BaaS Console**

{% hint style="info" %}
Store these in environment variables rather than hard-coding them. The publishable key is meant to be public (it ships in your client bundle), but using env vars keeps configuration clean across environments.
{% endhint %}
{% endstep %}

{% step %}

### Initialize the client

Create the client **once**, at the root of your app. It's **synchronous**, so `getSession()` works right away. The SDK fetches your project's networks lazily, on the first sign-in.

{% code title="baas.ts" %}

```ts
import { createBaasClient } from '@baas/sdk';

export const baas = createBaasClient({
  projectId:      'my-baas-project',
  publishableKey: 'sb_publishable_xxx',
  apiUrl:         'https://my-project-api.baas.sh',
});
```

{% endcode %}
{% endstep %}

{% step %}

### Create the user's account

For a brand-new user, create a passkey and sign in:

```ts
const session = await baas.auth.signUp();
//  → { address: '0x…', accessToken: 'eyJ…', expiresAt: 1735689600 }
```

A **returning** user signs in with their existing passkey instead:

```ts
const session = await baas.auth.signIn();
```

Both default to passkeys. See [Authentication](/baas-sdk/authentication.md) for wallet sign-in and the difference between sign up and sign in.
{% endstep %}

{% step %}

### React to auth state

Keep your UI in sync with the session. The callback fires immediately with the current state, then on every change.

```ts
const unsubscribe = baas.auth.onAuthStateChange((session) => {
  if (session) console.log('Signed in as', session.address);
  else         console.log('Signed out');
});
```

{% endstep %}

{% step %}

### Sign out

```ts
await baas.auth.signOut();
```

{% endstep %}
{% endstepper %}

{% hint style="success" %}
**`signIn()` and `signUp()` are zero-config shortcuts** (passkey by default), perfect for getting started in one line. When you need wallet sign-in or finer control, reach for the explicit methods covered in [Authentication](/baas-sdk/authentication.md).
{% endhint %}

<details>

<summary>Going to production</summary>

Two things to check before you ship, both configured outside the SDK:

* **CORS / origin** — sign-in and token refresh rely on an `HttpOnly` cookie, so the SDK sends requests with credentials. In production, **your app's origin must be allowed by your BaaS API** (credentialed CORS, no wildcard origin), otherwise token refresh fails silently. This is configured per project on the API side.
* **HTTPS** — required on any domain other than `localhost` (passkeys and WebAuthn need a secure origin).

</details>

## Next steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Authentication</strong></td><td>Passkeys, wallets, and the sign up vs sign in model.</td><td><a href="/pages/f0kFN583tRSVnXa7wuan">/pages/f0kFN583tRSVnXa7wuan</a></td></tr><tr><td><strong>Integration guides</strong></td><td>Framework guides, supported bundlers, and TypeScript setup.</td><td><a href="/pages/1q4AjEG7o1BZ5Z6hEuwV">/pages/1q4AjEG7o1BZ5Z6hEuwV</a></td></tr><tr><td><strong>Blockchain interactions</strong></td><td>Call your smart contracts, send transactions, and switch networks.</td><td><a href="/pages/Djvoam2RWqSjubUCII8o">/pages/Djvoam2RWqSjubUCII8o</a></td></tr></tbody></table>


---

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

```
GET https://docs.baas.sh/baas-sdk/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
