Skip to content
Vladimir Volek edited this page Jul 19, 2021 · 8 revisions

master build ci npm version downloads

blockfrost-js

A JavaScript/Typescript SDK for Blockfrost.io API.

Getting startedInstallationUsage


Getting started

To use this SDK, you first need login into to blockfrost.io create your project to retrive your API token.


Installation

The SDK is hosted on npmjs.com, so you can directly import it using your favorite package manager.

$ yarn add @blockfrost/blockfrost-js

Usage

Using the SDK is pretty straight-forward as you can see from the following examples.

Cardano

import { BlockfrostAPI } from '@blockfrost/blockfrost-js';

const API = new BlockFrostAPI({
  projectId: 'YOUR API KEY HERE', // see: https://blockfrost.io
});

try {
  const latestBlock = await API.blocksLatest();
  const latestEpoch = await API.epochsLatest();
  const health = await API.health();
  const address = await API.addresses(
    'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz',
  );

  console.log('address', address);
  console.log('latestEpoch', latestEpoch);
  console.log('latestBlock', latestBlock);
  console.log('health', health);
} catch (err) {
  console.log('error', err);
}

IPFS

import { BlockfrostIPFS } from '@blockfrost/blockfrost-js';
import fs from 'fs';

const IPFS = new BlockFrostIPFS({
  projectId: 'YOUR IPFS KEY HERE', // see: https://blockfrost.io
});

try {
  const stream = fs.createReadStream(`${__dirname}/img.svg`);
  const added = await IPFS.add(stream);

  console.log('added', added);

  const pinned = await IPFS.pin(added.ipfs_hash);

  console.log('pinned', pinned);
} catch (err) {
  console.log('error', err);
}

For a more detailed list of possibilities, check out the wiki.

@blockfrost/blockfrost-js

Clone this wiki locally