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

saksh-eth-wallet

v1.0.5

Published

A package to generate Ethereum addresses, monitor payments, send ETH, get transaction reports, and check balances in ETH and USD.

Downloads

248

Readme

eth-payment-monitor

A package to generate Ethereum addresses, monitor payments, send ETH, get transaction reports, and check balances in ETH and USD.

Installation

To install the package, use npm:

npm install saksh-eth-wallet

Configuration

Create a .env file in the root directory of your project and add the following content:

MONGODB_URI=mongodb://localhost:27017/eth-monitor
ALCHEMY_API_KEY=your_alchemy_api_key
COINLAYER_API_KEY=your_coinlayer_api_key

Replace your_alchemy_api_key, your_coinlayer_api_key, and mongodb://localhost:27017/eth-monitor with your actual details.

Usage

Here's an example of how to use the package:


const {
    sakshSetConfig,
    sakshGenerateMnemonic,
    sakshCreateUser,
    sakshGenerateAddressForUser,
    sakshGetUserAddresses,
    sakshGetETHBalance,
    sakshGetETHBalanceInUSD,
    sakshGetUserBalances,
    sakshGetUsersWithBalance,
    sakshMonitorAddresses,
    sakshSetGlobalCallback
} = require('saksh-eth-wallet'); // Replace with the actual file name

// Example usage
async function exampleUsage() {
    // Set the configuration
    sakshSetConfig(() => ({
        MONGODB_URI: 'your_mongodb_connection_string',
        ALCHEMY_API_KEY: 'your_alchemy_api_key',
        COINLAYER_API_KEY: 'your_coinlayer_api_key'
    }));

    // Generate a new mnemonic
    const mnemonic = sakshGenerateMnemonic();
    console.log('Generated Mnemonic:', mnemonic);

    // Create a new user
    const userId = 'user123';
    const user = await sakshCreateUser(userId);
    console.log('Created User:', user);

    // Define a callback function
    const callback = function (transaction) {
        console.log('Payment received:', transaction);
        // Add your notification logic here (e.g., send an email or SMS)
    };

    // Generate an address for the user with a callback function
    const addressData = await sakshGenerateAddressForUser(userId, "m/44'/60'/0'/0/0", callback);
    console.log('Generated Address:', addressData);

    // Set a global callback function
    sakshSetGlobalCallback(function (transaction) {
        console.log('Global callback - Payment received:', transaction);
        // Add your global notification logic here
    });

    // Get all addresses for the user
    const addresses = await sakshGetUserAddresses(userId);
    console.log('User Addresses:', addresses);

    // Get the ETH balance of an address
    const ethBalance = await sakshGetETHBalance(addressData.address);
    console.log('ETH Balance:', ethBalance);

    // Get the ETH balance in USD for an address
    await sakshGetETHBalanceInUSD(addressData.address, (balance) => {
        console.log('ETH Balance in USD:', balance);
    });

    // Get the balances for all addresses of the user
    await sakshGetUserBalances(userId, (balances) => {
        console.log('User Balances:', balances);
    });

    // Get user IDs with at least one address having a balance greater than zero
    const usersWithBalance = await sakshGetUsersWithBalance();
    console.log('Users with Balance:', usersWithBalance);

    // Monitor addresses and send notifications
    sakshMonitorAddresses();
}

exampleUsage().catch(console.error);

Functions

sakshSetConfig(callback)

Sets the configuration for the package. The callback function should return an object containing the necessary configuration data.

Parameters:

  • callback (Function): A function that returns an object with the following properties:
    • MONGODB_URI (String): MongoDB connection string.
    • ALCHEMY_API_KEY (String): Alchemy API key.
    • COINLAYER_API_KEY (String): Coinlayer API key.

Example:

sakshSetConfig(() => ({
  MONGODB_URI: 'your_mongodb_connection_string',
  ALCHEMY_API_KEY: 'your_alchemy_api_key',
  COINLAYER_API_KEY: 'your_coinlayer_api_key'
}));

sakshGenerateMnemonic()

Generates a new mnemonic phrase.

Returns:

  • String: A new mnemonic phrase.

Example:

const mnemonic = sakshGenerateMnemonic();
console.log('Generated Mnemonic:', mnemonic);

sakshCreateUser(userId)

Creates a new user with a mnemonic.

Parameters:

  • userId (String): The user ID.

Returns:

  • Object: The created user object.

Example:

const user = await sakshCreateUser('user123');
console.log('Created User:', user);

sakshGenerateAddressForUser(userId, path, callback)

Generates an address for a given user ID.

Parameters:

  • userId (String): The user ID.
  • path (String, optional): The derivation path (default: "m/44'/60'/0'/0/0").
  • callback (Function, optional): A callback function to be called when a payment is received.

Returns:

  • Object: The generated address data.

Example:

const addressData = await sakshGenerateAddressForUser('user123', "m/44'/60'/0'/0/0", function(transaction) {
  console.log('Payment received:', transaction);
});
console.log('Generated Address:', addressData);

sakshGetUserAddresses(userId)

Gets all addresses for a given user ID.

Parameters:

  • userId (String): The user ID.

Returns:

  • Array: An array of address objects.

Example:

const addresses = await sakshGetUserAddresses('user123');
console.log('User Addresses:', addresses);

sakshGetETHBalance(address)

Gets the ETH balance of an address.

Parameters:

  • address (String): The Ethereum address.

Returns:

  • String: The ETH balance.

Example:

const ethBalance = await sakshGetETHBalance('0xYourAddress');
console.log('ETH Balance:', ethBalance);

sakshGetETHBalanceInUSD(address, callback)

Gets the ETH balance in USD for an address.

Parameters:

  • address (String): The Ethereum address.
  • callback (Function): A callback function to handle the balance data.

Example:

await sakshGetETHBalanceInUSD('0xYourAddress', (balance) => {
  console.log('ETH Balance in USD:', balance);
});

sakshGetUserBalances(userId, callback)

Gets the balances for all addresses of a user.

Parameters:

  • userId (String): The user ID.
  • callback (Function): A callback function to handle the balances data.

Example:

await sakshGetUserBalances('user123', (balances) => {
  console.log('User Balances:', balances);
});

sakshGetUsersWithBalance()

Gets user IDs with at least one address having a balance greater than zero.

Returns:

  • Array: An array of user IDs.

Example:

const usersWithBalance = await sakshGetUsersWithBalance();
console.log('Users with Balance:', usersWithBalance);

sakshMonitorAddresses()

Monitors addresses and sends notifications when a payment is received. Calls both the address-specific and global callback functions.

Example:

sakshMonitorAddresses();

sakshSetGlobalCallback(callback)

Sets a global callback function that will be called whenever a payment is received.

Parameters:

  • callback (Function): A callback function to handle the transaction data.

Example:

sakshSetGlobalCallback(function(transaction) {
  console.log('Global callback - Payment received:', transaction);
});

This formatting uses headings, lists, and code blocks to improve readability and organization, making it suitable for GitHub documentation.






### License
This project is licensed under the MIT License.


### Support
Susheel2339 at gmail.com