Getting started overview

Integrating with Blockfrost Cardano involves a streamlined process designed to provide developers with rapid access to the Cardano blockchain. The initial setup requires creating an account, generating an API key for project authentication, and then employing this key to interact with Blockfrost's various endpoints. This guide details the steps to accomplish these tasks, enabling you to retrieve Cardano blockchain data, facilitate wallet integrations, and support decentralized application (dApp) development.

Blockfrost provides a comprehensive documentation portal that serves as the primary resource for API specifications, SDK usage, and more advanced topics. Developers can choose from multiple SDKs, including TypeScript and Python, to simplify interaction with the API.

The following table provides a quick reference to the essential steps for getting started:

Step What to do Where
1. Account Creation Register for a Blockfrost account. Blockfrost Sign-up Page
2. Project Setup Create a new project and select the desired network (Mainnet, Testnet). Blockfrost Dashboard
3. API Key Retrieval Locate and copy your project-specific API key. Blockfrost Dashboard (Project Settings)
4. Environment Setup Install a Blockfrost SDK or set up an HTTP client. Blockfrost SDK Documentation
5. First API Call Execute a simple request to verify connectivity and authentication. Your preferred development environment

Create an account and get keys

To begin utilizing Blockfrost's services, you must first create an account and obtain an API key. This key acts as your authentication credential for all API requests.

  1. Navigate to the Blockfrost Website: Open your web browser and go to the official Blockfrost homepage.
  2. Sign Up: Click on the "Sign Up" or "Get Started Free" button. You will be prompted to enter your email address and create a password. Follow the instructions to complete the registration process, which may include email verification.
  3. Access the Dashboard: After successful registration and login, you will be redirected to the Blockfrost Dashboard.
  4. Create a New Project: In the dashboard, locate the option to "Create a new project." Blockfrost organizes API access by projects, allowing you to manage different applications or environments separately.
  5. Configure Project Details:
    • Project Name: Provide a descriptive name for your project (e.g., "My Cardano dApp").
    • Network Selection: Choose the Cardano network you intend to interact with. Options typically include:
      • Mainnet: For production applications interacting with the live Cardano blockchain.
      • Testnet: For development and testing purposes, using non-real assets. The Cardano Testnet mirrors Mainnet functionality without financial implications.
  6. Generate API Key: Once the project is created, Blockfrost will automatically generate a unique API key for that project. This key is crucial for authenticating your requests.
  7. Copy Your API Key: On your project's dashboard page, find the API key. It is usually displayed prominently. Copy this key and store it securely. Treat your API key like a password; do not expose it in client-side code or public repositories.

Each project you create will have its own distinct API key, allowing for granular control over access and usage limits. The Blockfrost pricing page details the request limits associated with different tiers, including the generous free tier.

Your first request

With an API key in hand, you can now make your first request to the Blockfrost Cardano API. This example demonstrates fetching the current block height using a simple HTTP GET request, which is a common way to verify API connectivity. We will provide examples using both the curl command-line tool and a Python SDK snippet to illustrate the process.

Using cURL (HTTP Request)

The curl command is a versatile tool for making HTTP requests directly from your terminal. Replace YOUR_BLOCKFROST_API_KEY with the actual API key you obtained from your Blockfrost dashboard.

curl -H "project_id: YOUR_BLOCKFROST_API_KEY" \
     "https://cardano-mainnet.blockfrost.io/api/v0/blocks/latest"

Expected Successful Response (JSON):

{
  "time": 1678886400,
  "height": 12345678,
  "hash": "b9af3c92b2d07e6e5f8f94f9b8c6e2d1a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8",
  "slot": 23456789,
  "epoch": 300,
  "epoch_slot": 12345,
  "block_Vrf_key": "vrf_vk1...
  // ... other block details
}

This response indicates that your API key is valid and Blockfrost is successfully returning data from the Cardano Mainnet. The height field represents the latest block number on the chain.

Using Python SDK

For more complex integrations, using an official SDK is recommended as it handles authentication, request formatting, and response parsing. First, install the Blockfrost Python SDK:

pip install blockfrost-python

Then, create a Python script (e.g., get_latest_block.py):

