JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q54757F
  • License MIT

A comprehensive TypeScript SDK for interacting with GDEX API endpoints, providing REST API access, WebSocket real-time data, and crypto utilities. (Secure/Obfuscated)

Package Exports

  • gdex.pro-sdk
  • gdex.pro-sdk/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gdex.pro-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GDEX SDK

A comprehensive TypeScript SDK for interacting with GDEX API endpoints, providing REST API access, WebSocket real-time data, and crypto utilities for decentralized trading.

Key Features

  • 🚀 TypeScript Support: Full type safety and IntelliSense
  • 🌐 REST API Client: Complete access to all GDEX endpoints
  • 📡 WebSocket Client: Real-time data streaming
  • 🔧 Crypto Utilities: Address validation, formatting, and wallet operations
  • 📊 Trading Operations: Place orders, manage positions, market data
  • 📈 Copy Trading: Copy trade from top traders
  • 🏆 HyperLiquid Integration: Integrated with HyperLiquid futures
  • 🔌 Multi-network: Support for Ethereum, BSC, Solana, Sui, and more

Installation

npm install gdex-sdk

Quick Start

import { createSDK } from "gdex-sdk";

// Create SDK instance
const sdk = createSDK("https://trade-api.gemach.io/v1", {
  apiKey: "your-api-key", // Optional for public endpoints
  timeout: 10000,
});

// Get trending tokens
const trending = await sdk.tokens.getTrendingTokens(10);
console.log("Trending tokens:", trending);

Complete API Methods Reference

🪙 Token API (sdk.tokens)

Get Token Information

// Get paginated list of tokens
const tokens = await sdk.tokens.getTokens({
  page: 1,
  limit: 20,
  search: "USDC",
  sortBy: "marketCap",
  sortOrder: "desc",
});

// Get token details by address
const token = await sdk.tokens.getToken(
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a"
);

// Search tokens by name/symbol
const searchResults = await sdk.tokens.searchTokens("PEPE", 10);

// Get newest tokens
const newestTokens = await sdk.tokens.getNewestTokens(1, 1, "", 20);

// Get xstocks tokens
const xstocks = await sdk.tokens.getXstocks();

Price Data and Charts

// Get trending tokens
const trending = await sdk.tokens.getTrendingTokens(50);

// Get Pumpfun chart data
const chartData = await sdk.tokens.getChartTokenPumpfun(
  "DZZUrx7gN6cvNLWHi25ursiVFJob51exHEQujuzdpump",
  3600 // timeScale
);

// Get native prices for all chains
const nativePrices = await sdk.tokens.getNativePrices();

// Get token metadata (image, name, symbol)
const metadata = await sdk.tokens.getMetadataToken(
  1,
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a"
);

💹 Trading API (sdk.trading)

View Trades and History

// Get token trade history
const trades = await sdk.trading.getTrades(
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a",
  {
    page: 1,
    limit: 50,
  }
);

Buy/Sell Tokens (requires authentication)

// Buy tokens
const buyResult = await sdk.trading.buy(
  "0x1234...", // user address
  "1000000000000000000", // amount (in wei)
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a", // token address
  1, // chainId
  "your-private-key"
);

// Sell tokens
const sellResult = await sdk.trading.sell(
  "0x1234...", // user address
  "500000000000000000", // amount (in wei)
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a", // token address
  1, // chainId
  "your-private-key"
);

Limit Orders

// Get user's limit orders
const orders = await sdk.trading.getOrders(
  "0x1234...", // user address
  1, // chainId
  "encrypted-session-key"
);

// Create limit buy order
const limitBuy = await sdk.trading.createLimitBuy(
  "0x1234...", // user address
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a", // token address
  "1000000000000000000", // amount
  "0.001", // price
  1, // chainId
  "your-private-key"
);

