Getting started with TheRPC
Ethereum/Authentication

Authentication

All requests to TheRPC API require authentication using an API key. This guide explains how to obtain and use your API key securely.

# Getting an API Key

  1. Sign up at TheRPC.io
  2. Navigate to the Dashboard
  3. Go to API Keys section
  4. Generate a new API key

# Using Your API Key

HTTP Headers

Include your API key in every request using the Bearer authentication scheme:

Authorization: Bearer YOUR_API_KEY

Example Requests

Using curl:

curl --request POST 'YOUR_API_ENDPOINT' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
  }'

Using JavaScript:

const response = await fetch('YOUR_API_ENDPOINT', {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json',
		Authorization: `Bearer ${API_KEY}`,
	},
	body: JSON.stringify({
		jsonrpc: '2.0',
		method: 'eth_blockNumber',
		params: [],
		id: 1,
	}),
});

# Security Best Practices

  1. Keep Keys Secret
  • Never commit API keys to source control
  • Don't share keys in public forums
  • Use environment variables or secure vaults
  1. Key Rotation
  • Rotate keys periodically
  • Immediately revoke compromised keys
  • Use different keys for different environments
  1. Access Control
  • Use separate keys for different applications
  • Monitor key usage through dashboard
  • Implement proper key management

# Error Handling

Common authentication errors:

{
	"jsonrpc": "2.0",
	"error": {
		"code": -32001,
		"message": "Invalid authentication credentials"
	},
	"id": 1
}
  • Missing API key
  • Invalid API key format
  • Expired or revoked key
  • Rate limit exceeded

# Environment Setup

Environment Variables

# .env file
THERPC_API_KEY=your_api_key_here

Configuration Examples

Node.js:

require('dotenv').config();
const API_KEY = process.env.THERPC_API_KEY;

Python:

import os
from dotenv import load_dotenv

load_dotenv()
API_KEY = os.getenv('THERPC_API_KEY')

See also

Help Us Get Better!
Share this page and help us create an even better product for you.