Authentication

Learn how to securely authenticate your API requests using Tokra API keys and follow security best practices.

Every API request requires authentication via API key. Create your key in the Tokra dashboard under Settings → API Keys.

Include your key in the Authorization header:

curl -X POST https://api.tokra.io/v1/eth/mainnet \
  -H "Authorization: Bearer tk_live_abc123xyz789" \
  -H "Content-Type: application/json" \
  -d '{
    "method": "eth_blockNumber",
    "params": []
  }'
```

**Security tips:**
- Never expose API keys in client-side code
- Rotate keys every 90 days
- Use environment variables for key storage

---

# API REFERENCE

## Core Endpoints

**Get Account Balance**
```
POST /v1/{chain}/{network}

Parameters: address (string), block (string, default: "latest")

Response:

{
  "jsonrpc": "2.0",
  "result": "0x1bc16d674ec80000",
  "id": 1
}
```

**Get Transaction**
```
POST /v1/{chain}/{network}

Parameters: hash (string)

Response:

{
  "result": {
    "hash": "0xab12...",
    "from": "0x742d...",
    "to": "0x8f3c...",
    "value": "0x16345785d8a0000",
    "blockNumber": "0x12a4f2c"
  }
}
```

**Get Block**
```
POST /v1/{chain}/{network}
```
Parameters: `blockNumber` (string/number), `fullTransactions` (boolean)

**Get Transaction Receipt**
```
POST /v1/{chain}/{network}
```
Parameters: `hash` (string)

**Send Raw Transaction**
```
POST /v1/{chain}/{network}
```
Parameters: `signedTransaction` (string)

---

## WebSockets

Real-time blockchain data via WebSocket connections. Subscribe to new blocks, pending transactions, or smart contract events.

**Connect to WebSocket:**
```
wss://ws.tokra.io/v1/{chain}/{network}?apikey=YOUR_API_KEY

Subscription Types:

  1. New Blocks - Receive each new block as it's mined

  2. Pending Transactions - Stream pending txs from mempool

  3. Logs - Subscribe to smart contract events

Example:

const ws = new WebSocket('wss://ws.tokra.io/v1/eth/mainnet?apikey=tk_live_abc123');

ws.onopen = () => {
  ws.send(JSON.stringify({
    method: 'eth_subscribe',
    params: ['newHeads']
  }));
};

ws.onmessage = (event) => {
  const block = JSON.parse(event.data);
  console.log('New block:', block.params.result.number);
};
```

---

# RESOURCES

## Rate Limits

**Free Tier:** 10 requests/second
**Pro Tier:** 100 requests/second  
**Business Tier:** 1,000 requests/second

When you exceed your rate limit, you'll receive a `429 Too Many Requests` response. Your limits reset every second.

**Response header:**
```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 47
X-RateLimit-Reset: 1704920400

Best Practices:

  • Batch requests when possible using eth_batch

  • Implement exponential backoff for retries

  • Cache frequently accessed data (block numbers, contract ABIs)

  • Use WebSockets for real-time updates instead of polling

Create a free website with Framer, the website builder loved by startups, designers and agencies.