Getting started overview

Getting started with INFURA Ethereum involves a sequence of steps to establish connectivity and begin interacting with the Ethereum blockchain via their API. INFURA acts as an intermediary, providing access to Ethereum nodes without requiring users to run their own infrastructure. This guide outlines the process from account creation to executing a basic API call, focusing on the necessary credentials and configuration for initial setup.

The primary steps include:

  1. Account Creation: Registering for an INFURA account.
  2. Project Setup: Creating a new project within the INFURA dashboard to generate API keys.
  3. API Key Retrieval: Obtaining the project ID and API secret.
  4. First Request: Constructing and executing an API call using the generated credentials.

INFURA supports various Ethereum networks, including Mainnet, Sepolia, and Holesky for testing. For a comprehensive list of supported networks and their specifications, consult the INFURA Networks documentation.

Create an account and get keys

To begin using INFURA Ethereum, you must first create an account and generate the necessary API keys. These keys authenticate your requests and link them to your project.

1. Sign up for an INFURA account

Navigate to the INFURA homepage and select the option to sign up. You will typically need to provide an email address, create a password, and agree to their terms of service. INFURA offers a free Core plan which includes 100,000 requests per day across three projects, suitable for initial development and testing.

2. Create a new project

After successfully signing into your new account, you will be directed to the INFURA dashboard. From here, create a new project:

  1. Click the "Create New Project" button.
  2. Select "Ethereum" as the product.
  3. Provide a descriptive name for your project. This name helps you identify the project within your dashboard.
  4. Click "Create".

Upon creation, INFURA automatically generates a dedicated project ID and a set of API endpoints for various Ethereum networks.

3. Retrieve your API keys

Once your project is created, the dashboard will display your project details, including the Project ID. This Project ID serves as your primary API key for making requests. INFURA's documentation provides further details on creating a new INFURA project.

For enhanced security, especially in client-side applications or when directly exposing your Project ID, INFURA also allows for the creation of an API Key Secret. This secret is used for authenticated requests in certain scenarios, such as when using IPFS or Filecoin APIs, or for more secure server-side interactions. For Ethereum RPC calls, the Project ID is typically sufficient for public read-only access. If your application requires writing to the blockchain (e.g., sending transactions), you will typically use a client-side library like Web3.js or Ethers.js, which handle wallet integration and transaction signing locally, then relay the signed transaction through INFURA.

Your first request

With your API key (Project ID) in hand, you can now make your first request to the Ethereum network. This example demonstrates fetching the latest block number using a simple curl command and JavaScript with Web3.js.

Using curl (HTTP POST)

The Ethereum JSON-RPC API is accessible via HTTP POST requests. Replace YOUR_INFURA_PROJECT_ID with your actual Project ID.

curl -X POST \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
     https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID

This command requests the current block number from the Ethereum Mainnet. A successful response will look similar to this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1234567" 
}

The result field contains the latest block number in hexadecimal format.

Using JavaScript with Web3.js

For client-side or Node.js applications, libraries like Web3.js or Ethers.js simplify interaction with the Ethereum blockchain via INFURA. First, install Web3.js:

npm install web3

Then, use the following JavaScript code to connect to INFURA and fetch the latest block number. Replace YOUR_INFURA_PROJECT_ID with your Project ID.

const Web3 = require('web3');

const infuraProjectId = 'YOUR_INFURA_PROJECT_ID';
const web3 = new Web3(new Web3.providers.HttpProvider(`https://mainnet.infura.io/v3/${infuraProjectId}`));

async function getLatestBlockNumber() {
  try {
    const blockNumber = await web3.eth.getBlockNumber();
    console.log('Latest block number:', blockNumber);
  } catch (error) {
    console.error('Error fetching block number:', error);
  }
}

getLatestBlockNumber();

This script initializes Web3.js with your INFURA endpoint and asynchronously retrieves the latest block number, printing it to the console. Developers can find more examples of INFURA Ethereum JSON-RPC methods in the official documentation.

Common next steps

After successfully making your first request, consider these common next steps to further integrate INFURA Ethereum into your development workflow:

  • Explore other JSON-RPC methods: INFURA exposes the full Ethereum JSON-RPC API, allowing you to query account balances (eth_getBalance), retrieve transaction details (eth_getTransactionByHash), and interact with smart contracts (eth_call).
  • Integrate with dApp frameworks: If building a decentralized application (dApp), integrate INFURA with frameworks like Hardhat, Truffle, or Foundry. These tools streamline development, testing, and deployment of smart contracts.
  • Switch to a testnet: For development and testing, switch your project to a testnet like Sepolia or Holesky to avoid incurring costs or interacting with real assets on Mainnet. Update your INFURA endpoint URL accordingly (e.g., https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID).
  • Monitor usage: Utilize the INFURA dashboard to monitor your API request usage, identify potential bottlenecks, and ensure you stay within your plan's limits.
  • Implement WebSocket subscriptions: For real-time updates (e.g., new blocks, pending transactions), consider using INFURA's WebSocket endpoints. WebSockets provide persistent connections for streaming data, which is crucial for responsive dApps. The INFURA Ethereum WebSocket documentation provides implementation details.
  • Security considerations: While your Project ID is generally safe to expose for read-only public data, for sending transactions or any operation requiring private keys, ensure your application handles signing locally and only sends signed transactions to INFURA. Never expose private keys directly to INFURA or any third-party service. The Mozilla Developer Network's secure coding practices offer general guidance.

Troubleshooting the first call

Encountering issues during your first API call is common. Here's a quick reference for troubleshooting:

Authentication errors (401 Unauthorized)

  • Incorrect Project ID: Double-check that you have copied your Project ID accurately. Any typos will result in authentication failure.
  • Missing Project ID: Ensure your Project ID is included in the URL path (/v3/YOUR_INFURA_PROJECT_ID).
  • Rate Limiting: If you're on the free tier and making many rapid requests, you might hit the rate limit. Check your INFURA dashboard for usage statistics.

Network errors (e.g., connection refused, timeout)

  • Firewall/Proxy: Your local network or corporate firewall might be blocking outbound HTTP/HTTPS requests to INFURA. Verify your network settings.
  • Incorrect Endpoint URL: Ensure the base URL (https://mainnet.infura.io or the appropriate testnet URL) is correct.
  • INFURA Status: Check the INFURA status page to see if there are any ongoing service outages or degraded performance.

JSON-RPC errors (e.g., "Method not found", "Invalid params")

  • Typos in Method Name: Verify the JSON-RPC method name (e.g., eth_blockNumber) is spelled correctly and matches the INFURA Ethereum JSON-RPC method reference.
  • Incorrect Parameters: Ensure the params array in your JSON payload is correctly formatted and contains the expected data types and number of arguments for the specific method. For eth_blockNumber, the params array should be empty ([]).
  • JSON Formatting: Check for any syntax errors in your JSON payload (e.g., missing commas, unclosed brackets, incorrect quotes). Use a JSON linter if unsure.

If issues persist, consult the INFURA troubleshooting guide or reach out to their support channels.

INFURA Ethereum Getting Started: Quick Reference
Step What to Do Where
1. Sign Up Create an INFURA account. INFURA Homepage
2. Create Project In dashboard, create new Ethereum project. INFURA Dashboard
3. Get API Key Copy your Project ID. INFURA Project Settings
4. Make Request Use curl or a library (e.g., Web3.js) with your Project ID. Terminal/Code Editor
5. Monitor Usage Check API request volume and status. INFURA Dashboard