Skip to content

interlay/esplora-btc-api

Repository files navigation

Blockstream Esplora OpenAPI Spec & Clients

Built using OpenAPI. Requires openapi-generator-cli.

make rust-client
make ts-client

Typescript (Axios)

Install

yarn install @interlay/esplora-btc-api

Build

cd ts-client
yarn install
yarn build

Examples

Get the current chain's best height

import * as esplora from '@interlay/esplora-btc-api';

async function main() {
    let result = await new esplora.BlockApi().getLastBlockHeight();
    console.log(result.data);
}

main();

Get a raw block and extract the header

import * as esplora from '@interlay/esplora-btc-api';

async function main() {
    const api = new esplora.BlockApi();
    const result = await api.getBlockRaw("$HASH", {responseType: 'arraybuffer'});
    console.log(result.data.slice(0, 80).toString('hex'));
}

main();