Skip to main content

Base API Quick Start Guide

BlockEden.xyz provides high-performance infrastructure for Base, Coinbase's Layer 2 solution built on the OP Stack. Access Base's ultra-low fees and enterprise-grade security through our global API endpoints with sub-second response times.

What is Base?

Base is Coinbase's Layer 2 blockchain that brings the next billion users onchain:

  • Ultra-Low Fees: Transactions cost fractions of a penny
  • EVM Compatibility: Full Ethereum tooling and smart contract support
  • OP Stack Technology: Built on Optimism's proven infrastructure
  • Enterprise Security: Backed by Coinbase's institutional-grade infrastructure
  • No Native Token: Uses ETH for gas fees, simplifying the user experience
  • Instant Finality: Fast transaction confirmation with L2 scaling

API Endpoints

BlockEden.xyz supports all Base API methods through our global infrastructure:

Mainnet

  • JSON-RPC: https://api.blockeden.xyz/base/<your-api-key>
  • WebSocket: wss://api.blockeden.xyz/base/<your-api-key>

Testnet (Sepolia)

  • JSON-RPC: https://api.blockeden.xyz/base-sepolia/<your-api-key>
  • WebSocket: wss://api.blockeden.xyz/base-sepolia/<your-api-key>

Quick Start

Step 1: Get Your API Key

  1. Visit BlockEden.xyz Dashboard
  2. Create a new API key for Base
  3. Select Mainnet or Testnet

Step 2: Test Connection

Get Latest Block Number

curl -X POST https://api.blockeden.xyz/base/<your-api-key> \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'

Get Account Balance

curl -X POST https://api.blockeden.xyz/base/<your-api-key> \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4", "latest"],
"id": 1
}'

Get Gas Price

curl -X POST https://api.blockeden.xyz/base/<your-api-key> \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": [],
"id": 1
}'

Supported API Methods

Core JSON-RPC Methods

All standard Ethereum JSON-RPC methods are supported:

  • Account Methods: eth_getBalance, eth_getTransactionCount, eth_getCode
  • Block Methods: eth_blockNumber, eth_getBlockByNumber, eth_getBlockByHash
  • Transaction Methods: eth_sendRawTransaction, eth_getTransactionReceipt
  • Contract Methods: eth_call, eth_estimateGas, eth_getLogs
  • Gas Methods: eth_gasPrice, eth_feeHistory, eth_maxPriorityFeePerGas
  • Network Methods: eth_chainId, net_version

Layer 2 Specific Methods

  • L1 to L2 Messages: Track cross-layer transactions
  • L2 to L1 Withdrawals: Monitor withdrawal status
  • Gas Estimation: Optimized for L2 fee structure

Code Examples

JavaScript/TypeScript

// Using ethers.js with Base
import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://api.blockeden.xyz/base/<your-api-key>');

// Get latest block
const blockNumber = await provider.getBlockNumber();
console.log('Latest block:', blockNumber);

// Get account balance
const balance = await provider.getBalance('0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4');
console.log('Balance:', ethers.formatEther(balance), 'ETH');

// Get current gas price
const gasPrice = await provider.getFeeData();
console.log('Gas price:', ethers.formatUnits(gasPrice.gasPrice, 'gwei'), 'gwei');
// Deploy a contract to Base
const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
const contract = await contractFactory.deploy({
gasLimit: 1000000,
// Base uses very low gas prices
gasPrice: ethers.parseUnits('0.001', 'gwei')
});

await contract.waitForDeployment();
console.log('Contract deployed to:', await contract.getAddress());

Python

import requests
from web3 import Web3

# Connect to Base
w3 = Web3(Web3.HTTPProvider('https://api.blockeden.xyz/base/<your-api-key>'))

# Check connection
print(f"Connected: {w3.is_connected()}")
print(f"Chain ID: {w3.eth.chain_id}")
print(f"Latest block: {w3.eth.block_number}")

# Get account balance
balance = w3.eth.get_balance('0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4')
print(f"Balance: {w3.from_wei(balance, 'ether')} ETH")

# Get gas price
gas_price = w3.eth.gas_price
print(f"Gas price: {w3.from_wei(gas_price, 'gwei')} gwei")

Go

package main

import (
"context"
"fmt"
"log"
"math/big"

"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/common"
)

func main() {
// Connect to Base
client, err := ethclient.Dial("https://api.blockeden.xyz/base/<your-api-key>")
if err != nil {
log.Fatal(err)
}

// Get latest block number
header, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Latest block: %s\n", header.Number.String())

// Get account balance
account := common.HexToAddress("0x742D5Cc6bF2442E8C7c74c7b4Be6AB9d6f10f5B4")
balance, err := client.BalanceAt(context.Background(), account, nil)
if err != nil {
log.Fatal(err)
}

balanceInEth := new(big.Float)
balanceInEth.SetString(balance.String())
balanceInEth = balanceInEth.Quo(balanceInEth, big.NewFloat(1e18))
fmt.Printf("Balance: %f ETH\n", balanceInEth)
}

