Skip to main content

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

Node.js

Node.js version 24.0.0 or higher
2

Package Manager

npm, yarn, or pnpm installed
3

Solana CLI (Optional)

For wallet generation and management
Install from Solana’s official docs if needed

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 operations
  • bn.js - BigNumber support for precise calculations
These are automatically installed with the SDK.

Set Up a Solana Wallet

You’ll need a Solana wallet to interact with Drift Protocol.

Generate a New Keypair

1

Generate keypair

This creates a new keypair at ~/.config/solana/id.json
2

Get your wallet address

Save this address - you’ll need it to fund your wallet
3

Add private key to environment

Never commit your .env file or share your private key! Add .env to your .gitignore file.

Fund Your Wallet

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
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
Premium Providers (Recommended for Production):Premium RPC providers offer higher rate limits and better reliability.

Verify Installation

Create a simple test script to verify everything is set up correctly:
test-setup.ts
Run the script:
You may need to install ts-node or tsx for running TypeScript files:

TypeScript Configuration

For TypeScript projects, ensure your tsconfig.json includes:
tsconfig.json

Next Steps

Quick Start Guide

Place your first trade on Drift Protocol

API Reference

Explore the complete SDK documentation

Troubleshooting

Ensure all peer dependencies are installed:
  • Check your internet connection
  • Try a different RPC endpoint
  • Consider using a premium RPC provider for better reliability
The SDK uses bn.js for BigNumber operations. Import BN from the SDK:
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: