Getting Started

Get up and running with Bloque SDK in minutes.

Installation

Install the SDK using your preferred package manager:

npm
yarn
pnpm
bun
deno
npm add @bloque/sdk

API Key

To use the Bloque SDK, you'll need an API key. You can obtain one from the Bloque Dashboard.

Security

Never expose your API key in client-side code. Always use environment variables and keep your keys secure.

Initialize the SDK

Create an instance of the SDK with your API key and mode:

import { SDK } from '@bloque/sdk';

const bloque = new SDK({
  origin: 'your-origin',
  auth: {
    type: 'apiKey',
    apiKey: process.env.BLOQUE_API_KEY!,
  },
  mode: 'production', // or 'sandbox' for testing
});

Configuration Options

OptionTypeRequiredDescription
apiKeystringYesYour Bloque API key
mode'production' | 'sandbox'YesEnvironment mode

Modes

  • sandbox: For testing and development. No real transactions.
  • production: For live operations with real data.

Your First Request

Let's create a virtual card:

import { SDK } from '@bloque/sdk';

const bloque = new SDK({
  apiKey: process.env.BLOQUE_API_KEY!,
  mode: 'production',
});

async function createCard() {
  try {
    const card = await bloque.accounts.card.create({
      urn: 'did:bloque:user:123e4567',
      name: 'My First Card',
    });

    console.log('Card created successfully!');
    console.log('URN:', card.urn);
    console.log('Last four:', card.lastFour);
    console.log('Status:', card.status);
    console.log('Details URL:', card.detailsUrl);
  } catch (error) {
    console.error('Error creating card:', error);
  }
}

createCard();

Error Handling

Always wrap SDK calls in try-catch blocks to handle errors gracefully:

try {
  const card = await bloque.accounts.card.create({
    urn: 'did:bloque:user:123',
    name: 'My Card',
  });
  // Success
} catch (error) {
  if (error instanceof Error) {
    console.error('Failed:', error.message);
  }
  // Handle error
}

TypeScript Support

The SDK is built with TypeScript and provides full type safety:

import type { CardAccount, CreateCardParams } from '@bloque/sdk/accounts';

// Type-safe parameters
const params: CreateCardParams = {
  urn: 'did:bloque:user:123',
  name: 'My Card',
};

// Type-safe response
const card: CardAccount = await bloque.accounts.card.create(params);

Environment Variables

Use environment variables to store your API key securely:

# .env
BLOQUE_API_KEY=your_api_key_here
BLOQUE_MODE=sandbox

Then load them in your application:

import { SDK } from '@bloque/sdk';
import 'dotenv/config'; // or your preferred env loader

const bloque = new SDK({
  origin: 'your-origin',
  auth: {
    type: 'apiKey',
    apiKey: process.env.BLOQUE_API_KEY!,
  },
  mode: process.env.BLOQUE_MODE as 'production' | 'sandbox',
});

Next Steps