This guide will walk you through the complete process of creating, signing, starting, and evaluating strategies using the Glider API.

1

Create a Strategy

Let’s create a basic strategy with a 70/30 asset weighting between UNI and LINK tokens. You’ll need to create a strategy by sending a POST request to the /strategies/create endpoint.

// Example strategy data - purely the execution schema
const strategyData = {
  children: {
    blockType: "weight",
    weightType: "specified-percentage",
    weightings: ["70", "30"],
    children: [
      {
        assetId: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", // UNI token address
        blockType: "asset",
      },
      {
        assetId: "0x514910771AF9Ca656af840dff83E8264EcF986CA", // LINK token address
        blockType: "asset",
      },
    ],
  },
};

// API request
const response = await fetch("https://api.glider.fi/strategies/create", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-KEY": "your_api_key_here",
  },
  body: JSON.stringify({
    name: "70/30 UNI-LINK Strategy",
    description: "A simple strategy with 70% UNI and 30% LINK token allocation",
    tags: ["beginner", "defi"],
    ownerAddress: "0xYourWalletAddressHere", // The wallet address that will own this strategy
    strategyData: strategyData,
    // tradingSettings is optional
    tradingSettings: { type: "threshold", triggerPercentage: 10 },
  }),
});

const strategy = await response.json();
console.log("Strategy created:", strategy.strategyId);

The response will include a strategyId which is the unique identifier for your strategy.

2

Sign the Strategy's Session Key

To authenticate ownership of the strategy and provide Glider access to manage the assets within the strategy, you need to sign a message with the owner’s wallet. First, get the message to sign.

// First, get the message to sign
const signDataResponse = await fetch(
  `https://api.glider.fi/strategies/sign-data/${strategy.strategyId}`,
  {
    method: "GET",
    headers: {
      "X-API-KEY": "your_api_key_here",
    },
  }
);

const signData = await signDataResponse.json();
const messageToSign = signData.message;

Sign the message with the owner’s wallet. Depending on your use case, you can sign the message directly with Viem or with wallet providers like Privy.

import { useWalletClient } from "wagmi";

// Create wallet client
const client = useWalletClient();

// Sign the message with the owner's wallet
const signature = await client.signMessage({
  message: messageToSign,
});

Once you have the signature, send it to the API:

// Send the signature to the API
const signResponse = await fetch("https://api.glider.fi/strategies/sign", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-KEY": "your_api_key_here",
  },
  body: JSON.stringify({
    strategyId: strategy.strategyId,
    signature: signature,
    signerAddress: account.address,
  }),
});

const signResult = await signResponse.json();
console.log("Strategy signed successfully:", signResult.success);
3

Fund the Strategy

Before starting the strategy, you need to fund it with some assets. Let’s deposit 0.2 ETH:

// Request deposit transaction data
// Note: This endpoint provides convenience for generating transaction calldata.
// You can also directly transfer tokens to the strategy vault address if you prefer
// to construct the transactions yourself. The endpoint simply creates a standard
// transfer() transaction to the vault address.
const depositDataResponse = await fetch(
  `https://api.glider.fi/strategies/${strategy.strategyId}/deposit-calldata`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": "your_api_key_here",
    },
    body: JSON.stringify({
      amount: "200000000000000000", // 0.2 ETH in wei
      tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // native ETH (can also use "native")
      senderAddress: account.address,
    }),
  }
);

const depositData = await depositDataResponse.json();

// Send the deposit transaction using Viem
const depositHash = await client.sendTransaction({
  to: depositData.tx.to,
  data: depositData.tx.data,
  value: BigInt(depositData.tx.value),
  gas: BigInt(depositData.tx.gasLimit),
  chainId: depositData.tx.chainId,
});

console.log(`Deposit transaction submitted with hash: ${depositHash}`);

// Wait for transaction to be confirmed
const depositReceipt = await client.waitForTransactionReceipt({
  hash: depositHash,
});

console.log(
  "Deposit transaction confirmed:",
  depositReceipt.status === "success"
);
4

Start the Strategy

Now that you’ve created, signed, and funded the strategy, you can start it to begin the automation:

const startResponse = await fetch("https://api.glider.fi/strategies/start", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-KEY": "your_api_key_here",
  },
  body: JSON.stringify({
    strategyId: strategy.strategyId,
    ownerAddress: account.address,
    rebalanceIntervalMs: 86400000, // Rebalance daily (in milliseconds)
  }),
});

const startResult = await startResponse.json();
console.log("Strategy started successfully:", startResult);
5

Check the Strategy Status

You can check the status of your strategy at any time:

const strategyResponse = await fetch(
  `https://api.glider.fi/strategies/${strategy.strategyId}`,
  {
    method: "GET",
    headers: {
      "X-API-KEY": "your_api_key_here",
    },
  }
);

const strategyStatus = await strategyResponse.json();
console.log("Current strategy status:", strategyStatus);