Step-by-step guide to connecting to an Ethereum RPC endpoint using JavaScript, Python, and curl. Includes viem, ethers.js, and web3.py examples with KuberNodes.
You need a KuberNodes API key (free tier gives 50K requests/month) and Node.js 18+ or Python 3.9+. Sign up at kubernodes.com to get your key instantly.
viem is the modern TypeScript library for Ethereum. It provides type-safe, lightweight clients with excellent tree-shaking.
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http('https://rpc.kubernodes.com/ethereum?apiKey=YOUR_KEY'),
})
const blockNumber = await client.getBlockNumber()
console.log('Latest block:', blockNumber)ethers.js is the most popular Ethereum library. Use JsonRpcProvider for read operations and a Wallet for signing transactions.
import { JsonRpcProvider } from 'ethers'
const provider = new JsonRpcProvider(
'https://rpc.kubernodes.com/ethereum?apiKey=YOUR_KEY'
)
const block = await provider.getBlockNumber()
console.log('Block:', block)
const balance = await provider.getBalance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
console.log('Balance (wei):', balance.toString())web3.py is the standard Python library for Ethereum. Install with pip install web3.
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(
'https://rpc.kubernodes.com/ethereum?apiKey=YOUR_KEY'
))
print('Connected:', w3.is_connected())
print('Block:', w3.eth.block_number)Test your connection directly with a JSON-RPC call. No libraries needed — just HTTP.
curl -X POST https://rpc.kubernodes.com/ethereum?apiKey=YOUR_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'For real-time data (new blocks, logs, pending transactions), use a WebSocket connection instead of HTTP.
import { createPublicClient, webSocket } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: webSocket('wss://ws.kubernodes.com/ethereum?apiKey=YOUR_KEY'),
})
const unwatch = client.watchBlockNumber({
onBlockNumber: (blockNumber) => console.log('New block:', blockNumber),
})Get a free API key and start making requests in under 5 minutes.
Create free account