Overview

The Capsule Server SDK enables secure server-side signing by importing client-side sessions, ideal for automated transaction signing and server-side wallet operations. The server SDK provides nearly identical functionality to client-side implementations, allowing seamless transition between environments.

You can also use the Server SDK with pre-generated wallets if your use case requires wallet creation to occur server-side. To do this, follow the steps outlined in the Pre-generated Wallet Integration Guide and import the @usecapsule/server-sdk package in your server-side environment instead of the relevant client side package.

Installation

Usage

When you need to perform signing operations server-side, you can export an active session from your client application and import it into a server-side Capsule instance. This creates a server-side replica of your client-side wallet that can perform the same operations.

1

Export Client Session

In your client application, export the active session to get a serialized string:

// Client-side
const serializedSession = await capsule.exportSession();
// Send this string to your server endpoint
2

Initialize Server SDK

On your server, initialize the Capsule Server SDK:

// Server-side route
import { Capsule as CapsuleServer, Environment } from "@usecapsule/server-sdk";

const capsuleServer = new CapsuleServer(Environment.BETA, API_KEY);
3

Import Session

Import the serialized session to create a functional server-side client:

// Server-side await
capsuleServer.importSession(serializedSession); 
4

Perform Operations

Use the server-side instance just like a client-side one:

// Direct signing
const signature = await capsuleServer.signMessage(walletId, messageToSign);

// With ethers.js
import { CapsuleEthersSigner } from "@usecapsule/ethers-v6-integration";

const ethersSigner = new CapsuleEthersSigner(capsuleServer, provider);
const signature = await ethersSigner.signMessage(messageToSign);

Implement secure session transfer between client and server. The server can only perform signing while the imported session remains valid.

Examples

Explore our example implementation of the Server SDK:

Best Practices

  • Keep imported sessions secure and ephemeral
  • Implement proper error handling for invalid sessions
  • Monitor signing operations for security
  • Regularly refresh sessions to maintain functionality