Java SDK

Overview

📘

Fireblocks API Java SDK

Visit this link to try out the new Java SDK. Instructions for setup and usage can be found in the Github readme.

Java developers can use the official Fireblocks Java SDK to interact with the Fireblocks API:
Fireblocks API Java SDK

Using the Fireblocks Java SDK

Building the API client library requires:

  1. Java 11+
  2. Maven/Gradle

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.fireblocks.sdk</groupId>
  <artifactId>fireblocks-sdk</artifactId>
  <version>0.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.fireblocks.sdk:fireblocks-sdk:0.0.0"

Others

At first, generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/fireblocks-sdk-0.0.0.jar
  • target/lib/*.jar

Getting Started

Initiate Fireblocks Client

You can initialize the Fireblocks SDK in two ways, either by setting environment variables or providing the parameters directly:

Using Environment Variables
You can initialize the SDK using environment variables from your .env file or by setting them programmatically.

📘

Use the correct API Base URL

In the following script, make sure you're using the correct value for FIREBLOCKS_BASE_PATH for your environment:

  • For Sandbox workspaces: https://sandbox-api.fireblocks.io
  • For Mainnet or Testnet workspaces: https://api.fireblocks.io

Learn more about workspace differences.

Use bash commands to set environment variables:

export FIREBLOCKS_BASE_PATH="https://sandbox-api.fireblocks.io/v1"
export FIREBLOCKS_API_KEY="my-api-key"
export FIREBLOCKS_SECRET_KEY="my-secret-key"

Execute the following Java code:

import com.fireblocks.sdk.Fireblocks;
import com.fireblocks.sdk.ConfigurationOptions;

ConfigurationOptions configurationOptions = new ConfigurationOptions();
Fireblocks fireblocks = new Fireblocks(configurationOptions);

Providing Local Variables
Alternatively, you can directly pass the required parameters when initializing the Fireblocks API instance:

import com.fireblocks.sdk.BasePath;
import com.fireblocks.sdk.Fireblocks;
import com.fireblocks.sdk.ConfigurationOptions;

ConfigurationOptions configurationOptions = new ConfigurationOptions()
    .basePath(BasePath.Sandbox)
    .apiKey("my-api-key")
    .secretKey("my-secret-key");
Fireblocks fireblocks = new Fireblocks(configurationOptions);

Examples

Creating a Vault Account

CreateVaultAccountRequest request = new CreateVaultAccountRequest().name("My Vault Account");
String idempotencyKey = Integer.toString(new Random().nextInt()); // String | A unique identifier for the request. If the request is sent multiple times with the same idempotency key, the server will return the same response as the first request. The idempotency key is valid for 24 hours.
// Async request
CompletableFuture<VaultAccount> response = fireblocks.vaults().createVaultAccount(request, idempotencyKey);
// Waiting for the request
VaultAccount vaultAccount = response.get();

Retrieving Vault Accounts

BigDecimal limit = new BigDecimal(10);
CompletableFuture<VaultAccountsPagedResponse> response = fireblocks.vaults().getPagedVaultAccounts(null, null, null, null, null, null, null, limit);
VaultAccountsPagedResponse vaultAccountsPagedResponse = response.get();

Creating a Transaction

TransactionRequest transactionRequest = new TransactionRequest()
    .operation(TransactionOperation.TRANSFER)
    .source(new TransferPeerPath()
        .type(TransferPeerPath.TypeEnum.VAULT_ACCOUNT)
        .id("0"))
    .destination(new DestinationTransferPeerPath()
        .type(DestinationTransferPeerPath.TypeEnum.VAULT_ACCOUNT)
        .id("1"))
    .amount(new TransactionRequestAmount("0.001"))
    .assetId("ETH_TEST3"); // Ethereum Goerli testnet
    .note("My first Java transaction!");
String idempotencyKey = Integer.toString(new Random().nextInt()); // String | A unique identifier for the request. If the request is sent multiple times with the same idempotency key, the server will return the same response as the first request. The idempotency key is valid for 24 hours.
CompletableFuture<CreateTransactionResponse> response = fireblocks.transactions().createTransaction(transactionRequest, null, idempotencyKey);
CreateTransactionResponse transactionResponse = response.get();
String txId = transactionResponse.getId();