Tutorials & SDKs

JavaScript Integration

Use Hive from browsers, serverless functions, and Node.js with fetch. This guide covers bearer authentication, REST execution, tool discovery, reusable client code, and TypeScript shapes for apps that need live crypto market, wallet, DeFi, and security data.


Quick Start

const baseUrl = "https://mcp.hiveintelligence.xyz";
const apiKey = process.env.HIVE_API_KEY;

async function execute(tool, args = {}) {
  const response = await fetch(`${baseUrl}/api/v1/execute`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${apiKey}`,
    },
    body: JSON.stringify({ tool, args }),
  });

  if (!response.ok) {
    throw new Error(`Hive request failed: ${response.status} ${await response.text()}`);
  }

  return response.json();
}

const price = await execute("get_price", {
  ids: "bitcoin",
  vs_currencies: "usd",
});

console.log(price.bitcoin.usd);

Reusable Client

class HiveClient {
  constructor({
    apiKey,
    baseUrl = "https://mcp.hiveintelligence.xyz",
  }) {
    this.apiKey = apiKey;
    this.baseUrl = baseUrl;
  }

  async execute(tool, args = {}) {
    const response = await fetch(`${this.baseUrl}/api/v1/execute`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${this.apiKey}`,
      },
      body: JSON.stringify({ tool, args }),
    });

    if (!response.ok) {
      throw new Error(`Hive request failed: ${response.status} ${await response.text()}`);
    }

    return response.json();
  }

  async listTools(limit = 50) {
    const response = await fetch(`${this.baseUrl}/api/v1/tools?limit=${limit}`, {
      headers: { Authorization: `Bearer ${this.apiKey}` },
    });

    if (!response.ok) {
      throw new Error(`Tool discovery failed: ${response.status}`);
    }

    return response.json();
  }
}

const client = new HiveClient({ apiKey: process.env.HIVE_API_KEY });

const market = await client.execute("get_coins_market_data", {
  vs_currency: "usd",
  order: "market_cap_desc",
  per_page: 5,
});

const wallet = await client.execute("moralis_get_wallet_net_worth", {
  address: "0x1234...",
  chain: "eth",
});

TypeScript Shape

type ExecuteArgs = Record<string, unknown>;

interface HiveClientOptions {
  apiKey: string;
  baseUrl?: string;
}

class HiveClient {
  constructor(private options: HiveClientOptions) {}

  async execute<T>(tool: string, args: ExecuteArgs = {}): Promise<T> {
    const response = await fetch(`${this.options.baseUrl ?? "https://mcp.hiveintelligence.xyz"}/api/v1/execute`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${this.options.apiKey}`,
      },
      body: JSON.stringify({ tool, args }),
    });

    if (!response.ok) {
      throw new Error(`Hive request failed: ${response.status}`);
    }

    return response.json() as Promise<T>;
  }
}

type PriceResponse = {
  bitcoin?: { usd?: number };
};

Common Patterns

Market monitoring

const gainers = await client.execute("get_gainers_losers", {
  vs_currency: "usd",
  duration: "24h",
});

Wallet analysis

const balances = await client.execute("get_wallet_balances", {
  network: "eth",
  address: "0x1234...",
});

DeFi monitoring

const pools = await client.execute("get_yield_pools", {
  chain: "ethereum",
});

Prediction markets

const markets = await client.execute("codex_prediction_markets", {
  networkId: 1,
});

Production usage

Keep the Hive API key server-side for browser-facing apps. Browser code should call your own backend or serverless route, then that route should call Hive with Authorization: Bearer YOUR_HIVE_API_KEY. Add short TTL caching for prices, protocol metadata, and discovery responses so user traffic does not burn unnecessary credits.


Notes

  • The current REST payload keys are tool and args.
  • Use GET /api/v1/tools or Live Catalog when choosing tool names.
  • Prefer the MCP endpoint if your runtime already supports tool discovery natively.

Previous
SDK Overview