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

Getting Started with Phantom Server SDK

Please reach out to partnerships@phantom.com for access.

Installation

Install the Server SDK using your preferred package manager:
npm install @phantom/server-sdk
yarn add @phantom/server-sdk
pnpm add @phantom/server-sdk

Prerequisites

Please reach out to partnerships@phantom.com for access. Before using the SDK, you need:
  1. Phantom Organization Credentials
    • Organization ID
    • Organization Private Key (base58 encoded, P256 private key)
    • API Base URL
  2. Node.js version 16 or higher

Security First

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
  • Always use environment variables or secret management systems

Quick Start

1. Set up Environment Variables

Create a .env file in your project root:
PHANTOM_ORGANIZATION_ID=your-organization-id
PHANTOM_PRIVATE_KEY=your-base58-encoded-private-key
PHANTOM_API_URL=https://api.phantom.app/wallet

2. Initialize the SDK

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.PHANTOM_ORGANIZATION_ID!,
  apiPrivateKey: process.env.PHANTOM_PRIVATE_KEY!,
  apiBaseUrl: process.env.PHANTOM_API_URL!
});

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

Solana Networks

  • NetworkId.SOLANA_MAINNET - Solana Mainnet-Beta
  • NetworkId.SOLANA_DEVNET - Solana Devnet
  • NetworkId.SOLANA_TESTNET - Solana Testnet

Ethereum Networks

  • NetworkId.ETHEREUM_MAINNET - Ethereum Mainnet
  • NetworkId.ETHEREUM_GOERLI - Goerli Testnet
  • NetworkId.ETHEREUM_SEPOLIA - Sepolia Testnet

Other EVM Networks

  • NetworkId.POLYGON_MAINNET - Polygon Mainnet
  • NetworkId.POLYGON_MUMBAI - Mumbai Testnet
  • NetworkId.OPTIMISM_MAINNET - Optimism Mainnet
  • NetworkId.ARBITRUM_ONE - Arbitrum One
  • NetworkId.BASE_MAINNET - Base Mainnet

Future Support

  • NetworkId.BITCOIN_MAINNET - Bitcoin Mainnet
  • NetworkId.SUI_MAINNET - Sui Mainnet

Complete Example

Here’s a complete example demonstrating wallet creation and transaction signing:
import { ServerSDK, NetworkId } from '@phantom/server-sdk';
import { 
  Connection, 
  Transaction, 
  SystemProgram, 
  PublicKey,
  LAMPORTS_PER_SOL 
} from '@solana/web3.js';

async function main() {
  // Initialize SDK
  const sdk = new ServerSDK({
    organizationId: process.env.PHANTOM_ORG_ID!,
    apiPrivateKey: process.env.PHANTOM_PRIVATE_KEY!,
    apiBaseUrl: 'https://api.phantom.app/wallet'
  });

  // Create a wallet
  const wallet = await sdk.createWallet('Demo Wallet');
  const solanaAddress = wallet.addresses.find(
    a => a.addressType === 'Solana'
  )?.address!;

  console.log('Created wallet:', wallet.walletId);
  console.log('Solana address:', solanaAddress);

  // Connect to Solana
  const connection = new Connection('https://api.devnet.solana.com');
  
  // Create a transaction
  const transaction = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: new PublicKey(solanaAddress),
      toPubkey: new PublicKey(solanaAddress), // Self-transfer
      lamports: 0.001 * LAMPORTS_PER_SOL
    })
  );

  // Set transaction details
  const { blockhash } = await connection.getLatestBlockhash();
  transaction.recentBlockhash = blockhash;
  transaction.feePayer = new PublicKey(solanaAddress);


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

  console.log('Transaction signed:', signed.rawTransaction);
}

main().catch(console.error);

Next Steps

Troubleshooting

Common Issues

  1. “organizationId and apiBaseUrl are required”
    • Ensure all required config parameters are provided
    • Check for typos in parameter names
  2. “Failed to create wallet”
    • Verify your organization credentials are correct
    • Check network connectivity to the API endpoint
    • Ensure your organization has wallet creation permissions
  3. Transaction signing fails
    • 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
  4. “Unsupported network ID”
    • Use one of the predefined NetworkId enum values
    • Check that the network is supported for your operation

Getting Help

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.