Skip to main content

Environment Setup

This document covers the essential setup required to start building on Orca's SDK using the Whirlpools protocol. It includes installation, wallet setup, RPC client configuration, and the basics of interacting with the Solana ecosystem.

Prerequisites

Before you start, ensure you have Rust installed. To ensure compatibility with the Solana SDK v1.18, we recommend using rustc 1.78.0.

1. Initialize a new project

Initialize a new Rust project:

cargo new <project-name>

Add the necessary dependencies to your project:

cargo add orca_whirlpools solana-sdk solana-client tokio serde_json

Note: If you're using the Rust SDK in an already existing project which does not use the latest version of Solana SDK, you may need to apply a patchfile lock with the following command:

cargo update solana-sdk:<current-version> --precise <required-version>

You might also have to apply lockfile patches for solana-program, solana-client, solana-account-decoder, spl-token, spl-memo, spl-token-2022, spl-associated-token-account.

2. Wallet Management

You can generate a file system wallet using the Solana CLI and load it in your program.

use solana_sdk::signer::keypair::Keypair;
use solana_sdk::signature::Signer;
use std::fs;

fn main() {
let wallet_string = fs::read_to_string("path/to/wallet.json").unwrap();
let keypair_bytes: Vec<u8> = serde_json::from_str(&wallet_string).unwrap();
let wallet = Keypair::from_bytes(&keypair_bytes).unwrap();
}

⚠️ Important: Never share your private key publicly.

3. Configure the Whirlpools SDK for Your Network

Orca's Whirlpools SDK supports several networks: Solana Mainnet, Solana Devnet, Eclipse Mainnet, and Eclipse Testnet. To select a network, use the setWhirlpoolsConfig function.

use orca_whirlpools::{WhirlpoolsConfigInput, set_whirlpools_config_address};

fn main() {
set_whirlpools_config_address(WhirlpoolsConfigInput::SolanaDevnet).unwrap();
// Rest of the code
}

Available networks are:

  • solanaMainnet
  • solanaDevnet
  • eclipseMainnet
  • eclipseTestnet

ℹ️ The set_whirlpools_config_address function accepts either one of Orca's default network keys or a custom address. This allows you to specify a WhirlpoolsConfig account of your choice, including configurations not owned by Orca.

4. Airdrop SOL to Your Wallet

Once your wallet is created, you will need some SOL to pay for transactions. You can request an airdrop of SOL from the network, but this is only available on Solana Devnet and Ecipse Testnet.

use solana_client::rpc_client::RpcClient;
use solana_sdk::signature::Signer;

fn main() {
// Rest of the code
let rpc_client = RpcClient::new("https://api.devnet.solana.com");
match rpc_client.request_airdrop(&wallet.pubkey(), 1_000_000_000) {
Ok(signature) => println!("Airdrop successful. Transactoin signature: {:?}", signature),
Err(e) => println!("Error: {:?}", e),
}
}

5. Set the default funder for Transactions

After funding your wallet, you can set the wallet as the FUNDER for future transactions within the SDK. The funder is the account that will cover the transaction costs for initializing pools, providing liquidity, etc.

use orca_whirlpools::{set_funder};
use solana_sdk::signature::Signer;

fn main() {
// Rest of the code
set_funder(wallet.pubkey()).unwrap();
}

Next steps

Once you've completed the setup, you can move on to building more complex functionalities using the Orca SDK, such as creating and managing pools, providing liquidity, etc. Refer to individual function documentation to use this wallet setup in action.