Skip to main content

Default Initialization

Initialize GlamClient by setting the ANCHOR_PROVIDER_URL and ANCHOR_WALLET environment variables:
import { GlamClient, ClusterNetwork } from '@glamsystems/glam-sdk';

const glamClient = new GlamClient();

Keypair Wallet

Alternatively, initialize GlamClient with an RPC URL and wallet keypair:
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";
import { GlamClient, ClusterNetwork } from "@glamsystems/glam-sdk";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const keypairPath = "/path/to/wallet/keypair.json";

const loadWallet = (path: string) => {
  let keypair = Keypair.fromSecretKey(
    Buffer.from(
      JSON.parse(require("fs").readFileSync(path, { encoding: "utf-8" })),
    ),
  );
  return new NodeWallet(keypair);
};

const glamClient = new GlamClient({
  provider: new AnchorProvider(connection, loadWallet(keypairPath)),
  cluster: ClusterNetwork.Mainnet,
});

Custom Wallet Implementation

Any custom wallet that implements the Wallet interface can be used with GlamClient.

Read-Only Wallet

A read-only wallet allows querying vault data without signing transactions:
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
import { Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
import { GlamClient, ClusterNetwork } from "@glamsystems/glam-sdk";

class ReadOnlyWallet implements Wallet {
  constructor(readonly pubkey: PublicKey) {}
  signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T> {
    throw new Error("Method not implemented.");
  }
  signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]> {
    throw new Error("Method not implemented.");
  }
  get publicKey(): PublicKey {
    return this.pubkey;
  }
}

const connection = new Connection("https://api.mainnet-beta.solana.com");
const wallet = new ReadOnlyWallet(new PublicKey("<ReadOnlyWalletPubkey>"));

const glamClient = new GlamClient({
  provider: new AnchorProvider(connection, wallet),
  cluster: ClusterNetwork.Mainnet,
  statePda: new PublicKey("<GlamStatePda>"),
});