Fireblocks Python SDK

2.17.0 · active · verified Thu Apr 16

The Fireblocks Python SDK provides a robust interface to interact with the Fireblocks platform for secure digital asset operations, including managing vault accounts and executing transactions. It is actively maintained with frequent updates and bug fixes, currently at version 2.17.0, and follows a regular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Fireblocks SDK using API key and secret, then fetches a list of vault accounts. It demonstrates secure loading of credentials via environment variables and basic error handling.

import os
from fireblocks_sdk import FireblocksSDK
from fireblocks_sdk.sdk import FireblocksApiException

# Ensure environment variables are set for API Key and Secret
# export FIREBLOCKS_API_KEY="<your_api_key>"
# export FIREBLOCKS_SECRET_KEY_PATH="./fireblocks_secret.key" (or content in FIREBLOCKS_SECRET_KEY env var)
# export FIREBLOCKS_BASE_PATH="https://sandbox-api.fireblocks.io/v1" (or production URL)

try:
    api_key = os.environ.get('FIREBLOCKS_API_KEY', '')
    # It's recommended to load the private key from a file, not directly from an env var
    # For simplicity, using a placeholder here; in production, load securely.
    # For this quickstart, let's assume the secret key is in an environment variable 
    # or a known path for demonstration, but typically it's a file path.
    secret_key_path = os.environ.get('FIREBLOCKS_SECRET_KEY_PATH')
    if secret_key_path and os.path.exists(secret_key_path):
        with open(secret_key_path, 'r') as f:
            private_key = f.read()
    else:
        private_key = os.environ.get('FIREBLOCKS_SECRET_KEY', '')
        print("Warning: Loading private key directly from environment variable. Consider using a file path for security.")

    base_url = os.environ.get('FIREBLOCKS_BASE_PATH', 'https://sandbox-api.fireblocks.io/v1')

    if not api_key or not private_key:
        raise ValueError("FIREBLOCKS_API_KEY and FIREBLOCKS_SECRET_KEY/FIREBLOCKS_SECRET_KEY_PATH must be set.")

    fireblocks = FireblocksSDK(private_key=private_key, api_key=api_key, base_url=base_url)
    
    # Fetch and print vault accounts
    vault_accounts = fireblocks.get_vault_accounts()
    print("Successfully connected to Fireblocks and fetched vault accounts.")
    if vault_accounts:
        print(f"First vault account name: {vault_accounts[0].name}")
    else:
        print("No vault accounts found.")

except FireblocksApiException as e:
    print(f"Fireblocks API Error: {e.status_code} - {e.message}")
except ValueError as e:
    print(f"Configuration Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →