TypeScript SDK

Overview

A Typescript developer can use the Fireblocks API easily with the official TypeScript SDK:

The Fireblocks TypeScript SDK.

In this guide, you'll set up the Fireblocks SDK and see an example of a basic API script to create a vault and retrieve its data.

Additionally if you are developing on EVM chains - you might be using some of the familiar libraries, such as web3.js or ethers.js - Fireblocks is well intergrated into these libraries as described in the Ethereum Development.

Using the Fireblocks SDK

Install Node v16 or newer

The Fireblocks JavaScript SDK requires Node v16 or newer. You can check which version of Node you already have installed by running the following command.

node -v

Learn how to install or update Node to a newer version.

Install fireblocks/ts-sdk

The Fireblocks TypeScript SDK is open-source and is hosted on GitHub.


Installing the latest SDK is easy with npm:

npm install @fireblocks/ts-sdk

Your First Fireblocks TypeScript code example!

Now that you're set up, run a quick check for the API. The examples below will show you how to initialize the Fireblocks SDK, create a new vault account, query Fireblocks to get the vault accounts list and create a basic transfer transaction.

📘

Use the correct API Base URL

In the following script, make sure you're using the correct value for baseUrl 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.

import { readFileSync } from 'fs';
import { Fireblocks, BasePath } from "@fireblocks/ts-sdk";

const FIREBLOCKS_API_SECRET_PATH = "./fireblocks_secret.key";

// Initialize a Fireblocks API instance with local variables
const fireblocks = new Fireblocks({
    apiKey: "my-api-key",
    basePath: BasePath.Sandbox, // or assign directly to "https://sandbox-api.fireblocks.io/v1";
    secretKey: readFileSync(FIREBLOCKS_API_SECRET_PATH, "utf8"),
});


// creating a new vault account
async function createVault() {
    try {
        const vault = await fireblocks.vaults.createVaultAccount({
            createVaultAccountRequest: {
                name: 'My First Vault Account',
                hiddenOnUI: false,
                autoFuel: false
            }
        });
        return vault;
    } catch (e) {
        console.log(e);
    }
}

//retrive vault accounts
async function getVaultPagedAccounts(limit: number) {
    try {
        const vaults = await fireblocks.vaults.getPagedVaultAccounts({
            limit
        });
        return vaults;
    } catch (e) {
        console.log(e);
    }
}

// create a transaction
async function createTransaction(assetId, amount, srcId, destId) {
    let payload = {
        assetId,
        amount,
        source: {
            type: TransferPeerPathType.VaultAccount,
            id: String(srcId)
        },
        destination: {
            type: TransferPeerPathType.VaultAccount,
            id: String(destId)
        },
        note: "Your first transaction!"
    };
    const result = await fireblocks.transactions.createTransaction({ transactionRequest: payload });
    console.log(JSON.stringify(result, null, 2));
}