// Create limit sell order
const limitSell = await sdk.trading.createLimitSell(
  "0x1234...", // user address
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a", // token address
  "500000000000000000", // amount
  "0.002", // price
  1, // chainId
  "your-private-key"
);

// Update order
const updateOrder = await sdk.trading.updateOrder(
  "0x1234...", // user address
  "order-id",
  "0.0015", // new price
  1, // chainId
  "your-private-key"
);

👤 User API (sdk.user)

Authentication and Login

// Login
const loginResult = await sdk.user.login(
  "0x1234...", // address
  12345, // nonce
  "session-key",
  "signature",
  "referral-code",
  1 // chainId
);

// Get user information
const userInfo = await sdk.user.getUserInfo(
  "0x1234...",
  "session-key",
  1 // chainId
);

Portfolio and Holdings

// Get holdings list
const holdings = await sdk.user.getHoldingsList(
  "0x1234...",
  "session-key",
  1 // chainId
);

Watchlist and Settings

// Add token to watchlist
const addToWatchlist = await sdk.user.addWatchList(
  "0x1234...", // user address
  "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a", // token address
  1, // chainId
  "your-private-key"
);

// Get watchlist
const watchlist = await sdk.user.getWatchList(
  "0x1234...",
  "session-key",
  1 // chainId
);

// Update user settings
const updateSettings = await sdk.user.saveUserSettings(
  "0x1234...", // user address
  "0.1", // quickBuyAmount
  true, // autoBuy
  1, // chainId
  "your-private-key"
);

🤖 Copy Trade API (sdk.copyTrade)

Manage Copy Trading

// Create new copy trade
const createCopyTrade = await sdk.copyTrade.createCopyTrade(
  "0x1234...", // your address
  "0x5678...", // target trader address
  "Top Trader #1", // name
  "20", // gas price
  1, // buy mode (1: fixed amount, 2: percentage)
  "0.1", // copy amount
  false, // buy existing tokens
  "-10", // loss percent
  "20", // profit percent
  true, // copy sell
  [1, 2], // excluded DEX numbers
  1, // chainId
  "your-private-key"
);

// Update copy trade
const updateCopyTrade = await sdk.copyTrade.updateCopyTrade(
  "0x1234...", // your address
  "copy-trade-id",
  "0x5678...", // target trader
  "Updated Name",
  "25", // new gas price
  2, // new buy mode
  "0.15", // new copy amount
  true, // buy existing tokens
  "-15", // new loss percent
  "25", // new profit percent
  true, // copy sell
  [1], // excluded DEXes
  false, // is delete
  false, // is change status
  1, // chainId
  "your-private-key"
);

// Get copy trade list
const copyTrades = await sdk.copyTrade.getCopyTradeList(
  "0x1234...",
  "session-key",
  1 // chainId
);

// Get top traders
const topTraders = await sdk.copyTrade.getTopTraders();

🏆 HyperLiquid API (sdk.hyperLiquid)

Futures Copy Trading

// Create HyperLiquid copy trade
const hlCreate = await sdk.hyperLiquid.hlCreate(
  "0x1234...", // your address
  "0x5678...", // trader wallet
  "HL Copy Trade #1", // name
  1, // copy mode (1: fixed, 2: proportion)
  "100", // amount per order
  "-10", // loss percent
  "20", // profit percent
  false, // opposite copy
  "your-private-key"
);

// Update HyperLiquid copy trade
const hlUpdate = await sdk.hyperLiquid.hlUpdate(
  "0x1234...", // your address
  "0x5678...", // trader wallet
  "Updated HL Copy", // new name
  2, // new copy mode
  "150", // new amount
  "-15", // new loss percent
  "25", // new profit percent
  "copy-trade-id",
  false, // opposite copy
  "your-private-key",
  false, // is delete
  false // is change status
);

// Get HyperLiquid leaderboard
const leaderboard = await sdk.hyperLiquid.getHLLeaderBoard();

// Get copy trade list
const hlCopyTrades = await sdk.hyperLiquid.getCopyTradeList(
  "0x1234...",
  "session-key"
);

