Hive Intelligence

SDKs

JavaScript Integration

JavaScript Integration

Access Hive Intelligence using the native Fetch API.


Quick Start

No installation required - works in browsers and Node.js 18+.

const API_URL = "https://api.hiveintelligence.xyz/api/execute";

async function callHive(toolName, args = {}) {
    const response = await fetch(API_URL, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ toolName, arguments: args })
    });
    if (!response.ok) throw new Error(`HTTP ${response.status}`);
    return response.json();
}

// Get Bitcoin price
const result = await callHive("get_price", {
    ids: "bitcoin",
    vs_currencies: "usd"
});
console.log(`Bitcoin: $${result.data.bitcoin.usd}`);

Helper Class

Create a reusable client:

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

    async execute(toolName, args = {}) {
        const response = await fetch(`${this.baseUrl}/api/execute`, {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ toolName, arguments: args })
        });
        if (!response.ok) {
            const error = await response.text();
            throw new Error(`API Error: ${error}`);
        }
        return response.json();
    }

    async getPrice(coinId, currency = "usd") {
        const result = await this.execute("get_price", {
            ids: coinId,
            vs_currencies: currency
        });
        return result.data[coinId][currency];
    }

    async checkSecurity(contract, chainId = "1") {
        const result = await this.execute("get_token_security", {
            contract_addresses: contract,
            chain_id: chainId
        });
        return result.data;
    }
}

// Usage
const client = new HiveClient();
const btcPrice = await client.getPrice("bitcoin");
console.log(`Bitcoin: $${btcPrice}`);

TypeScript Support

Add type definitions for better IDE support:

interface HiveResponse<T> {
    data: T;
    error?: string;
}

interface PriceData {
    [coin: string]: {
        [currency: string]: number;
    };
}

interface SecurityData {
    is_honeypot: boolean;
    is_open_source: boolean;
    is_mintable: boolean;
    buy_tax: string;
    sell_tax: string;
    holder_count: number;
}

class HiveClient {
    private baseUrl: string;

    constructor(baseUrl = "https://api.hiveintelligence.xyz") {
        this.baseUrl = baseUrl;
    }

    async execute<T>(toolName: string, args: Record<string, any> = {}): Promise<HiveResponse<T>> {
        const response = await fetch(`${this.baseUrl}/api/execute`, {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ toolName, arguments: args })
        });
        if (!response.ok) throw new Error(`HTTP ${response.status}`);
        return response.json();
    }

    async getPrice(coinId: string, currency = "usd"): Promise<number> {
        const result = await this.execute<PriceData>("get_price", {
            ids: coinId,
            vs_currencies: currency
        });
        return result.data[coinId][currency];
    }

    async checkSecurity(contract: string, chainId = "1"): Promise<SecurityData> {
        const result = await this.execute<SecurityData>("get_token_security", {
            contract_addresses: contract,
            chain_id: chainId
        });
        return result.data;
    }
}

Working with Tool Categories

Market Data

const client = new HiveClient();

// Get top coins by market cap
const topCoins = await client.execute("get_coins_market_data", {
    vs_currency: "usd",
    order: "market_cap_desc",
    per_page: 100
});

// Get historical price data
const history = await client.execute("get_coin_market_chart_range", {
    id: "bitcoin",
    vs_currency: "usd",
    from: 1704067200,
    to: 1706745600
});

// Get trending coins
const trending = await client.execute("get_trending", {});

DeFi Analytics

// Get all protocols
const protocols = await client.execute("get_protocols", {});

// Get specific protocol
const aave = await client.execute("get_defi_protocol", {
    protocol: "aave"
});

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

Portfolio Tracking

// Get wallet balances
const balances = await client.execute("get_wallet_balance", {
    address: "0x..."
});

// Get DeFi positions
const positions = await client.execute("get_wallet_defi_positions", {
    address: "0x..."
});

Security Analysis

const security = await client.execute("get_token_security", {
    contract_addresses: "0x...",
    chain_id: "1"
});

if (security.data.is_honeypot) {
    console.warn("WARNING: Potential honeypot!");
}

if (parseFloat(security.data.sell_tax) > 10) {
    console.warn(`WARNING: High sell tax: ${security.data.sell_tax}%`);
}

Concurrent Requests

const client = new HiveClient();

// Fetch multiple prices in parallel
const [btc, eth, sol] = await Promise.all([
    client.getPrice("bitcoin"),
    client.getPrice("ethereum"),
    client.getPrice("solana")
]);

console.log(`BTC: $${btc}, ETH: $${eth}, SOL: $${sol}`);

Error Handling

async function callHiveSafe(toolName, args = {}) {
    try {
        const response = await fetch("https://api.hiveintelligence.xyz/api/execute", {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ toolName, arguments: args })
        });

        if (response.status === 429) {
            console.warn("Rate limited. Wait and retry.");
            throw new Error("Rate limited");
        }

        if (!response.ok) {
            const error = await response.text();
            throw new Error(`API Error: ${error}`);
        }

        return response.json();
    } catch (error) {
        console.error("Request failed:", error.message);
        throw error;
    }
}

React Example

import { useState, useEffect } from 'react';

function useCryptoPrice(coinId) {
    const [price, setPrice] = useState(null);
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(null);

    useEffect(() => {
        async function fetchPrice() {
            try {
                const response = await fetch("https://api.hiveintelligence.xyz/api/execute", {
                    method: "POST",
                    headers: { "Content-Type": "application/json" },
                    body: JSON.stringify({
                        toolName: "get_price",
                        arguments: { ids: coinId, vs_currencies: "usd" }
                    })
                });
                const data = await response.json();
                setPrice(data.data[coinId].usd);
            } catch (err) {
                setError(err.message);
            } finally {
                setLoading(false);
            }
        }
        fetchPrice();
    }, [coinId]);

    return { price, loading, error };
}

function PriceDisplay({ coin }) {
    const { price, loading, error } = useCryptoPrice(coin);

    if (loading) return <span>Loading...</span>;
    if (error) return <span>Error: {error}</span>;
    return <span>${price.toLocaleString()}</span>;
}

Node.js with npm packages

For older Node.js versions, use node-fetch:

import fetch from 'node-fetch';

const response = await fetch("https://api.hiveintelligence.xyz/api/execute", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
        toolName: "get_price",
        arguments: { ids: "bitcoin", vs_currencies: "usd" }
    })
});

const data = await response.json();
console.log(data);

Quick Reference

ToolDescription
get_priceGet current prices
get_coins_market_dataMarket data with pagination
get_coin_market_chart_rangeHistorical price charts
get_trendingTrending coins
get_protocolsDeFi protocol list
get_token_securityToken security analysis
get_wallet_balanceWallet balances

Full Tools Reference →

Previous
Python
Next
Go