Authentication

All API requests require your API key in the URL path:

https://api.blockeden.xyz/base/<your-api-key>

Example:

https://api.blockeden.xyz/base/abc123def456/

Rate Limits

  • Free Tier: 100 requests/second, 86,400 requests/day
  • Pro Tier: 1,000 requests/second, 10M requests/day
  • Enterprise: Custom limits based on your needs

Rate limit headers are included in responses:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1640995200

Network Information

Mainnet

  • Chain ID: 8453
  • Native Token: ETH (18 decimals)
  • Block Time: ~2 seconds
  • Explorer: https://basescan.org

Testnet (Base Sepolia)

Layer 2 Benefits

Ultra-Low Transaction Costs

// Example transaction costs on Base vs Ethereum
const estimateGas = async () => {
const gasLimit = await contract.estimateGas.transfer(recipient, amount);
const gasPrice = await provider.getFeeData();

// Base: typically 0.001-0.01 gwei
const baseCost = gasLimit * gasPrice.gasPrice;
console.log(`Transaction cost: ${ethers.formatEther(baseCost)} ETH`);
// Usually less than $0.01
};

Fast Finality

  • Soft Finality: ~2 seconds on Base
  • Hard Finality: ~7 days (L1 challenge period)
  • Practical Finality: Immediate for most applications

Ethereum Security

  • Inherits Ethereum's security model
  • Fraud proofs ensure transaction validity
  • Decentralized sequencer (roadmap)

WebSocket Subscriptions

Real-time data streaming for Base network events:

const ws = new WebSocket('wss://api.blockeden.xyz/base/<your-api-key>');

ws.onopen = () => {
// Subscribe to new blocks
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'eth_subscribe',
params: ['newHeads'],
id: 1
}));

// Subscribe to pending transactions
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'eth_subscribe',
params: ['newPendingTransactions'],
id: 2
}));
};

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

Error Handling

Common HTTP Status Codes

  • 200: Success
  • 400: Bad Request (invalid JSON or parameters)
  • 401: Unauthorized (invalid API key)
  • 429: Too Many Requests (rate limit exceeded)
  • 500: Internal Server Error

JSON-RPC Error Codes

  • -32700: Parse error
  • -32600: Invalid Request
  • -32601: Method not found
  • -32602: Invalid params
  • -32603: Internal error
  • -32000: Server error

Example Error Response

{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid params",
"data": "Missing required parameter"
},
"id": 1
}

Best Practices

Gas Optimization for L2

// Use appropriate gas settings for Base
const transaction = {
to: recipient,
value: ethers.parseEther("0.1"),
gasLimit: 21000,
// Base typically uses very low gas prices
gasPrice: ethers.parseUnits("0.001", "gwei")
};

// Or use EIP-1559 for better UX
const transaction1559 = {
to: recipient,
value: ethers.parseEther("0.1"),
gasLimit: 21000,
maxFeePerGas: ethers.parseUnits("0.01", "gwei"),
maxPriorityFeePerGas: ethers.parseUnits("0.001", "gwei")
};

Error Handling with Retries

async function makeRequest(method, params, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
const response = await fetch('https://api.blockeden.xyz/base/<your-api-key>', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1 })
});

if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}

const data = await response.json();
if (data.error) {
throw new Error(`RPC Error ${data.error.code}: ${data.error.message}`);
}

return data.result;
} catch (error) {
if (i === retries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, i)));
}
}
}

Contract Deployment

// Deploy contracts efficiently on Base
async function deployContract(factory, args = []) {
// Get current gas price
const feeData = await provider.getFeeData();

const contract = await factory.deploy(...args, {
gasLimit: 3000000,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
});

// Wait for deployment
const receipt = await contract.waitForDeployment();
console.log(`Contract deployed to: ${await contract.getAddress()}`);
console.log(`Transaction hash: ${receipt.deploymentTransaction().hash}`);

return contract;
}

Common Use Cases

DeFi Applications

  • DEX trading with minimal fees
  • Yield farming protocols
  • Lending and borrowing platforms
  • Stablecoin transfers

NFT Projects

  • Low-cost minting
  • NFT marketplaces
  • Gaming assets
  • Social tokens

Payment Systems

  • Micropayments
  • Subscription services
  • Cross-border transfers
  • Merchant payments

Next Steps

  • Explore the Base JSON-RPC API Reference for complete method documentation
  • Learn about Base WebSocket Guide for real-time data streaming
  • Check out Base L2 Features Guide for Layer 2 specific functionality
  • Visit BlockEden.xyz Dashboard to monitor your usage

Support