npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electrum-cash-react-native

v2.0.10

Published

electrum-cash-react-native is a fork of electrum-cash: a lightweight JavaScript library that lets you connect with one or more Electrum servers.

Downloads

1

Readme

electrum-cash-react-native

React Native notes

electrum-cash-react-native is a very minimal fork of electrum-cash, adding compatiblity for React Native by replacing the Node-only modules net, tls and fs with react-native-tcp-socket.

Replace:

const { ElectrumClient } = require("electrum-cash");

with

import { ElectrumClient } from "electrum-cash-react-native";

Electrum-cash documentation

Electrum-cash is a lightweight JavaScript library that lets you connect with one or more Electrum servers. It offers encrypted connections by default, performs the expected protocol version negotiation and automatically keeps your connection alive until your close it.

Installation

Install the library with NPM:

# npm install electrum-cash

Usage

Load library

Before you can use the library you need to include it in your project.

If you only want to use a single server, load the ElectrumClient module:

// Load the electrum library.
const { ElectrumClient } = require("electrum-cash");

If you want to use multiple servers, load the ElectrumCluster module:

// Load the electrum library.
const { ElectrumCluster } = require("electrum-cash");

Connect to servers

After you have loaded the appropriate module you need to initialize the module by configuring your application identifier and protocol version.

If you only want to use a single server, initialize an ElectrumClient and connect to the server:

// Initialize an electrum client.
const electrum = new ElectrumClient(
  "Electrum client example",
  "1.4.1",
  "bch.imaginary.cash"
);

// Wait for the client to connect
await electrum.connect();

If you want to use multiple servers, initialize an ElectrumCluster and add some servers:

For more information on various cluster configurations, read the cluster documentation.

// Initialize an electrum cluster where 2 out of 3 needs to be consistent, polled randomly with fail-over (default).
const electrum = new ElectrumCluster("Electrum cluster example", "1.4.1", 2, 3);

// Add some servers to the cluster.
electrum.addServer("bch.imaginary.cash");
electrum.addServer("electroncash.de");
electrum.addServer("electroncash.dk");
electrum.addServer("electron.jochen-hoenicke.de", 51002);
electrum.addServer("electrum.imaginary.cash");

// Wait for enough connections to be available.
await electrum.ready();

Request information

Once your ElectrumClient or ElectrumCluster is connected and ready, you can call methods:

For a list of methods you can use, refer to the Electrum Cash documentation.

// Declare an example transaction ID.
const transactionID =
  "4db095f34d632a4daf942142c291f1f2abb5ba2e1ccac919d85bdc2f671fb251";

// Request the full transaction hex for the transaction ID.
const transactionHex = await electrum.request(
  "blockchain.transaction.get",
  transactionID
);

// Print out the transaction hex.
console.log(transactionHex);

Subscribe to notifications.

Once your ElectrumClient or ElectrumCluster is connected and ready, you can set up subscriptions to get notifications on events:

For a list of methods you can subscribe to, refer to the Electrum Cash documentation.

// Set up a callback function to handle new blocks.
const handleNewBlocks = function (data) {
  // Print out the block information.
  console.log(data);
};

// Set up a subscription for new block headers and handle events with our callback function.
await electrum.subscribe(handleNewBlocks, "blockchain.headers.subscribe");

Shutting down

When you're done and don't want to be connected anymore you can disconnect the server(s).

If you're using a single ElectrumClient, call the disconnect() function:

// Close the connection.
await electrum.disconnect();

If you're using a ElectrumCluster with multiple servers, call the shutdown() function.

// Close all connections.
await electrum.shutdown();

Documentation

For a complete list of methods and parameters, read the API documentation.

Support and communication

If you need help with how to use the library or just want to talk about electrum-cash, you can find us on Telegram and Discord.

You can also read our tutorials on read.cash, or share your own.

Notes

The keep-alive functionality of this library only works when the protocol version is 1.2 or higher.