All requests to TheRPC API require authentication using an API key. This guide explains how to obtain and use your API key securely.
Include your API key in every request using the Bearer authentication scheme:
Authorization: Bearer YOUR_API_KEY
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,
}),
});
Common authentication errors:
{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "Invalid authentication credentials"
},
"id": 1
}
# .env file
THERPC_API_KEY=your_api_key_here
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')