0.0.1 • Published 2 months ago

@electrum-cash/application v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Introduction

The @electrum-cash/application library provides a robust framework for building SPV-validated tools and services.

Features

  • Full SPV-validation of monitored transactions and blocks.
  • Rich notifications for each step in the transaction, block or address life-cycle.
  • You can ask for partial data without needing to understand how to acquire it.
  • Automatic handling of network edge-cases, fail-over and opportunistic caching.

For complete information on all typings, arguments and options available, read to the documentation generated from the source code.

Trade-offs

  • Full SPV-validation raises network, memory and processing costs.
  • Opportunistic caching raises storage and memory costs.
  • Automatic handling of network edge-cases reduces privacy control.

Usage

Installation

Installation is easy, just get the library from NPM:

npm install @electrum-cash/application

Setup

// Import library features.
import { initializeElectrumApplication } from '@electrum-cash/application';

// Initialize the electrum application.
const electrumEvents = await initializeElectrumApplication('My Electrum Application');

Event handling

Tracking the blockchain

Once you have initialized the electrum application you can monitor when new blocks become available.

// Log when new block headers are available.
electrumEvents.on('BlockReceived', console.log);

// Log when new block headers have been verified.
electrumEvents.on('BlockVerified', console.log);

// Log what chain height and percent of the chain has been verified.
electrumEvents.on('ChainStatus', console.log);

Tracking transactions

After you monitor an address or transaction, you get events for each step in each transactions life-cycle.

// Log when new transactions are available.
electrumEvents.on('TransactionReceived', console.log);

// Log when new transactions are verified.
electrumEvents.on('TransactionVerified', console.log);

// Log when new transactions are doublespent.
electrumEvents.on('TransactionDoubleSpendDetected', console.log);

// Either monitor a specific transaction...
await monitorTransaction(transactionHash);

// .. or all pending transactions for a specific address.
await monitorAddress(address);

Tracking address history

After you monitor an address, you get events when an address history is updated.

// Log when the address history has changed.
electrumEvents.on('AddressUpdateReceived', console.log);

// TODO: Add events for address balance updates.

// Monitor a specific address.
await monitorAddress(address);

Requesting Data

Getting balance, UTXOs and transaction history.

...

Support

If you find bugs or have problems using this library, you can file issues on the Gitlab.