HyperLiquid Trading Operations

// Deposit to HyperLiquid
const deposit = await sdk.hyperLiquid.hlDeposit(
  "0x1234...", // your address
  "1000", // amount
  "your-private-key"
);

// Withdraw from HyperLiquid
const withdraw = await sdk.hyperLiquid.hlWithdraw(
  "0x1234...", // your address
  "500", // amount
  "your-private-key"
);

// Place order for close position
const placeOrder = await sdk.hyperLiquid.hlPlaceOrder(
  "0x1234...", // your address
  "ETH", // coin
  true, // is buy
  "100", // size
  "2000", // price
  "your-private-key"
);

// Close all positions
const closeAll = await sdk.hyperLiquid.hlCloseAll(
  "0x1234...",
  "your-private-key"
);

🌐 WebSocket Client

Connect and Subscribe

// Connect WebSocket
await sdk.connectWebSocket();
const wsClient = sdk.getWebSocketClient();

// Subscribe to real-time data
if (wsClient) {
  wsClient.subscribe({ channel: "trades", symbol: "ETH/USDC" });
  wsClient.subscribe({ channel: "orderbook", symbol: "BTC/USDC" });

  // Listen for events
  wsClient.on("trade", (trade) => {
    console.log("New trade:", trade);
  });

  wsClient.on("orderbook", (orderbook) => {
    console.log("Order book update:", orderbook);
  });

  wsClient.on("connect", () => {
    console.log("WebSocket connected");
  });

  wsClient.on("disconnect", () => {
    console.log("WebSocket disconnected");
  });
}

// Check connection status
const isConnected = sdk.isWebSocketConnected();

// Disconnect
sdk.disconnect();

🔧 Crypto Utilities (sdk.crypto)

Wallet Address Operations

import { CryptoUtils } from "gdex-sdk";

// Validate address
const isValid = CryptoUtils.isValidAddress(
  "0x1234567890123456789012345678901234567890"
);

// Convert to checksum address
const checksum = CryptoUtils.toChecksumAddress(
  "0x1234567890123456789012345678901234567890"
);

// Shorten address
const shortened = CryptoUtils.shortenAddress(
  "0x1234567890123456789012345678901234567890"
);
// Result: "0x1234...7890"

Number and Currency Formatting

// Format token amount
const formatted = CryptoUtils.formatTokenAmount("1000000000000000000", 18);
// Result: "1.0"

// Format currency
const currency = CryptoUtils.formatCurrency(1234567.89);
// Result: "$1,234,567.89"

// Format percentage
const percentage = CryptoUtils.formatPercentage(25.5);
// Result: "25.50%"

// Format large numbers (K, M, B)
const large = CryptoUtils.formatLargeNumber(1234567);
// Result: "1.23M"

Wallet Operations

// Generate random wallet
const wallet = CryptoUtils.generateRandomWallet();
console.log(wallet.address); // wallet address
console.log(wallet.privateKey); // private key

// Create wallet from private key
const fromPrivateKey = CryptoUtils.createWalletFromPrivateKey("0x...");

// Sign message
const signature = CryptoUtils.sign("message-to-sign", "private-key");

// Verify signature
const isValidSig = CryptoUtils.verifySignature(
  "message",
  "signature",
  "address"
);

Configuration

import { GDEXSDK } from "gdex-sdk";

const sdk = new GDEXSDK("https://trade-api.gemach.io/v1", {
  apiKey: "your-api-key",
  timeout: 30000,
});

// Get configuration information
const config = sdk.getConfig();
console.log(config);
// {
//   baseURL: 'https://trade-api.gemach.io/v1',
//   hasApiKey: true,
//   hasWebSocket: true,
//   timeout: 30000
// }

