> ## Documentation Index
> Fetch the complete documentation index at: https://developers.fireblocks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java SDK

> [!NOTE]
>
> **Install the Fireblocks Documentation MCP first.** Whether you're using an AI assistant or not, this makes it easy to search, reference, and keep your Fireblocks work grounded in the official docs. [Set up your AI agent](https://developers.fireblocks.com/docs/building-with-ai.md#fireblocks-documentation-mcp) with one copied prompt, or follow the manual steps in [Getting Started](https://developers.fireblocks.com/docs/quickstart.md).

Java developers can use [the official Fireblocks Java SDK](https://github.com/fireblocks/java-sdk) to interact with the Fireblocks API. Instructions for setup and usage can be found in the repo's README.md file.

# Using the Fireblocks Java SDK

Building the API client library requires:

1. Java 11+
2. Maven/Gradle

## Installation

### Maven users

Add this dependency to your project's POM:

```xml theme={"system"}
<dependency>
  <groupId>com.fireblocks.sdk</groupId>
  <artifactId>fireblocks-sdk</artifactId>
  <version>33.0.0</version>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy theme={"system"}
implementation 'com.fireblocks.sdk:fireblocks-sdk:33.0.0'
```

Check the [Java SDK releases](https://github.com/fireblocks/java-sdk/releases) for the latest version.

## Getting Started

### Initiate Fireblocks Client

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

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

> [!NOTE]
>
> **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 US Mainnet or Testnet workspaces: `https://api.fireblocks.io`
> * For EU Mainnet or Testnet workspaces: `https://eu-api.fireblocks.io`
> * For EU2 Mainnet or Testnet workspaces: `https://eu2-api.fireblocks.io`
>
> [Learn more about workspace differences](https://developers.fireblocks.com/docs/workspace-environments.md).

Use bash commands to set environment variables:

```bash theme={"system"}
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:

```java theme={"system"}
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:

```java theme={"system"}
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

```java theme={"system"}
CreateVaultAccountRequest request = new CreateVaultAccountRequest().name("My Vault Account");
String idempotencyKey = UUID.randomUUID().toString(); // 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<ApiResponse<VaultAccount>> response = fireblocks.vaults().createVaultAccount(request, idempotencyKey);
// Waiting for the request
VaultAccount vaultAccount = response.get().getData();
```

### Retrieving Vault Accounts

```java theme={"system"}
BigDecimal limit = new BigDecimal(10);
CompletableFuture<ApiResponse<VaultAccountsPagedResponse>> response = fireblocks.vaults().getPagedVaultAccounts(null, null, null, null, null, null, null, limit, null, null, null);
VaultAccountsPagedResponse vaultAccountsPagedResponse = response.get().getData();
```

### Creating a Transaction

```java theme={"system"}
TransactionRequest transactionRequest = new TransactionRequest()
    .operation(TransactionOperation.TRANSFER)
    .source(new SourceTransferPeerPath()
        .type(TransferPeerPathType.VAULT_ACCOUNT)
        .id("0"))
    .destination(new DestinationTransferPeerPath()
        .type(TransferPeerPathType.VAULT_ACCOUNT)
        .id("1"))
    .amount(new TransactionRequestAmount("0.001"))
    .assetId("ETH_TEST")
    .note("My first Java transaction!")
    .externalTxId("<YOUR_UNIQUE_ID>"); // Optional - Your unique ID; Fireblocks rejects later requests with the same value
// Use externalTxId, not an idempotency key, for transactions: an idempotency key expires after 24 hours
CompletableFuture<ApiResponse<CreateTransactionResponse>> response = fireblocks.transactions().createTransaction(transactionRequest, null, null);
CreateTransactionResponse transactionResponse = response.get().getData();
String txId = transactionResponse.getId();
```
