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

# Get started with the Phantom Server SDK

> Learn how to use the Phantom Server SDK to create and manage wallets programmatically

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

## Critical security information

<Warning>
  The private key for your organization is meant to be stored *only on your server*, in a secure environment.

  * *Never* expose this key in client-side code.
  * *Never* commit it to version control.
  * Store it securely using environment variables or secret management systems.
</Warning>

## Installation

Install the Server SDK using your preferred package manager:

```bash theme={null}
npm install @phantom/server-sdk
```

```bash theme={null}
yarn add @phantom/server-sdk
```

```bash theme={null}
pnpm add @phantom/server-sdk
```

## Prerequisites

Before using the SDK, you need:

* Phantom organization credentials, provided when you create an organization with Phantom:
  * Organization ID
  * Organization private key (base58 encoded)
  * App ID
* Node.js version 16 or higher.

## Quick start

### Step 1: Set up environment variables

Create an `.env` file in your project root:

```env theme={null}
ORGANIZATION_ID=your-organization-id
PRIVATE_KEY=your-base58-encoded-private-key
APP_ID=your-app-id
```

### Step 2: Initialize the SDK

```typescript theme={null}
import { ServerSDK, NetworkId } from "@phantom/server-sdk";
import dotenv from "dotenv";

// Load environment variables
dotenv.config();

// Initialize the SDK
const sdk = new ServerSDK({
  organizationId: process.env.ORGANIZATION_ID!,
  apiPrivateKey: process.env.PRIVATE_KEY!,
  appId: process.env.APP_ID!,
});

// Create a wallet
const wallet = await sdk.createWallet("My First Wallet");
console.log("Wallet ID:", wallet.walletId);
console.log("Addresses:", wallet.addresses);

// Sign a message
const signature = await sdk.signMessage({
  walletId: wallet.walletId,
  message: "Hello, Phantom!",
  networkId: NetworkId.SOLANA_MAINNET,
});
console.log("Signature:", signature);
```

## Network support

The SDK supports multiple blockchain networks through the `NetworkId` enum:

| **Network** | **NetworkId**                | **Description**     |
| ----------- | ---------------------------- | ------------------- |
| Solana      | `NetworkId.SOLANA_MAINNET`   | Solana Mainnet-Beta |
|             | `NetworkId.SOLANA_DEVNET`    | Solana Devnet       |
|             | `NetworkId.SOLANA_TESTNET`   | Solana Testnet      |
| Ethereum    | `NetworkId.ETHEREUM_MAINNET` | Ethereum Mainnet    |
|             | `NetworkId.ETHEREUM_GOERLI`  | Goerli Testnet      |
|             | `NetworkId.ETHEREUM_SEPOLIA` | Sepolia Testnet     |
| Polygon     | `NetworkId.POLYGON_MAINNET`  | Polygon Mainnet     |
|             | `NetworkId.POLYGON_MUMBAI`   | Mumbai Testnet      |
| Optimism    | `NetworkId.OPTIMISM_MAINNET` | Optimism Mainnet    |
| Arbitrum    | `NetworkId.ARBITRUM_ONE`     | Arbitrum One        |
| Base        | `NetworkId.BASE_MAINNET`     | Base Mainnet        |
| Bitcoin     | `NetworkId.BITCOIN_MAINNET`  | Bitcoin Mainnet     |
| Sui         | `NetworkId.SUI_MAINNET`      | Sui Mainnet         |

## Usage examples

### Creating a wallet

```typescript theme={null}
import { ServerSDK, NetworkId } from '@phantom/server-sdk';
// Initialize SDK
const sdk = new ServerSDK({
  organizationId: process.env.ORGANIZATION_ID!,
  apiPrivateKey: process.env.PRIVATE_KEY!,
  appId: process.env.APP_ID!,
});

// Create a wallet with a custom name
const wallet = await sdk.createWallet("User Wallet 123");

// Access addresses for different chains
const solanaAddress = wallet.addresses.find(addr => addr.addressType === "Solana")?.address;

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

console.log("Solana address:", solanaAddress);
console.log("Ethereum address:", ethereumAddress);
```

### Signing and sending transactions

#### Solana-native Web3.js transaction objects

```typescript theme={null}
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";

// Create a Solana transaction
const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: new PublicKey(solanaAddress),
    toPubkey: new PublicKey(recipientAddress),
    lamports: 1000000, // 0.001 SOL
  }),
);

// Set transaction parameters
transaction.recentBlockhash = blockhash;
transaction.feePayer = new PublicKey(solanaAddress);

// Sign and send the transaction
const signedTx = await sdk.signAndSendTransaction({
  walletId: wallet.walletId,
  transaction,
  networkId: NetworkId.SOLANA_MAINNET,
});

console.log("Signed transaction:", signedTx.rawTransaction);
```

