Files
trezor-suite/packages/blockchain-link/README.md
Daniel Suchý 6253be3f9f chore: Prettier refactor, update, add CI check (#4950)
* chore: remove redundant prettier, gitignore files

* fix: Fix missign html opening tag

* chore: upgrade prettier

* chore(ci): Add prettier check to CI

* chore(eslint): turn off prettier-eslint

* chore: fix formatting of translations

* chore: run prettier over whole codebase
2022-02-17 18:15:59 +01:00

2.3 KiB

@trezor/blockchain-link

blockchain-link is a client and unified interface for several backends (BE further on) of various blockchain networks. Currently, there are implementations for

  • blockbook: BE developed and deployed by SatoshiLabs. Provides access to Bitcoin(like) and Ethereum(like) networks.
  • ripple: third party BE that provides access to the Ripple network.
  • blockfrost: third party BE that provides access to the Cardano network.
  • electrum: protocol implemented by multiple third party backends that provide access to the Bitcoin network.

Usage

Add blockchain-link to your dependencies.

yarn add @trezor/blockchain-link

And use it.

import BlockchainLink from '@trezor/blockchain-link';
import Blockbook from '@trezor/blockchain-link/lib/workers/blockbook';

const link = new BlockchainLink({
    name: 'Name used in logs.',
    worker: Blockbook,
    server: ['url1.of.the.be', 'url2.of.the.be'],
    debug: true,
});

try {
    const resp = link.getInfo();
} catch (error) {}

For complete API see the methods of BlockchainLink class in index.ts.

Workers

Each src/workers/*/index file can be used in WebWorker thread. Built from source using webpack worker-loader:

import BlockbookWorker from 'worker-loader?filename=workers/blockbook-worker.[hash].js!@trezor/blockchain-link/lib/workers/blockbook/index.js';

Development

This package provides a simple testing UI for playing around with various implementations and BEs. Run UI with webworkers support

yarn workspace @trezor/blockchain-link dev

or without webworkes support (workers are compiled into a bundle)

yarn workspace @trezor/blockchain-link dev:module

Tests

yarn workspace @trezor/blockchain-link lint
yarn workspace @trezor/blockchain-link type-check
yarn workspace @trezor/blockchain-link test:unit

Integration tests

Testing lib and build outputs:

yarn workspace @trezor/blockchain-link build:lib
yarn workspace @trezor/blockchain-link build:workers
yarn workspace @trezor/blockchain-link test:integration

Publishing

Follow instructions how to publish @trezor package to npm registry.