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-simplifier

v0.0.7

Published

A simple web3 wrapper for nodejs

Downloads

485

Readme

Web3 Simplifier

web3-simplifier is a simple utility package that simplifies interactions with the Ethereum blockchain using the popular web3.js library. It provides a set of easy-to-use methods for common blockchain tasks such as querying balances, sending transactions, interacting with smart contracts, and more.

Installation

You can install the web3-simplifier package via npm:

npm install web3-simplifier
const Web3Utils = require('web3-simplifier');

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

const balance = await web3Utils.getBalance('0x1234...abcd');
console.log(balance); // e.g., "1.0"


const chainId = await web3Utils.getChainId();
console.log(chainId); // e.g., 1


const currentBlock = await web3Utils.getCurrentBlock();
console.log(currentBlock); // e.g., 1234567


const gasPrice = await web3Utils.getGasPrice();
console.log(gasPrice); // e.g., "20000000000" (20 Gwei)


const txCount = await web3Utils.getBlockTransactionCount(12345); // 12345 is block number
console.log(txCount); // e.g., 10


const blockDetails = await web3Utils.getBlock(12345);  // 12345 is block number
console.log(blockDetails);


const txDetails = await web3Utils.getTransaction('0x1234...abcd'); // transaction hash
console.log(txDetails);


const pendingTxs = await web3Utils.getPendingTransactions();
console.log(pendingTxs);


const txFromBlock = await web3Utils.getTransactionFromBlock(12345, 0); // 12345 is block number , 0 is index
console.log(txFromBlock);

// index means block transactions list index number if block contains 100 transaction index is 5 then return  5th transaction details 

const receipt = await web3Utils.getTransactionReceipt('0x1234...abcd');  // transaction hash
console.log(receipt);

// this return the logs and other details of transaction

const txCount = await web3Utils.getTransactionCount('0x1234...abcd'); // user address
console.log(txCount); // e.g., 5

// this return the nounce of the address that means addres transaction count 

const newAddress = await web3Utils.createAddress();
console.log(newAddress);

var transferData = {
            from_address: "From Address",
            to_address: "To Address",
            privatekey: "From Address Private Key",
            amount: "Transfer Amount in String Format like 0.01 or 1",
            gas: "gas Amount to Spend like 21000 for basic Transaction need"
        }

const transferData = {
    from_address: '0x1234...abcd',
    to_address: '0x5678...efgh',
    privatekey: '0xabcdef...',
    amount: '1',
    gas: '21000'
};

const transferReceipt = await web3Utils.transferAmount(transferData);
console.log(transferReceipt);

const decodedLog = await web3Utils.decodeLogsParameter('uint256', '0x1234...abcd'); //uint256 is type, topic
console.log(decodedLog);
// type must be uint256 or string or address 

const result = await web3Utils.contractCall(Abi, '0xContractAddress', 'balanceOf', ['0x1234...abcd']); // abi, contract address, function name, params
console.log(result);
// parameters in Array format what are the inputs are given. if no parameters are given then give the empty array.


const tokenBalance = await web3Utils.getContractBalance(Abi, '0xTokenContractAddress', '0x1234...abcd'); // abi, contract address, user address
console.log(tokenBalance);

const txReceipt = await web3Utils.contractSend(Abi, '0xContractAddress', 'approve', '0x1234...abcd', '0xPrivateKey', ['0x5678...efgh', '1000000000000000000']);
                                                // abi, contract address, function name, from address, privatekey, params
console.log(txReceipt);

  let fileContent = fs.readFileSync(path.join(__dirname, './Storage.sol'), 'utf8');
    
    // Deploy the contract using web3Utils
    const test = await web3Utils.deployContractFromFile(
        'v0.5.16+commit.9c3226ce', // Solidity version
        fileContent,               // Contract file content
        'Storage.sol',     // Contract file name
        'Storage',         // Contract name (constructor function name)
        '0xa073d0eA2.....142ae62Fc',  // Deployer address
        '3c7a6.............324h3424hc', // Private key (use environment variable for security)
        ['0xa073d0e........62Fc'] // Constructor arguments (example)
    );