This guide will help you quickly integrate TheRPC into your project. Follow these steps to start making blockchain API calls.
To use TheRPC, you'll need an API key:
TheRPC supports multiple networks. Configure your environment with your API endpoint and key:
API_ENDPOINT="YOUR_API_ENDPOINT"
API_KEY="YOUR_API_KEY"
Here are basic examples for different programming languages. For more comprehensive examples and language-specific features, check out our Tools & SDKs Overview.
curl --request POST ${API_ENDPOINT} \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ${API_KEY}' \
--data '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'
const axios = require('axios');
const config = {
url: 'YOUR_API_ENDPOINT',
apiKey: 'YOUR_API_KEY',
};
async function getBlockNumber() {
const response = await axios.post(
config.url,
{
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
id: 1,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${config.apiKey}`,
},
},
);
console.log('Latest Block Number:', response.data.result);
}
import requests
config = {
'url': 'YOUR_API_ENDPOINT',
'api_key': 'YOUR_API_KEY'
}
def get_block_number():
response = requests.post(
config['url'],
headers={
'Content-Type': 'application/json',
'Authorization': f"Bearer {config['api_key']}"
},
json={
'jsonrpc': '2.0',
'method': 'eth_blockNumber',
'params': [],
'id': 1
}
)
return response.json()['result']
For more complex interactions, we recommend using Web3 libraries. You can find detailed examples for all supported languages and frameworks in our Tools & SDKs documentation.
const Web3 = require('web3');
const web3 = new Web3('YOUR_API_ENDPOINT');
// Add API key to requests
web3.setHeader('Authorization', 'Bearer YOUR_API_KEY');
async function getBalance(address) {
const balance = await web3.eth.getBalance(address);
return web3.utils.fromWei(balance, 'ether');
}
from web3 import Web3
from web3.middleware import http_retry_request_middleware
w3 = Web3(Web3.HTTPProvider(
'YOUR_API_ENDPOINT',
request_kwargs={
'headers': {'Authorization': 'Bearer YOUR_API_KEY'}
}
))
# Add retry middleware
w3.middleware_onion.add(http_retry_request_middleware)
All supported API methods with examples in different programming languages can be found in our Ethereum Methods documentation. This includes:
When using TheRPC, you'll receive specific API endpoints for each network you want to access. Simply replace YOUR_API_ENDPOINT
with the appropriate endpoint for your chosen network.