Skip to main content

Quickstart

This guide will walk you through creating a GLAM vault and performing your first deposit using the SDK.

Prerequisites

Before you begin, make sure you have:
  • Completed the installation steps
  • A Solana wallet with some SOL for transaction fees
  • Access to a Solana RPC endpoint

Initialize the client

The GlamClient is the main entry point for the SDK. You can initialize it with default settings or provide custom configuration.

Basic initialization

By default, GlamClient uses environment variables for configuration:
import { GlamClient } from '@glamsystems/glam-sdk';

// Uses ANCHOR_PROVIDER_URL and ANCHOR_WALLET from environment
const glamClient = new GlamClient();

Custom configuration

You can also provide a custom configuration:
import { GlamClient, ClusterNetwork } from '@glamsystems/glam-sdk';
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
import { Connection, Keypair } from '@solana/web3.js';
import fs from 'fs';

// Load your wallet
const keypair = Keypair.fromSecretKey(
  new Uint8Array(JSON.parse(fs.readFileSync('/path/to/keypair.json', 'utf-8')))
);
const wallet = new Wallet(keypair);

// Create provider
const connection = new Connection('https://api.devnet.solana.com');
const provider = new AnchorProvider(connection, wallet);

// Initialize client with custom config
const glamClient = new GlamClient({
  provider,
  cluster: ClusterNetwork.Devnet
});

Create a vault

Now let’s create your first GLAM vault:
1

Import required utilities

import { 
  GlamClient, 
  stringToChars, 
  StateAccountType,
  WSOL 
} from '@glamsystems/glam-sdk';
import { PublicKey } from '@solana/web3.js';
2

Initialize the vault

const glamClient = new GlamClient();

// Transaction options
const txOptions = {
  maxFeeLamports: 10_000,
  useMaxFee: true,
  simulate: true,
};

// Create the vault
const txSig = await glamClient.state.initialize(
  {
    name: stringToChars("My First Vault"),
    enabled: true,
    accountType: StateAccountType.VAULT,
    baseAssetMint: WSOL, // Use wrapped SOL as base asset
  },
  txOptions
);

console.log('Transaction signature:', txSig);
console.log('Vault address:', glamClient.vaultPda.toBase58());
console.log('Vault state:', glamClient.statePda.toBase58());
3

Understanding the result

After creating the vault, you’ll receive:
  • Transaction signature - Confirming the vault creation
  • Vault address (vaultPda) - The main vault account
  • Vault state (statePda) - The state/configuration account
Save these addresses as you’ll need them for future operations.
The stringToChars utility converts your vault name to the format expected by the protocol. Vault names are stored as fixed-length character arrays on-chain.

Deposit SOL

Once you have a vault, you can deposit SOL into it:
import { BN } from '@coral-xyz/anchor';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';

// Deposit 1 SOL
const amount = new BN(1 * LAMPORTS_PER_SOL);
const txSig = await glamClient.vault.depositSol(
  amount,
  true, // wrap SOL to WSOL
  txOptions
);

console.log('Deposit successful:', txSig);

Deposit SPL tokens

You can also deposit any SPL token:
import { fetchMintAndTokenProgram } from '@glamsystems/glam-sdk';

const tokenMint = new PublicKey('YOUR_TOKEN_MINT_ADDRESS');

// Fetch token metadata to get decimals
const { mint } = await fetchMintAndTokenProgram(
  glamClient.provider.connection,
  tokenMint
);

// Deposit 10 tokens (accounting for decimals)
const amount = new BN(10 * 10 ** mint.decimals);
const txSig = await glamClient.vault.deposit(
  tokenMint,
  amount,
  txOptions
);

console.log('Token deposit successful:', txSig);

Working with existing vaults

If you want to interact with a vault you created previously, you need to set the state PDA:
import { PublicKey } from '@solana/web3.js';

const glamClient = new GlamClient();

// Set the state PDA for an existing vault
const vaultStatePda = new PublicKey('YOUR_VAULT_STATE_ADDRESS');
glamClient.statePda = vaultStatePda;

// Now you can perform operations on this vault
const amount = new BN(1 * LAMPORTS_PER_SOL);
await glamClient.vault.depositSol(amount, true, txOptions);
You need to discover the vault state PDA from the vault address. See the examples for a helper function that does this.

Complete example

Here’s a complete working example that creates a vault and deposits SOL:
example.ts
import { 
  GlamClient, 
  stringToChars, 
  StateAccountType,
  WSOL 
} from '@glamsystems/glam-sdk';
import { BN } from '@coral-xyz/anchor';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';

async function main() {
  // Initialize client
  const glamClient = new GlamClient();
  
  // Transaction options
  const txOptions = {
    maxFeeLamports: 10_000,
    useMaxFee: true,
    simulate: false, // Set to false for actual transactions
  };
  
  try {
    // Create vault
    console.log('Creating vault...');
    const createTxSig = await glamClient.state.initialize(
      {
        name: stringToChars("My Trading Vault"),
        enabled: true,
        accountType: StateAccountType.VAULT,
        baseAssetMint: WSOL,
      },
      txOptions
    );
    
    console.log('✅ Vault created!');
    console.log('Transaction:', createTxSig);
    console.log('Vault:', glamClient.vaultPda.toBase58());
    console.log('State:', glamClient.statePda.toBase58());
    
    // Deposit SOL
    console.log('\nDepositing SOL...');
    const depositAmount = new BN(0.1 * LAMPORTS_PER_SOL);
    const depositTxSig = await glamClient.vault.depositSol(
      depositAmount,
      true,
      txOptions
    );
    
    console.log('✅ Deposit successful!');
    console.log('Transaction:', depositTxSig);
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

Transaction options

The TxOptions object allows you to configure transaction behavior:
  • maxFeeLamports - Maximum priority fee in lamports
  • useMaxFee - Whether to use the max fee
  • simulate - Simulate the transaction without sending (useful for testing)
  • signer - Custom signer (defaults to wallet from config)

Next steps

Now that you’ve created a vault and made deposits, you can explore:

Access control

Enable protocol integrations and set transfer policies

DeFi integrations

Swap on Jupiter, trade on Drift, lend on Kamino

Staking

Stake SOL or use liquid staking with Marinade

Examples

View complete example applications

Build docs developers (and LLMs) love