> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phantom.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating and managing wallets

> Learn how to create wallets, retrieve addresses, and manage wallet inventory with Phantom Server SDK

<Danger>
  The Server SDK is currently experimental and not ready for production use. Reach out to [partnerships@phantom.com](mailto:partnerships@phantom.com) for access.
</Danger>

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:

```typescript theme={null}
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:

```typescript theme={null}
// 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');
```

<Note>
  Always use descriptive wallet names that help you identify the wallet's purpose or owner. This makes wallet recovery and management much easier.
</Note>

### Understanding wallet addresses

When you create a wallet, it automatically generates addresses for multiple blockchains:

```typescript theme={null}
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

```typescript theme={null}
// 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

<Warning>
  Always persist the wallet ID immediately after creation. You cannot recover a wallet without its ID.
</Warning>

### Database integration example

```typescript theme={null}
// 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:

```typescript theme={null}
// 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:

```typescript theme={null}
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:

```typescript theme={null}
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:

```typescript theme={null}
// 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

* [Sign transactions with your wallets](/sdks/server-sdk/signing-transactions)
* [Sign messages for authentication](/sdks/server-sdk/signing-messages)

## 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.
