The Server SDK is currently experimental and not ready for production use.

Creating and Managing Wallets

This guide covers wallet creation, address management, and inventory operations using the Phantom Server SDK.

Creating Wallets

Basic Wallet Creation

The simplest way to create a wallet is with the createWallet method:
const wallet = await sdk.createWallet();

console.log('Wallet ID:', wallet.walletId);
console.log('Addresses:', wallet.addresses);

Named Wallets

Use meaningful names to organize and identify wallets:
// Use a naming convention for easier management
const wallet = await sdk.createWallet('user_123456');
// or
const wallet = await sdk.createWallet(`customer_${customerId}_${timestamp}`);
// or
const wallet = await sdk.createWallet('treasury_wallet_2024');
Best Practice: Always use descriptive wallet names that help you identify the wallet’s purpose or owner. This makes wallet recovery and management much easier.

Understanding Wallet Addresses

When you create a wallet, it automatically generates addresses for multiple blockchains:
const wallet = await sdk.createWallet('Multi-chain Wallet');

// The addresses array contains addresses for different chains
wallet.addresses.forEach(addr => {
  console.log(`${addr.addressType}: ${addr.address}`);
});

// Example output:
// Solana: 5XYz...ABC
// Ethereum: 0x123...def
// Polygon: 0x456...ghi

Extracting Specific Addresses

// Find specific blockchain addresses
const solanaAddress = wallet.addresses.find(
  addr => addr.addressType === 'Solana'
)?.address;

const ethereumAddress = wallet.addresses.find(
  addr => addr.addressType === 'Ethereum'
)?.address;

const polygonAddress = wallet.addresses.find(
  addr => addr.addressType === 'Polygon'
)?.address;

Storing Wallet Information

Critical: Always persist the wallet ID immediately after creation. You cannot recover a wallet without its ID.

Database Integration Example

// Example using Prisma
async function createWalletForUser(userId: string) {
  try {
    // Create wallet with meaningful name
    const walletName = `user_${userId}`;
    const phantomWallet = await sdk.createWallet(walletName);
    
    // Extract the Solana address
    const solanaAddress = phantomWallet.addresses.find(
      addr => addr.addressType === 'Solana'
    )?.address!;
    
    // Immediately save to database
    const dbWallet = await prisma.wallet.create({
      data: {
        userId,
        walletId: phantomWallet.walletId, // Critical!
        walletName,
        solanaAddress,
        ethereumAddress: phantomWallet.addresses.find(
          addr => addr.addressType === 'Ethereum'
        )?.address,
        createdAt: new Date()
      }
    });
    
    return dbWallet;
  } catch (error) {
    console.error('Failed to create wallet:', error);
    throw error;
  }
}

Retrieving Wallet Addresses

Get addresses for an existing wallet using its ID:
// Get all addresses for a wallet
const addresses = await sdk.getWalletAddresses(walletId);

addresses.forEach(addr => {
  console.log(`${addr.addressType}: ${addr.address}`);
});

Listing Wallets

Basic Wallet Listing

Get all wallets in your organization:
const result = await sdk.getWallets();

console.log(`Total wallets: ${result.totalCount}`);
console.log(`Retrieved: ${result.wallets.length}`);

result.wallets.forEach(wallet => {
  console.log(`${wallet.walletName} (${wallet.walletId})`);
});

Pagination

Handle large numbers of wallets with pagination:
async function getAllWallets() {
  const wallets = [];
  let offset = 0;
  const limit = 50;
  
  while (true) {
    const result = await sdk.getWallets(limit, offset);
    wallets.push(...result.wallets);
    
    // Check if we've retrieved all wallets
    if (offset + result.wallets.length >= result.totalCount) {
      break;
    }
    
    offset += limit;
  }
  
  return wallets;
}

Filtering and Searching

The SDK returns wallet metadata. You can implement filtering in your application:
// Get wallets and filter by name pattern
async function findWalletsByPattern(pattern: string) {
  const allWallets = await getAllWallets();
  
  return allWallets.filter(wallet => 
    wallet.walletName?.includes(pattern)
  );
}

// Find wallets created in a date range
async function getWalletsCreatedBetween(startDate: Date, endDate: Date) {
  const allWallets = await getAllWallets();
  
  return allWallets.filter(wallet => {
    const createdAt = new Date(wallet.createdAt);
    return createdAt >= startDate && createdAt <= endDate;
  });
}

Next Steps

Disclaimers

The Server SDK is a beta version, and Phantom will not be liable for any losses or damages suffered by you or your end users. Any suggestions, enhancement requests, recommendations, or other feedback provided by you regarding the Server SDK will be the exclusive property of Phantom. By using this beta version and providing feedback, you agree to assign any rights in that feedback to Phantom.