Installation
Get started with Drift Protocol v2 by installing the SDK and setting up your Solana wallet for trading.Prerequisites
Before installing the Drift SDK, ensure you have:Solana CLI (Optional)
Install the SDK
Install the@drift-labs/sdk package in your project:
Current SDK version: 2.158.0-beta.0
Core Dependencies
The Drift SDK includes these key dependencies:@coral-xyz/anchor(0.29.0 & 0.30.1) - Solana program framework@solana/web3.js(1.98.0) - Solana JavaScript API@solana/spl-token(0.4.13) - SPL token operationsbn.js- BigNumber support for precise calculations
Set Up a Solana Wallet
You’ll need a Solana wallet to interact with Drift Protocol.Generate a New Keypair
Fund Your Wallet
- Devnet (Testing)
- Mainnet (Production)
For testing on devnet, use the Solana faucet:You can also get devnet USDC from Drift’s faucet after connecting your wallet.
Environment Variables
Create a.env file in your project root:
.env
Finding RPC Endpoints
Finding RPC Endpoints
You can use public RPC endpoints or premium providers for better performance:Public Endpoints:
- Devnet:
https://api.devnet.solana.com - Mainnet:
https://api.mainnet-beta.solana.com
Verify Installation
Create a simple test script to verify everything is set up correctly:test-setup.ts
You may need to install
ts-node or tsx for running TypeScript files:TypeScript Configuration
For TypeScript projects, ensure yourtsconfig.json includes:
tsconfig.json
Next Steps
Quick Start Guide
Place your first trade on Drift Protocol
API Reference
Explore the complete SDK documentation
Troubleshooting
Module not found errors
Module not found errors
Ensure all peer dependencies are installed:
Connection timeout errors
Connection timeout errors
- Check your internet connection
- Try a different RPC endpoint
- Consider using a premium RPC provider for better reliability
BigNum/BN errors
BigNum/BN errors
The SDK uses
bn.js for BigNumber operations. Import BN from the SDK:Node version errors
Node version errors
Drift SDK requires Node.js 24.0.0 or higher. Update Node.js:
Building from Source
If you want to contribute or build the SDK from source:For M1 Mac users, set the Rust toolchain first: