Authentication overview

Authentication for the Blockchain.com API is a process that verifies the identity of a client attempting to access its resources. This mechanism ensures that only authorized applications and users can interact with Blockchain.com's services, which include retrieving Bitcoin blockchain data, monitoring transactions, and managing wallet functionalities. The specific authentication method required depends on the type of data or operation being requested, with public data access typically relying on API keys and more sensitive wallet operations utilizing OAuth 2.0 or signed requests.

The Blockchain.com API provides access to various data points, including block explorer information, transaction details, and wallet balances. For read-only access to public blockchain data, such as querying transaction hashes or address details, an API key is generally sufficient. For operations that involve user-specific data, such as accessing a user's wallet balance or initiating transactions, more secure and granular authentication methods are employed to protect user privacy and asset security. The choice of authentication method directly impacts the scope of actions an application can perform and the level of security afforded to the user's data and funds.

Supported authentication methods

Blockchain.com API supports several authentication methods, each designed for different use cases and security requirements. Understanding when to use each method is critical for secure and efficient integration.

API Key

API keys are unique identifiers used to authenticate applications accessing public, read-only data from the Blockchain.com API. They are typically passed as a query parameter or a custom header in API requests. API keys offer a straightforward method for accessing non-sensitive data, such as cryptocurrency prices, block information, or general network statistics. However, they should be treated as sensitive information and protected against unauthorized disclosure, as their compromise could lead to overuse of API quotas or unauthorized data access within the scope of the key.

OAuth 2.0

OAuth 2.0 is an authorization framework that allows third-party applications to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the third-party application to obtain access on its own behalf. For the Blockchain.com API, OAuth 2.0 is primarily used for granting access to user-specific wallet functionalities without sharing user credentials directly with the third-party application. This method is suitable for applications that need to perform actions such as viewing wallet balances, sending transactions, or managing addresses on behalf of a Blockchain.com user. The OAuth 2.0 flow involves obtaining an access token, which then authorizes subsequent API calls for a defined period and scope. The OAuth 2.0 specification is designed to enhance security by delegating authorization securely.

Signed Requests

Certain sensitive API endpoints, particularly those related to wallet interactions beyond basic read access, may require requests to be cryptographically signed. This method typically involves using a private key to create a digital signature of the request payload, which is then sent along with the request. The signature allows the API server to verify the integrity and authenticity of the request, ensuring that it has not been tampered with and originates from an authorized party. Signed requests add an extra layer of security, protecting against replay attacks and ensuring non-repudiation for critical operations like transaction initiation. While specific implementation details vary by endpoint, the general principle aligns with practices seen in other financial APIs to secure sensitive operations, as detailed by RFC 5849 on OAuth 1.0 Message Signatures, which shares principles of request signing.

The following table summarizes the supported authentication methods:

Method When to Use Security Level
API Key Accessing public, read-only blockchain data (e.g., block explorer, market data). Basic (requires secure storage and transmission).
OAuth 2.0 Accessing user-specific wallet data or performing actions on behalf of a user (e.g., viewing wallet balance, initiating payments). High (delegated authorization, token-based).
Signed Requests Performing critical write operations or highly sensitive read operations on wallets (e.g., sending funds, modifying wallet settings). High (cryptographically verified integrity and authenticity).

Getting your credentials

To begin using the Blockchain.com API, you must obtain the necessary credentials. The process typically involves creating an account and generating API keys or setting up an OAuth 2.0 application.

API Keys

  1. Create a Blockchain.com Account: If you don't already have one, register for an account on the official Blockchain.com website.
  2. Navigate to API Settings: Once logged in, locate the API section or developer dashboard within your account settings. This is usually accessible through a dedicated 'API' or 'Developers' link on the main navigation or user profile menu.
  3. Generate New API Key: Within the API settings, there will be an option to generate a new API key. You might be prompted to label your key for organizational purposes.
  4. Record Your API Key: Upon generation, the API key will be displayed. It is crucial to copy and store this key securely, as it may only be shown once. Treat it like a password.
  5. Configure Permissions (if applicable): Some API platforms allow you to configure specific permissions or whitelist IP addresses for your API key. Review these options to restrict access as much as possible, following the principle of least privilege.

For detailed instructions on generating API keys, refer to the Blockchain.com API documentation.

OAuth 2.0 Credentials

For applications requiring OAuth 2.0, the setup involves registering your application with Blockchain.com:

  1. Register Your Application: In the developer or API section of your Blockchain.com account, look for an option to register a new application.
  2. Provide Application Details: You will typically need to provide your application's name, description, and importantly, redirect URIs (or callback URLs). These URIs are where users will be redirected after granting or denying access to your application.
  3. Obtain Client ID and Client Secret: Upon successful registration, Blockchain.com will issue a Client ID and Client Secret for your application. The Client ID is public, but the Client Secret must be kept confidential and never exposed in client-side code.
  4. Configure Scopes: During registration or later, you will define the OAuth scopes (permissions) your application requires. Request only the minimum necessary permissions to perform its intended functions.

The Blockchain.com API documentation provides specific steps for registering an OAuth 2.0 application and managing its credentials.

Authenticated request example

Here's an example of how to make an authenticated request to the Blockchain.com API using an API key for a public endpoint. This example assumes you have obtained an API key.

Example: Retrieving the latest block data using an API Key

This request retrieves information about the latest Bitcoin block, authenticated via an API key passed as a query parameter.

curl -X GET "https://api.blockchain.info/charts/blocks-size?timespan=1year&format=json&api_code=YOUR_API_KEY"

Replace YOUR_API_KEY with your actual API key obtained from your Blockchain.com developer dashboard. Note that specific endpoints and required parameters may vary, so always consult the official API reference for the most up-to-date information.

Security best practices

Adhering to security best practices is essential when integrating with the Blockchain.com API to protect your application, user data, and the integrity of your interactions.

  • Secure API Key Storage: Never hardcode API keys directly into your application's source code, especially for client-side applications. Store them in environment variables, secret management services (like AWS Secrets Manager or Google Secret Manager), or secure configuration files that are not committed to version control.
  • Client Secret Protection: For OAuth 2.0, the Client Secret must be kept strictly confidential. It should only be used by your backend server and never exposed in client-side code (e.g., JavaScript in a web browser or mobile app).
  • Use HTTPS/TLS: Always ensure all communications with the Blockchain.com API occur over HTTPS (TLS). This encrypts data in transit, preventing eavesdropping and tampering. Blockchain.com enforces HTTPS for all API endpoints.
  • Least Privilege Principle: Configure your API keys and OAuth scopes to grant only the minimum necessary permissions required for your application's functionality. Avoid granting broad access if only specific operations are needed.
  • Regular Key Rotation: Periodically rotate your API keys and OAuth secrets. This limits the window of exposure if a key is compromised. Define a schedule for key rotation based on your organization's security policies.
  • IP Whitelisting: If the Blockchain.com API allows it, configure IP address whitelisting for your API keys. This restricts API access to requests originating from a predefined set of trusted IP addresses, adding a layer of network-level security.
  • Error Handling and Logging: Implement robust error handling and logging for API authentication failures. Monitor logs for suspicious activity, such as repeated authentication attempts with invalid credentials, which could indicate a brute-force attack.
  • Input Validation: Sanitize and validate all user inputs before using them in API requests to prevent injection attacks and other vulnerabilities.
  • Protect Redirect URIs: For OAuth 2.0, ensure your redirect URIs are securely configured and only point to trusted, controlled locations within your application. This prevents attackers from redirecting authorization codes to malicious sites.
  • Token Revocation: Implement mechanisms to revoke access tokens or API keys immediately if a compromise is suspected or an application's access is no longer required.
  • Stay Updated: Regularly review the Blockchain.com API documentation for any updates to authentication methods or security recommendations.