# Node backend (/docs/swivy/node-backend)

<Callout type="warn" title="Preview: Swivy is not generally available">
Swivy is a **staging/testnet preview using software custody**, not a production custody service. All six public SDK packages are available at **1.0.1**. Use test assets only. [Set up the preview](/docs/swivy/preview-setup) or [request project access](/docs/swivy/request-access).
</Callout>

Use `@swivy/node` when your server needs to finish a login, read the signed-in user, create wallets, submit intents, configure networks or hand an AI agent a [session grant](/docs/swivy/agent-session-grants).

Use the API base URL shown in your environment’s Integrations screen. The public docs/dashboard alias is not the runtime API base URL. Follow the [SDK version and dependency guidance](/docs/swivy/preview-setup) before installing.

## 1. Install and configure [#1-install-and-configure]

```bash
npm install @swivy/node@1.0.1
```

```bash
SWIVY_BASE_URL=https://YOUR_SWIVY_BASE_URL
SWIVY_APP_ID=app_...
SWIVY_SECRET_KEY=sk_swivy_...
SWIVY_CONTROL_PLANE_KEY=sak_swivy_...   # only for admin tasks: projects, environments, chains, webhooks
```

<Callout type="danger" title="Keep server keys on the server">
`SWIVY_SECRET_KEY` and `SWIVY_CONTROL_PLANE_KEY` must never reach a browser or a mobile app. Browsers and phones use the publishable key.
</Callout>

```ts
import { SwivyNodeClient } from '@swivy/node';

export const createSwivyClient = () => new SwivyNodeClient({
  baseUrl: process.env.SWIVY_BASE_URL!,
  appId: process.env.SWIVY_APP_ID!,
  secretKey: process.env.SWIVY_SECRET_KEY!,
  controlPlaneKey: process.env.SWIVY_CONTROL_PLANE_KEY,
});
```

## 2. Finish a login [#2-finish-a-login]

```ts
export async function finishLogin(email: string, code: string) {
  const swivy = createSwivyClient(); // one session state per request/user
  const login = await swivy.verifyEmailCode(email, code);
  const me = await swivy.getMe();
  return { sessionToken: login.sessionToken, user: me.identity, wallets: me.managedAccounts };
}
```

The client keeps the session token in memory. Create a client per request/user; do not share a mutable logged-in client across customers. For the following examples, create a fresh client with `const swivy = createSwivyClient()` and attach the requesting user’s session with `swivy.setSessionToken(token)`.

## 3. Create or load a wallet [#3-create-or-load-a-wallet]

```ts
const { account } = await swivy.ensureEmbeddedWallet('evm', { label: 'Primary wallet' });
```

Chain families are `'evm'` and `'solana'`.

## 4. Submit a transaction intent [#4-submit-a-transaction-intent]

```ts
const intent = await swivy.createTransactionIntentAndWait({
  accountId: account.id,
  chain: 'evm',
  challengeId, // from the user's passkey step-up, when policy requires it
  payload: {
    network: 'base-sepolia',
    transaction: { to: '0x1111111111111111111111111111111111111111', value: '0x0', data: '0x' },
  },
});
```

## 5. Point each network at an RPC [#5-point-each-network-at-an-rpc]

```ts
await swivy.upsertEnvironmentChainRpcConfig('env_...', 'evm', {
  network: 'base-sepolia',
  rpcUrl: 'https://YOUR_BASE_RPC',
});

await swivy.upsertEnvironmentChainRpcConfig('env_...', 'solana', {
  network: 'solana-devnet',
  rpcUrl: 'https://YOUR_SOLANA_RPC',
  commitment: 'confirmed',
});
```

You can point these at [Swop RPC](/docs/rpc) project URLs.

## 6. Manage admin keys [#6-manage-admin-keys]

Rotate to narrower, organization-scoped keys after setup:

```ts
const created = await swivy.createOrganizationAdminCredential('org_...', { label: 'Ops admin', role: 'admin' });
await swivy.listOrganizationAdminCredentials('org_...');
await swivy.revokeOrganizationAdminCredential('org_...', 'orgkey_...');
```

Swivy won't let you remove the last active owner key of an organization.

## Export and raw signing [#export-and-raw-signing]

`exportManagedAccount` and `rawSign` exist for hybrid-custody escape hatches. Both need a step-up challenge and are off unless your environment policy allows them. Prefer intents.
