Introduction
The @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 generated from the source code.
Usage
Installation
Installation is easy, just get the library from NPM:
npm install @electrum-cash/application
Setup
import { initializeElectrumApplication } from '@electrum-cash/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.
electrumEvents.on('BlockReceived', console.log);
electrumEvents.on('BlockVerified', console.log);
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.
electrumEvents.on('TransactionReceived', console.log);
electrumEvents.on('TransactionVerified', console.log);
electrumEvents.on('TransactionDoubleSpendDetected', console.log);
await monitorTransaction(transactionHash);
await monitorAddress(address);
Tracking address history
After you monitor an address, you get events when an address history is updated.
electrumEvents.on('AddressUpdateReceived', console.log);
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.