# Installation

Install and configure the HivePay SDK for your project.


# Package Installation

pnpm add @hivepay/client
npm install @hivepay/client
yarn add @hivepay/client
bun add @hivepay/client

# ESM Import

The SDK is distributed as an ESM module:

import { HivePay } from '@hivepay/client';
import { HivePay } from '@hivepay/client';
const { HivePay } = require('@hivepay/client');

# Creating a Client

# With API Key

Most operations require an API key:

import { HivePay } from '@hivepay/client';

const hivepay = new HivePay({
  apiKey: 'sk_live_xxxxxxxxxxxxx'
});

# Without API Key

Registration doesn't require an API key:

import { HivePay } from '@hivepay/client';

// Create public client
const publicClient = new HivePay();

// Register a merchant
const result = await publicClient.merchants.register({
  name: 'My Store',
  hiveAccount: 'mystore'
});

// Create authenticated client from result
const authClient = publicClient.withApiKey(result.apiKey);

# Configuration Options

Option Type Default Description
apiKey string - Your HivePay API key
endpoint string https://hivepay.me API endpoint URL
timeout number 30000 Request timeout in ms

# Full Configuration

const hivepay = new HivePay({
  apiKey: 'sk_live_xxxxxxxxxxxxx',
  endpoint: 'https://hivepay.me',  // Default
  timeout: 30000                    // 30 seconds
});

# Custom Endpoint

For self-hosted deployments:

const hivepay = new HivePay({
  apiKey: 'sk_live_xxxxxxxxxxxxx',
  endpoint: 'https://your-hivepay-instance.com'
});

# Environment Variables

Store your API key securely using environment variables:

// .env
HIVEPAY_API_KEY=sk_live_xxxxxxxxxxxxx

// app.ts
import { HivePay } from '@hivepay/client';

const hivepay = new HivePay({
  apiKey: process.env.HIVEPAY_API_KEY!
});
require('dotenv').config();
const { HivePay } = require('@hivepay/client');

const hivepay = new HivePay({
  apiKey: process.env.HIVEPAY_API_KEY
});

# TypeScript Configuration

The SDK includes TypeScript definitions. No additional @types package is needed.

Recommended tsconfig.json settings:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "strict": true
  }
}

# Browser Usage

The SDK works in modern browsers with native fetch support:

<script type="module">
  import { HivePay } from 'https://esm.sh/@hivepay/client';

  const hivepay = new HivePay({ apiKey: 'sk_live_xxx' });
  // ...
</script>

# Verifying Installation

Test your installation:

import { HivePay } from '@hivepay/client';

const hivepay = new HivePay({ apiKey: process.env.HIVEPAY_API_KEY! });

async function testConnection() {
  try {
    const feeRate = await hivepay.payments.getFeeRate();
    console.log('Connected! Current fee rate:', feeRate);
  } catch (error) {
    console.error('Connection failed:', error);
  }
}

testConnection();

# Next Steps