User Management

The SDK provides user management functionality to create and retrieve users associated with wallet addresses:

import { SpaceportSDK } from '@spaceport/sdk'

async function userManagementExamples() {
  // Initialize SDK with a wallet
  const account = privateKeyToAccount(`0x${process.env.YOUR_PRIVATE_KEY}`)
  const sdk = SpaceportSDK.createWithAccount(account, {
    chain: 'devnet',
    apiKey: process.env.SDK_API_KEY,
  })

  // Create a new user (wallet address is automatically included from SDK)
  const newUser = await sdk.users.create({
    email: '[email protected]',
    firstName: 'John',
    lastName: 'Doe',
  })
  console.log(`User created: ${newUser.userId}`)

  // Get the current user (based on the wallet address used to initialize the SDK)
  try {
    const currentUser = await sdk.users.getCurrentUser()
    console.log(`Current user: ${currentUser.email} (${currentUser.walletAddress})`)
  } catch (error) {
    console.log('No user found for current wallet address')
  }

  // Get a user by specific wallet address
  const walletAddress = '0x1234567890123456789012345678901234567890'
  try {
    const user = await sdk.users.getByWalletAddress(walletAddress)
    console.log(`User found: ${user.email}`)
    console.log(`Organization ID: ${user.organizationId}`)
    console.log(`Core login enabled: ${user.allowCoreLogin}`)
  } catch (error) {
    console.log(`No user found with wallet address: ${walletAddress}`)
  }
}

User Management Methods

  • users.create(params): Creates a new user with the wallet address from the SDK configuration
  • users.getCurrentUser(): Gets the user associated with the current SDK wallet address
  • users.getByWalletAddress(address): Gets a user by their specific wallet address