Skip to main content

Harmony API Quick Start Guide

Harmony is a blockchain platform designed for high throughput and low latency, featuring a unique sharding-based architecture and cross-chain compatib

Share
Last updated on August 19, 2026

bex.co provides high-performance, reliable Harmony infrastructure through our comprehensive JSON-RPC API. Connect to Ethereum mainnet, testnets, and layer 2 solutions with enterprise-grade reliability and developer-friendly tools.

Overview

Our Harmony API supports:

  • Harmony Mainnet and all major testnets (Sepolia, Holesky)
  • Layer 2 Solutions (Polygon, Arbitrum, Optimism)
  • Full JSON-RPC Specification with debug and trace methods
  • WebSocket Connections for real-time data
  • Archive Node Access for historical data
  • MEV Protection and transaction simulation

Quick Start

Step 1: Get Your API Key

  1. Visit bex.co Dashboard
  2. Sign up for a free account if you haven't already
  3. Create a new API key for Harmony
  4. Select your target network (Mainnet, Sepolia, etc.)

Step 2: Make Your First Request

Using cURL

bash
curl -X POST https://api.bex.co/harmony/${accessKey} \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
  }'

Using JavaScript (Fetch)

javascript
const response = await fetch('https://api.bex.co/harmony/${accessKey}', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'eth_blockNumber',
    params: [],
    id: 1
  })
});
 
const data = await response.json();
console.log('Current block number:', parseInt(data.result, 16));

Using Python

python
import requests
import json
 
url = "https://api.bex.co/harmony/${accessKey}"
payload = {
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
}
 
response = requests.post(url, json=payload)
result = response.json()
print(f"Current block number: {int(result['result'], 16)}")

Core RPC Methods

Account Information

javascript
// Get account balance
{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": ["0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4", "latest"],
  "id": 1
}
 
// Get transaction count (nonce)
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionCount",
  "params": ["0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4", "latest"],
  "id": 1
}

Block Information

javascript
// Get latest block
{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": ["latest", true],
  "id": 1
}
 
// Get block by hash
{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByHash",
  "params": ["0x1234...abcd", true],
  "id": 1
}

Transaction Operations

javascript
// Get transaction by hash
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionByHash",
  "params": ["0x1234...abcd"],
  "id": 1
}
 
// Send raw transaction
{
  "jsonrpc": "2.0",
  "method": "eth_sendRawTransaction",
  "params": ["0x1234...abcd"],
  "id": 1
}

Network Endpoints

Mainnet

  • HTTP: https://api.bex.co/harmony/${accessKey}
  • WebSocket: wss://api.bex.co/harmony/${accessKey}

Testnets

  • Sepolia: https://ethereum-sepolia.bex.co/<your-api-key>
  • Holesky: https://ethereum-holesky.bex.co/<your-api-key>

Layer 2 Networks

  • Polygon: https://polygon-mainnet.bex.co/<your-api-key>
  • Arbitrum: https://arbitrum-mainnet.bex.co/<your-api-key>
  • Optimism: https://optimism-mainnet.bex.co/<your-api-key>

Authentication & Security

API Key Authentication

All requests require your API key in the URL path. Keep your API key secure and never expose it in client-side code.

Rate Limits

  • Free tier: 100 requests per second
  • Pro tier: 1,000 requests per second
  • Enterprise: Custom limits

Best Practices

  1. Use HTTPS for all API calls
  2. Implement retry logic with exponential backoff
  3. Cache responses when appropriate
  4. Monitor your usage in the dashboard
  5. Use batch requests for multiple operations

Common Use Cases

Check Account Balance

javascript
async function getBalance(address) {
  const response = await fetch('https://api.bex.co/harmony/${accessKey}', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'eth_getBalance',
      params: [address, 'latest'],
      id: 1
    })
  });
  
  const data = await response.json();
  const balanceWei = BigInt(data.result);
  const balanceEth = balanceWei / BigInt('1000000000000000000');
  return balanceEth.toString();
}

Monitor New Blocks

javascript
// Using WebSocket for real-time updates
const ws = new WebSocket('wss://api.bex.co/harmony/${accessKey}');
 
ws.on('open', () => {
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    method: 'eth_subscribe',
    params: ['newHeads'],
    id: 1
  }));
});
 
ws.on('message', (data) => {
  const result = JSON.parse(data);
  if (result.params) {
    console.log('New block:', result.params.result);
  }
});

Smart Contract Interaction

javascript
async function callContract(contractAddress, data) {
  const response = await fetch('https://api.bex.co/harmony/${accessKey}', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'eth_call',
      params: [
        {
          to: contractAddress,
          data: data
        },
        'latest'
      ],
      id: 1
    })
  });
  
  return await response.json();
}

Error Handling

Common Error Codes

javascript
// Handle RPC errors properly
async function safeRpcCall(method, params) {
  try {
    const response = await fetch(endpoint, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        jsonrpc: '2.0',
        method,
        params,
        id: 1
      })
    });
    
    const data = await response.json();
    
    if (data.error) {
      throw new Error(`RPC Error ${data.error.code}: ${data.error.message}`);
    }
    
    return data.result;
  } catch (error) {
    console.error('RPC call failed:', error);
    throw error;
  }
}

Retry Logic

javascript
async function withRetry(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, i)));
    }
  }
}

Next Steps

  • Explore the [Harmony JSON-RPC API Reference]./harmony-json-rpc-api.md for complete method documentation
  • Learn about [WebSocket Connections]./harmony-websockets.md for real-time data
  • Follow our [Web3.js Integration Guide]./harmony-web3-integration.md for frontend development
  • Check out our [Ethers.js Integration Guide]./harmony-ethers-integration.md for modern development patterns

Resources

Need Help?


Cost: 300 CUs / req

One API key for 30+ chains

bex router is a single multi-chain gateway — one key, one bill, metered in compute units instead of an account per network.

Explore bex router