
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@electrum-cash/network
Advanced tools
@electrum-cash/network is a lightweight JavaScript library that lets you connect with one or more Electrum servers.
@electrum-cash/network is a lightweight JavaScript
library that lets you connect Electrum
servers.
It offers encrypted connections by default, performs the expected protocol version negotiation and automatically keeps your connection alive until your close it.
Install the library with NPM:
# npm install @electrum-cash/network
To use the library, import the ElectrumClient
into your project:
// Load the electrum library.
import { ElectrumClient } from '@electrum-cash/network';
Initialize and connect the client with your application identifier and protocol version, as well as a hostname to connect to.
// Initialize an electrum client.
const electrumClient = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash');
// Wait for the client to connect.
await electrumClient.connect();
Alternatively, you can provide a pre-configured ElectrumSocket
instead of the hostname:
// Set up your own socket, somehow.
const electrumSocket = new MyElectrumSocketClass();
// Initialize the electrum client.
const electrumClient = new ElectrumClient('Electrum client example', '1.4.1', electrumSocket);
// Wait for the client to connect.
await electrumClient.connect();
Once your ElectrumClient
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 electrumClient.request('blockchain.transaction.get', transactionID);
// Print out the transaction hex.
console.log(transactionHex);
Once your ElectrumClient
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 handleNotifications = function(data)
{
if(data.method === 'blockchain.headers.subscribe')
{
// Print out the block information.
// {
// jsonrpc: '2.0',
// method: 'blockchain.headers.subscribe',
// params:
// [
// {
// height: 797111,
// hex: '002001202a6b1367f68201ad957e95bec9bda3f132ca2fcb75c0c000000000000000000074befba60bd8615d87ddb636aa99bc032cec8db3adb0d915d45391bc811c1e9ceacf89647a60051819a79559'
// }
// ]
// }
console.log(data);
}
}
// Listen for notifications.
electrumClient.on('notification', handleNotifications);
// Set up a subscription for new block headers.
await electrumClient.subscribe('blockchain.headers.subscribe');
When you're done and don't want to be connected anymore you can disconnect the server:
// Close the connection.
await electrumClient.disconnect();
For a complete list of methods and parameters, read the API documentation.
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.
The keep-alive functionality of this library only works when the protocol version is 1.2 or higher.
FAQs
@electrum-cash/network is a lightweight JavaScript library that lets you connect with one or more Electrum servers.
The npm package @electrum-cash/network receives a total of 86 weekly downloads. As such, @electrum-cash/network popularity was classified as not popular.
We found that @electrum-cash/network demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.