17min

SDK Documentation

Drift Protocol is an open sourced project:

Setting Up

For any help/setup questions, feel free to ask in #dev-chat on Discord!

Prerequsites

Requires Anchor and Solana's web3.js library to be installed.

npm install @drift-labs/sdk

Program IDs

Anchor automatically generates IDLs based on a Program ID.

Endpoint

Program ID

Devnet

AsW7LnXB9UA1uec9wi9MctYTgTz7YH9snhxd16GsFaGX

Mainnet-beta

dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN



To receive devnet usdc for (https://master.drift.trade)

Initialize a Clearinghouse Object

This Clearinghouse client object wraps around the core Rust program. All the trading functions will call from the Clearinghouse class.

TypeScript
|

From here, all program calls will be made through the Clearinghouse Object.

Create a User Account

User accounts need to be initialized on the clearinghouse before being able to interact with the Clearinghouse program. User account connects the trader's wallet and the on-chain market. Funds are escrowed within the user account.

TypeScript
|

Deposit

TypeScript
|

Withdrawal

TypeScript
|



Fetching Data

Public Market Data

Market Indices

To refer to each market, the SDK refers to market indices based on the following table. (Note that this is subject to change and update as new markets are deployed) see https://github.com/drift-labs/protocol-v1/blob/master/sdk/src/constants/markets.ts

Market Index

Market

Oracle Key

0

SOL

H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG

1

BTC



2

ETH



3

LUNA



4

AVAX



5

BNB



...

...



64

...



Get Mark Price

The following function returns the mark price given a market index.

TypeScript
|



Updated 23 Mar 2022
Did this page help you?
Yes
No