Base API Overview
Welcome to the Base API Quickstart and Reference Guide. This guide provides everything you need to start building on Base using dRPC’s JSON-RPC API. Whether you're retrieving account balances, fetching block details, executing transactions, or estimating gas fees, this comprehensive guide will help you integrate Base seamlessly into your applications.
This page includes:
- A Quickstart Guide to help you set up and make your first Base API request.
- A detailed list of all Base API methods, categorized for easy reference.
Base API Quickstart#
To get started with building on Base using dRPC's Base RPC API, follow these steps:
1. Create a dRPC Account or Use Public Base RPC endpoints
By signing up for a free dRPC account, you can access their Premium Base RPC endpoints.
Public endpoints:
HTTPS
https://base.drpc.org/
WSS:
wss://base.drpc.org
2. Set Up Your Development Environment
RPC can be requested in various ways (opens in a new tab). In this example, we are going to use Node.js. Ensure you have Node.js (opens in a new tab) and npm installed on your system. You can verify their installation by running:
node -v
npm -v
If not installed, download and install them from the official Node.js website (opens in a new tab).
3. Initialize Your Project
Create a new directory for your project and initialize it:
mkdir Base-drpc-quickstart
cd Base-drpc-quickstart
npm init --yes
4. Install Axios
Axios is a popular HTTP client for making API requests. Install it using npm:
npm install axios
5. Obtain dRPC Endpoint
Log in to your dRPC account and navigate to the Base RPC endpoints section. Copy the HTTPS endpoint URL for the Base Mainnet.
6. Write Your First Script
Create an index.js
file in your project directory and add the following code:
const axios = require('axios');
const url = 'https://lb.drpc.org/ogrpc?network=base&dkey=YOUR_DRPC_API_KEY';
const payload = {
jsonrpc: '2.0',
id: 1,
method: 'eth_blockNumber',
params: []
};
axios.post(url, payload)
.then(response => {
console.log('The latest block number is', parseInt(response.data.result, 16));
})
.catch(error => {
console.error('Error fetching block number:', error);
});
Replace ‘https://lb.drpc.org/ogrpc?network=base&dkey=YOUR_DRPC_API_KEY'
with the actual endpoint URL you obtained from dRPC.
7. Run Your Script
Execute your script using Node.js:
node index.js
You should see the latest Base block number printed in your console.
Additional Information
dRPC offers various features such as high performance nodes, access to multiple chains, and MEV protection. For more details, visit their Base documentation (opens in a new tab).
By following these steps, you can start building on Base using dRPC's reliable and efficient RPC endpoints.
Base API Methods#
Base is a decentralized blockchain platform designed to deliver high throughput, low latency, and customizable subnets, making it ideal for building decentralized applications (dApps) and financial solutions with scalability and security.
Accounts info#
Retrieves essential on-chain data related to accounts
eth_getBalance : Retrieves the balance of an account.
eth_getCode : Fetches the smart contract code stored at a given address.
eth_getStorageAt : Retrieves the data stored at a specific storage slot of an account.
Blocks info#
Provides methods for retrieving detailed information about specific blocks
eth_blockNumber : Retrieves the latest block number.
eth_getBlockByHash : Fetches block details by hash.
eth_getBlockByHash#full : Returns full block details by hash.
eth_getBlockByNumber : Retrieves block data by block number.
eth_getBlockByNumber#full : Fetches full block details by number.
eth_newBlockFilter : Available only on paid tier. Creates a filter for new blocks.
eth_getBlockTransactionCountByHash : Returns the transaction count for a block by its hash.
eth_getBlockTransactionCountByNumber : Retrieves the transaction count for a block by its number.
Chain info#
Provides essential data about the state and performance of the Base network
eth_chainId : Returns the chain ID of the network.
net_listening : Checks if the client is actively listening for network connections.
net_version : Returns the current network version.
net_peerCount : Retrieves the number of active peers connected to the node.
eth_syncing : Indicates the synchronization status of the node.
Debug and trace#
Available only on paid tier. These methods are useful for analyzing execution flows and debugging
debug_traceBlockByHash : Traces the execution of all transactions in a block by its hash.
debug_traceBlockByNumber : Traces the execution of all transactions in a block by its number.
debug_traceTransaction : Provides detailed trace information for a specific transaction.
debug_traceCall : Traces a specific call without altering the blockchain state.
Event logs#
Allows the filtering and retrieval of event logs generated by smart contracts
eth_getLogs : Available only on paid tier. Retrieves event logs based on specified filter criteria.
eth_newFilter : Available only on paid tier. Creates a new filter to monitor logs.
eth_getFilterChanges : Available only on paid tier. Retrieves changes for a filter since its last check.
eth_uninstallFilter : Uninstalls a previously created filter.
eth_getFilterLogs : Available only on paid tier. Fetches logs matching a specific filter.
Executing transactions#
Are essential for interacting with smart contracts and sending transactions
eth_call : Executes a read-only call to a smart contract without making any state changes.
eth_sendRawTransaction : Sends a raw, signed transaction to the Avalanche blockchain for execution.
Gas estimation#
Provides tools to estimate gas fees and optimize transaction costs.
eth_estimateGas : Estimates the gas required for a transaction.
eth_gasPrice : Returns the current gas price on the network.
eth_maxPriorityFeePerGas : Retrieves the maximum priority fee per gas unit.
Getting uncles#
Provides methods to retrieve information about uncle blocks
eth_getUncleCountByBlockHash : Retrieves the number of uncle blocks for a given block by its hash.
eth_getUncleCountByBlockNumber : Returns the number of uncle blocks for a specified block number.
Subscriptions#
Enables real-time monitoring of blockchain events via WebSockets
eth_subscribe : Subscribes to events such as new blocks, pending transactions, or log updates.
eth_unsubscribe : Unsubscribes from an active WebSocket event subscription.
Transactions info#
Provides methods to retrieve transaction details, counts, and receipts
eth_getTransactionByHash : Retrieves transaction details using a transaction hash.
eth_getTransactionCount : Returns the number of transactions sent from an address.
eth_getTransactionReceipt : Retrieves the receipt of a processed transaction.
eth_newPendingTransactionFilter : Available only on paid tier. Sets up a filter for monitoring pending transactions.
eth_getTransactionByBlockHashAndIndex : Retrieves a transaction from a block by hash and index.
eth_getTransactionByBlockNumberAndIndex : Retrieves a transaction by block number and index.
Web3#
Provides methods to retrieve transaction-related data
web3_clientVersion : Returns the version of the Avalanche node client in use.
web3_sha3 : Computes the Keccak-256 (SHA3) hash of the provided data.