API Reference
Node SDK

Node SDK Reference

The Node SDK (@partylayer/enterprise-node) is for server-side integrations. Use it to manage users, apps, wallets, webhooks, and more from your backend.

Installation

npm install @partylayer/enterprise-node

Quick Start

import { PartyLayerNode } from '@partylayer/enterprise-node';
 
const pl = new PartyLayerNode({
  apiKey: 'sk_live_xxx', // Server-side API key
  baseUrl: 'https://api.partylayer.io/v1', // Optional
});

Resources

Users

// List users
const users = await pl.users.list({ page: 1, pageSize: 20 });
 
// Get user by ID
const user = await pl.users.get('usr_abc123');
 
// Create user
const newUser = await pl.users.create({
  email: 'alice@example.com',
  name: 'Alice',
  auth0Id: 'auth0|xxx',
});

Apps

// List apps
const apps = await pl.apps.list();
 
// Create app
const app = await pl.apps.create({
  name: 'My dApp',
  appUrl: 'https://mydapp.com',
  category: 'defi',
});
 
// Update app
await pl.apps.update('app_abc123', { name: 'Updated Name' });
 
// Delete app
await pl.apps.delete('app_abc123');

Wallets

// Get wallet for a user
const wallet = await pl.wallets.get('usr_abc123');
 
// Create wallet
const newWallet = await pl.wallets.create('usr_abc123');

Webhooks

// List webhooks
const webhooks = await pl.webhooks.list();
 
// Create webhook
const webhook = await pl.webhooks.create({
  url: 'https://myapp.com/webhooks/partylayer',
  events: ['user.created', 'tx.completed'],
});
 
// Delete webhook
await pl.webhooks.delete('wh_abc123');

API Keys

// List API keys
const keys = await pl.apiKeys.list();
 
// Create API key
const key = await pl.apiKeys.create({
  name: 'Production Key',
  environment: 'live',
  scopes: ['read', 'write'],
});
 
// Revoke API key
await pl.apiKeys.revoke('key_abc123');

Delegated Sessions

// Create delegated session for backend signing
const session = await pl.delegatedSessions.create({
  userId: 'usr_abc123',
  scopes: ['submit_transaction', 'query_contracts'],
  expiresInMinutes: 60,
});
 
// Execute transaction via delegated session
const result = await pl.delegatedSessions.execute(session.id, {
  templateId: 'pkg:Module:Template',
  choice: 'ClaimReward',
  args: { amount: '100' },
});

Webhook Verification

import { verifyWebhookSignature } from '@partylayer/enterprise-node';
 
// Express middleware example
app.post('/webhooks/partylayer', (req, res) => {
  const signature = req.headers['x-partylayer-signature'];
  const timestamp = req.headers['x-partylayer-timestamp'];
 
  const isValid = verifyWebhookSignature(
    req.body,
    signature,
    timestamp,
    process.env.WEBHOOK_SECRET,
  );
 
  if (!isValid) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
 
  const event = req.body;
  switch (event.type) {
    case 'user.created':
      // Handle new user
      break;
    case 'tx.completed':
      // Handle completed transaction
      break;
  }
 
  res.json({ received: true });
});

Error Handling

import { PartyLayerNode, ApiError } from '@partylayer/enterprise-node';
 
try {
  await pl.users.get('usr_nonexistent');
} catch (error) {
  if (error instanceof ApiError) {
    console.log(error.statusCode); // 404
    console.log(error.code);       // 'NOT_FOUND'
    console.log(error.message);    // 'User not found'
  }
}