Supported Networks

  • Ethereum (chainId: 1) - ETH
  • Base (chainId: 8453) - ETH
  • Binance Smart Chain (chainId: 56) - BNB
  • Solana (chainId: 622112261) - SOL
  • Sonic (chainId: 146) - S
  • Sui (chainId: 1313131213) - SUI
  • Nibiru (chainId: 6900) - NIBI
  • Berachain (chainId: 80094) - BERA
  • Optimism (chainId: 10) - ETH
  • Arbitrum (chainId: 42161) - ETH
  • Fraxtal (chainId: 252) - frxETH

Network-Specific Features

EVM Chains (Ethereum, Base, BSC, Sonic, Berachain, Optimism, Arbitrum, Fraxtal,Nibiru)

  • Full trading support (buy/sell/limit orders)
  • Copy trading not yet supported (coming soon)

Solana

  • Native Solana trading support
  • Pump.fun integration
  • ✅ Copy trading fully supported

Sui Network

  • Native Sui trading
  • Copy trading not yet supported (coming soon)

Error Handling

try {
  const token = await sdk.tokens.getToken("invalid-address");
} catch (error) {
  if (error.response?.status === 404) {
    console.log("Token not found");
  } else if (error.code === "NETWORK_ERROR") {
    console.log("Network issue");
  }
  console.error("Error:", error.message);
}

Complete Examples

Basic Example

import { createSDK } from "gdex-sdk";

async function basicExample() {
  const sdk = createSDK("https://trade-api.gemach.io/v1");

  // Get trending tokens
  const trending = await sdk.tokens.getTrendingTokens(10);
  console.log("Top 10 trending tokens:", trending);

  // Search for tokens
  const searchResults = await sdk.tokens.searchTokens("PEPE");
  console.log("PEPE tokens:", searchResults);

  // Get price history
  if (searchResults.length > 0) {
    const priceHistory = await sdk.tokens.getPriceHistory(
      searchResults[0].address,
      "1h",
      24
    );
    console.log("24h price history:", priceHistory);
  }
}

basicExample().catch(console.error);

Trading Example

import { createSDK } from "gdex-sdk";

async function tradingExample() {
  const sdk = createSDK("https://trade-api.gemach.io/v1", {
    apiKey: "your-api-key",
  });

  const userAddress = "0x1234...";
  const privateKey = "your-private-key";
  const tokenAddress = "0xa0b86a33e6776a721c4e3cef6e9e1a7ed6ae6c3a";

  try {
    // Buy tokens
    const buyResult = await sdk.trading.buy(
      userAddress,
      "100000000000000000", // 0.1 ETH
      tokenAddress,
      1, // Ethereum
      privateKey
    );

    if (buyResult?.isSuccess) {
      console.log("Buy successful:", buyResult.hash);
    } else {
      console.log("Buy failed:", buyResult?.message);
    }

    // Create limit sell order
    const limitSell = await sdk.trading.createLimitSell(
      userAddress,
      tokenAddress,
      "50000000000000000", // 0.05 ETH worth
      "0.002", // price
      1, // Ethereum
      privateKey
    );

    console.log("Limit sell order:", limitSell);
  } catch (error) {
    console.error("Trading error:", error);
  }
}

tradingExample().catch(console.error);

Copy Trading Example

import { createSDK } from "gdex-sdk";

async function copyTradingExample() {
  const sdk = createSDK("https://trade-api.gemach.io/v1", {
    apiKey: "your-api-key",
  });

  const userAddress = "0x1234...";
  const privateKey = "your-private-key";
  const traderAddress = "0x5678..."; // trader address to copy

  try {
    // Create copy trade
    const solCopyTrade = await sdk.copyTrade.createCopyTrade(
      userAddress,
      traderAddress,
      "Solana Top Trader Copy",
      "20", // gas price
      1, // fixed amount mode
      "1.0", // copy 1 SOL per trade
      false, // don't buy existing tokens
      "-10", // 10% stop loss
      "20", // 20% take profit
      true, // copy sell orders
      [], // no excluded DEXes
      622112261, // Solana chainId
      privateKey
    );

    if (solCopyTrade?.isSuccess) {
      console.log("Copy trade created successfully");
    } else {
      console.log("Copy trade failed:", solCopyTrade?.message);
    }

    // Get top traders to copy
    const topTraders = await sdk.copyTrade.getTopTraders();
    console.log("Top traders:", topTraders.slice(0, 5));
  } catch (error) {
    console.error("Copy trading error:", error);
  }
}

