# Introduction

The [`@electrum-cash/application`](https://www.npmjs.com/package/@electrum-cash/application) library provides a robust framework for building SPV-validated tools and services.

- 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](https://electrum-cash.gitlab.io/application/) generated from the source code.

# Usage

## Installation

Installation is easy, just get the library from NPM:

```sh
npm install @electrum-cash/application
```

## Setup

```ts
// 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.

```ts
// 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.

```ts
// 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.

```ts
// 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.

...

```ts
```

## Support

If you find bugs or have problems using this library, you can file issues on the [Gitlab](https://gitlab.com/electrum-cash/application/issues).
