Examples here are written using bun
1.1.9. If you are using node
, the recommended version is v20.18.0. And use @drift-labs/sdk
.
If you are using the drift sdk in browser environment, it's recommended to use @drift-labs/sdk-browser
instead.
Install NVM if you haven't already:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash`
Install compatible Node version:
nvm install 20.18.0`
nvm use`
Verify the installation:
node --version
bun install
All examples require the following environment variables:
PRIVATE_KEY
: The private key of the account to use, can be:- numbers array (from
solana-keygen new
) - base58 encoded private key (phantom exported private key)
- a file to any of the above.
To generate a compatible private key file, run the
0_generate_private_key.ts
script:This will create abun run examples/0_generate_private_key.ts
private-key.json
file in the root of this project (e.g.,sdk-examples/private-key.json
). You should then set yourPRIVATE_KEY
environment variable to this path, for example, in your.env
file:PRIVATE_KEY=./private-key.json
- numbers array (from
RPC_URL
: The RPC URL of the network to use for the example, you need a proper one
Each file under examples/
is an example, start with:
bun run example/1_init_user.ts