#### Ethereum/EVM-transaction objects

```typescript theme={null}
// Viem transaction object
const evmTransaction = {
  to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
  value: 1000000000000000000n, // 1 ETH in wei
  data: "0x",
  gasLimit: 21000n,
};

const signedEvmTx = await sdk.signAndSendTransaction({
  walletId: wallet.walletId,
  transaction: evmTransaction, // Native EVM transaction object
  networkId: NetworkId.ETHEREUM_MAINNET,
});

// Ethers.js transactions also supported
const ethersTransaction = {
  to: recipientAddress,
  value: ethers.parseEther("0.01"),
  serialize: () => "0x...", // Ethers serialization method
};

await sdk.signAndSendTransaction({
  walletId: wallet.walletId,
  transaction: ethersTransaction,
  networkId: NetworkId.ETHEREUM_MAINNET,
});
```

#### Raw formats-hex strings and bytes

```typescript theme={null}
// Hex string transaction
await sdk.signAndSendTransaction({
  walletId: wallet.walletId,
  transaction: "0x02f8710182013685012a05f2008301388094742d35cc...", // Raw hex
  networkId: NetworkId.ETHEREUM_MAINNET,
});

// Raw bytes
const transactionBytes = new Uint8Array([1, 2, 3, 4, 5 /* ... */]);
await sdk.signAndSendTransaction({
  walletId: wallet.walletId,
  transaction: transactionBytes,
  networkId: NetworkId.SOLANA_MAINNET,
});
```

### Signing messages

```typescript theme={null}
const solanaSignature = await sdk.signMessage({
  walletId: wallet.walletId,
  message: "Please sign this message to authenticate",
  networkId: NetworkId.SOLANA_MAINNET,
});

// Unicode messages work too
const unicodeSignature = await sdk.signMessage({
  walletId: wallet.walletId,
  message: "Welcome to Web3! 你好世界", // Unicode text
  networkId: NetworkId.SOLANA_MAINNET,
});

const ethSignature = await sdk.signMessage({
  walletId: wallet.walletId,
  message: "Sign in to our dApp",
  networkId: NetworkId.ETHEREUM_MAINNET,
});
```

### Managing wallets

```typescript theme={null}
// Get all wallets for your organization with pagination
const result = await sdk.getWallets(20, 0); // limit: 20, offset: 0

console.log(`Total wallets: ${result.totalCount}`);
console.log("Wallets:", result.wallets);

// Get addresses for a specific wallet
const addresses = await sdk.getWalletAddresses(walletId);

// Get specific addresses by derivation path
const customAddresses = await sdk.getWalletAddresses(
  walletId,
  ["m/44'/501'/0'/0'", "m/44'/60'/0'/0/0"], // Solana and Ethereum
);
```

## Next steps

* [Create and manage wallets](/sdks/server-sdk/creating-wallets)
* [Sign and send transactions](/sdks/server-sdk/signing-transactions)
* [Sign messages for authentication](/sdks/server-sdk/signing-messages)
* [Explore the complete API reference](/sdks/server-sdk/api-reference)

## Troubleshooting

### "organizationId and appId are required" error

Solutions:

* Ensure all required config parameters are provided.
* Check for typos in parameter names.

### "Failed to create wallet" error

Solutions:

* Verify your organization credentials are correct.
* Check network connectivity to the API endpoint.
* Ensure your organization has wallet creation permissions.

### Transaction signing fails

Solutions:

* Verify the wallet ID exists and belongs to your organization.
* Check that the transaction is properly formatted.
* Ensure you're using the correct network ID.

### "Unsupported network ID" error

Solutions:

* Use one of the predefined `NetworkId` enum values.
* Check that the network is supported for your operation.

## Need help?

<CardGroup cols={2}>
  <Card title="Support" icon="life-ring" href="https://docs.google.com/forms/d/e/1FAIpQLSeHWETFkEJbHQCF-lnl1AHmVQPuyfC0HbnxjDjIp6VYV1sBZQ/viewform">
    Get help from developer support team
  </Card>

  <Card title="Example apps" icon="code" href="https://github.com/phantom/phantom-connect-sdk/tree/main/examples/server-sdk-examples">
    Review the example apps
  </Card>
</CardGroup>

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