copyTradingExample().catch(console.error);

🌐 WebSocket Client

The GDEX SDK provides real-time WebSocket connections for all supported blockchain networks. The WebSocket streams live data including new tokens and token updates.

Real-time Data Types

  • newTokensData - Information about newly created tokens
  • effectedTokensData - Updates for existing tokens (price changes, volume, etc.)

Supported WebSocket Networks

Network Chain ID WebSocket URL
Ethereum 1 wss://trade-ws-1.gemach.io
Base 8453 wss://trade-ws-8453.gemach.io
BSC 56 wss://trade-ws-56.gemach.io
Solana 622112261 wss://trade-ws-622112261.gemach.io
Sonic 146 wss://trade-ws-146.gemach.io
Sui 1313131213 wss://trade-ws-1313131313.gemach.io
Nibiru 6900 wss://trade-ws-6900.gemach.io
Berachain 80094 wss://trade-ws-80094.gemach.io
Optimism 10 wss://trade-ws-10.gemach.io
Arbitrum 42161 wss://trade-ws-42161.gemach.io
Fraxtal 252 wss://trade-ws-252.gemach.io

Quick Start WebSocket Example

import { createSDK } from "gdex-sdk";

async function webSocketExample() {
  const sdk = createSDK("https://trade-api.gemach.io/v1", {
    apiKey: "your-api-key",
  });

  try {
    // Connect to Solana WebSocket
    console.log("🔗 Connecting to Solana WebSocket...");
    await sdk.connectWebSocketWithChain(622112261);

    const wsClient = sdk.getWebSocketClient();

    if (wsClient) {
      // Connection events
      wsClient.on("connect", (data) => {
        console.log("✅ WebSocket connected to chain:", data.chainId);
      });

      // Real-time data events
      wsClient.on("message", (data) => {
        // New tokens discovered
        if (data.newTokensData) {
          console.log("🆕 New tokens:", data.newTokensData);
          // Handle new token data
          data.newTokensData.forEach((token) => {
            console.log(`New token: ${token.symbol} (${token.address})`);
          });
        }

        // Existing token updates
        if (data.effectedTokensData) {
          console.log("📊 Token updates:", data.effectedTokensData);
          // Handle token updates
          data.effectedTokensData.forEach((update) => {
            console.log(`Updated: ${update.symbol} - Price: $${update.priceUsd}`);
          });
        }
      });

      // Error handling
      wsClient.on("error", (error) => {
        console.error("❌ WebSocket error:", error.message);
      });

      wsClient.on("disconnect", (data) => {
        console.log("⚠️ WebSocket disconnected:", data.reason);
      });
    }

    console.log("🎯 WebSocket is running. Press Ctrl+C to exit.");
  } catch (error) {
    console.error("❌ Failed to connect:", error);
    process.exit(1);
  }
}

webSocketExample().catch(console.error);

Examples in examples/ Directory

Check the examples/ directory for complete usage examples:

TypeScript Support

The SDK provides full TypeScript definitions:

import {
  GDEXSDK,
  Token,
  Trade,
  UserInfo,
  CopyTrade,
  HyperLiquidLeaderboard,
} from "gdex-sdk";

// All types have IntelliSense and type checking
const sdk = new GDEXSDK("https://trade-api.gemach.io/v1");
const tokens: Token[] = await sdk.tokens.getTrendingTokens(10);

License

MIT

Support

gdex-sdk