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.
The Server SDK is currently experimental and not ready for production use. Reach out to partnerships@phantom.com for access.
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.
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
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:
ORGANIZATION_ID=your-organization-id
PRIVATE_KEY=your-base58-encoded-private-key
APP_ID=your-app-id
Step 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 . 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_MAINNETSolana Mainnet-Beta NetworkId.SOLANA_DEVNETSolana Devnet NetworkId.SOLANA_TESTNETSolana Testnet Ethereum NetworkId.ETHEREUM_MAINNETEthereum Mainnet NetworkId.ETHEREUM_GOERLIGoerli Testnet NetworkId.ETHEREUM_SEPOLIASepolia Testnet Polygon NetworkId.POLYGON_MAINNETPolygon Mainnet NetworkId.POLYGON_MUMBAIMumbai Testnet Optimism NetworkId.OPTIMISM_MAINNETOptimism Mainnet Arbitrum NetworkId.ARBITRUM_ONEArbitrum One Base NetworkId.BASE_MAINNETBase Mainnet Bitcoin NetworkId.BITCOIN_MAINNETBitcoin Mainnet Sui NetworkId.SUI_MAINNETSui Mainnet
Usage examples
Creating a wallet
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
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
// Viem transaction object
const evmTransaction = {
to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E" ,
value: 1000000000000000000 n , // 1 ETH in wei
data: "0x" ,
gasLimit: 21000 n ,
};
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 ,
});
// 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
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
// 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
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?
Support Get help from developer support team
Example apps Review the example apps
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.