Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/interlay/esplora-btc-api

Blockstream Esplora Client (Typescript)
https://github.com/interlay/esplora-btc-api

bitcoin blockstream typescript

Last synced: 19 days ago
JSON representation

Blockstream Esplora Client (Typescript)

Awesome Lists containing this project

README

        

# [Blockstream Esplora](https://github.com/Blockstream/esplora) OpenAPI Spec & Clients

Built using [OpenAPI](https://github.com/OpenAPITools/openapi-generator). Requires [openapi-generator-cli](https://github.com/OpenAPITools/openapi-generator-cli).

```shell
make rust-client
make ts-client
```

## Typescript (Axios)

### Install

```bash
yarn install @interlay/esplora-btc-api
```

### Build

```bash
cd ts-client
yarn install
yarn build
```

### Examples

#### Get the current chain's best height

```typescript
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

```typescript
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();
```