from blockfrost import BlockFrostApi, ApiError
import os

# It's recommended to store your API key in an environment variable
# Example: export BLOCKFROST_API_KEY="YOUR_BLOCKFROST_API_KEY"
api_key = os.environ.get("BLOCKFROST_API_KEY", "YOUR_BLOCKFROST_API_KEY")

try:
    api = BlockFrostApi(project_id=api_key)
    latest_block = api.block_latest()
    print(f"Latest Block Height: {latest_block.height}")
    print(f"Latest Block Hash: {latest_block.hash}")
except ApiError as e:
    print(f"Blockfrost API Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

Execute the script:

python get_latest_block.py

Expected Output:

Latest Block Height: 12345678
Latest Block Hash: b9af3c92b2d07e6e5f8f94f9b8c6e2d1a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8

This demonstrates a successful interaction using the Python SDK, confirming your setup is correct.

Common next steps

Once you've successfully made your first API call, consider these next steps to further develop your integration with Blockfrost Cardano:

  • Explore More Endpoints: Blockfrost offers a wide array of endpoints for accessing various aspects of the Cardano blockchain, including transactions, addresses, assets, and pools. Refer to the Blockfrost API Reference to discover more functionalities relevant to your project.
  • Implement Advanced Features: Explore more advanced features like querying specific transactions, fetching NFT metadata, or monitoring address balances. The API can also be used for submitting transactions, though this typically involves signing them off-chain first. The Cardano documentation on transaction signing can provide further context.
  • Utilize SDKs: If you are working with a supported language (TypeScript, Python, Go, Rust, C#, Java), leveraging the official Blockfrost SDKs can significantly streamline development by abstracting away HTTP request details and providing typed interfaces.
  • Manage API Keys Securely: Ensure your API keys are stored securely, ideally using environment variables or a secrets management service, and never hardcoded in your application or committed to version control.
  • Monitor Usage: Keep an eye on your API request usage through the Blockfrost dashboard to stay within your plan limits. If your application scales, consider upgrading to a paid plan to accommodate higher request volumes.
  • Error Handling: Implement robust error handling in your application to gracefully manage API rate limits, invalid requests, or network issues. The Blockfrost SDKs typically provide structured error responses for easier debugging.
  • Community and Support: Engage with the Blockfrost community on Discord for questions, discussions, and support.

Troubleshooting the first call

If your first API call does not return the expected result, consider the following common issues and their solutions:

  • Incorrect API Key: Double-check that the project_id header (for direct HTTP requests) or the project_id parameter (for SDKs) precisely matches the API key from your Blockfrost dashboard. Copy-pasting errors are common.
  • Network Mismatch: Ensure that the network specified in your API endpoint (e.g., cardano-mainnet.blockfrost.io) corresponds to the network your API key was generated for (Mainnet or Testnet). An API key generated for Testnet will not work on Mainnet endpoints, and vice-versa.
  • Missing or Incorrect Header: For direct HTTP requests, the project_id header is mandatory. Ensure it's correctly formatted as -H "project_id: YOUR_API_KEY".
  • Rate Limiting: While less likely on a first call, excessive requests can lead to rate limiting. Check your Blockfrost dashboard for current usage and limits. If you are experiencing rate limiting, you might receive a 429 Too Many Requests HTTP status code.
  • Network Connectivity: Verify your internet connection. A basic ping blockfrost.io can confirm general network access. Proxy or firewall settings might also interfere with outbound requests.
  • Typographical Errors in URL/Endpoint: Carefully review the API endpoint URL for any typos. Refer to the Blockfrost API documentation for the exact paths.
  • SDK Configuration Issues: If using an SDK, ensure it's correctly installed and initialized with your API key. Consult the specific SDK documentation for configuration details.
  • Environment Variable Not Set: If you are retrieving the API key from an environment variable (as in the Python example), ensure the variable is correctly set in your environment before running your script. For example, on Linux/macOS: export BLOCKFROST_API_KEY="YOUR_API_KEY".
  • Server-Side Errors: Occasionally, the API service itself might experience temporary issues. Check the Blockfrost Status Page for any reported outages or maintenance.