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

web3-plugin-faucettestnet2

v1.0.1

Published

A web3.js Faucet Plugin for Testnets using web3.js, Tableland, and smart contracts

Downloads

4

Readme

web3.js Faucet Plugin for Testnets

(created using the ChainSafe/Web3.js web3-plugin-template)

Overview

The Faucet Plugin is a utility designed to facilitate interactions with the Ethereum blockchain through the Web3.js library. It provides functionality for preparing and sending transactions, specifically tailored to request Ether from a faucet. This plugin is part of a larger ecosystem that aims to simplify managing and interacting with Ethereum assets.

Features Preparation of Transactions: The plugin offers a method to prepare a transaction requesting Ether from a faucet. This involves creating a transaction object with the recipient's address, the amount of Ether requested, and other necessary details such as gas limit and nonce.

Future Features (the vision) User request handling: Request validation—Validates user requests to ensure they meet the criteria for receiving Ether (e.g., valid Ethereum address format). Rate limiting—Implements rate limiting to prevent abuse of the faucet and ensure fair distribution of Ether.

Database integration with Tableland: Address Verification—Checks the Tableland database to verify if a user’s address has already claimed Ether, preventing double-spending. Claim Record Management—Updates the Tableland database to mark an address as having claimed Ether after a successful transaction.

Ethereum Blockchain Interaction: Transaction Sending—Uses web3.js to send transactions from the faucet’s Ethereum address to the user’s address, transferring the requested amount of testnet Ether. Gas Management—Automatically sets appropriate gas prices and gas limits for transactions to ensure they are processed efficiently.

Smart Contract Support (Optional): Contract Interaction—If the faucet uses smart contracts for more complex logic (e.g., time-locked claims), the plugin can interact with these contracts using web3.js. Event Listening—The plugin listens for specific events emitted by the smart contracts to trigger actions (e.g., updating the database when a user claims Ether).

User feedback and Error handling: Confirmation Messages provide feedback to the user upon successful Ether distribution, including the transaction hash for verification.

Security Measures: Secure Storage of Private Keys—Ensures that the faucet’s private key is securely stored and not exposed, protecting the faucet’s funds. Encryption—Uses encryption for sensitive data, such as API keys for Tableland, to enhance security.

Customization and Extensibility: Customizable Rules allow for customization of rules, such as the amount of Ether distributed per request or the eligibility criteria.

Usage

Installation To use the Faucet Plugin, ensure you have Node.js installed on your system. Then, create a new project directory and initialize a new Node.js project:

mkdir my-project && cd my-project npm init -y

Install the required dependencies npm install web3 crypto-js

Implementation First, import the necessary modules and define the FaucetPlugin class:

import Web3 from 'web3';
import crypto from 'crypto';

const generateMockPrivateKey = (): string => {
  return '0x' + crypto.randomBytes(32).toString('hex');
};

const mockPrivateKey = generateMockPrivateKey();

export class FaucetPlugin {
  public pluginNamespace = "faucet";
  public web3: Web3;

  constructor(web3Instance: Web3) {
    this.web3 = web3Instance;
  }

  public async requestEther(address: string, amount: number): Promise<any> {
    // Implementation details...
  }

  public async signAndSendTransaction(transaction: any, privateKey: string): Promise<any> {
    // Implementation details...
  }
}

Example Usage

Here's an example of how to instantiate the FaucetPlugin and use its methods:

const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

const faucetPlugin = new FaucetPlugin(web3);

// Prepare a transaction
const transaction = await faucetPlugin.requestEther('0xRecipientAddress', 10);

// Sign and send the transaction
const signedTransaction = await faucetPlugin.signAndSendTransaction(transaction, mockPrivateKey);

Testing

The Faucet Plugin supports unit testing to ensure its functionality remains intact. Jest is recommended for testing due to its simplicity and integration with JavaScript projects. Install Jest and its types:

npm install --save-dev jest @types/jest ts-jest

Configure Jest to work with TypeScript by adding a jest.config.js file:

module.exports = { preset: 'ts-jest', testEnvironment: 'node', }; Write tests for the FaucetPlugin methods to verify their correctness and edge cases.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT