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

v0.1.10

Published

Collection of tools to simplify interaction with the Ethereum blockchain

Downloads

5

Readme

web3-tools

A collection of tools to interact with the Ethereum blockchain through a web3 instance.

Installation

Node.js

npm install --save web3-tools

Browser

Browser package is currently not available. Stay tuned. For now, you can use browserify.

Usage

The library is initialized with a web3 instance. It exports an object with uncomplicated, easy to use functions.

const web3 = someWeb3Instance // requires web3 1.0
const {deployContract, sendTransaction} = require('web3-tools')(web3)

All functions of the library return a promise that resolves to a transaction receipt as soon as the contract is mined. A transaction receipt (for example for contract deployment) looks like this:

{ blockHash: '0x2e16f86b70d4c8f89f442295584017590b7b3ac0d27847b0e04df64bd5aa7a89',
  blockNumber: 4652060,
  contractAddress: '0x86Af6004557039b52666b0B58eb052E6Ddeeb1Af',
  cumulativeGasUsed: 1649769,
  gasUsed: 1649769,
  logs: [],
  logsBloom: '0x00000....',
  root: null,
  status: null,
  transactionHash: '0xb9de15fc9197d0501873445674b253aa0469e8e50d090609b80082bc503733d7',
  transactionIndex: 0 }

deployContract

Deploy a contract on the blockchain.

Parameters

  1. options
    • options.contractJSON: The compiled JSON of the contract
    • options.from: The contract creator address. Use your public ethereum address here.
    • options.fromKey: The private key belonging to the creator.
    • options.args: Arguments passed to the constructor.
    • options.maxGas: The maximum amount of gas to pay. Promise will reject if too low.

Returns

A promise that resolves to the transaction receipt when the transaction is mined.

Example

let options = {
    maxGas: 3000000,
    contractJSON: fs.readFileSync("./mycontract.json").toString(),
    from: '0x11b1EeC366d1e79923c15514f1B8C014Ce780c8D',
    fromKey: Buffer.from('f8ce489f073b6aa62b8841894e42b0fac0b522185dc350af0a4f2ce3b43633a9', 'hex'),
    args: []
}

deployContract(options)
.then(function(receipt) {
  console.log('Contract deployed at ' + receipt.contractAddress)
})
.catch(console.error)

sendTransaction

Call a method of a deployed contract. Will send a transaction to the network.

Parameters

  1. options
    • options.methodName: The name of the method to be called
    • options.contractAddress: The address of the contract
    • options.contractABI: The compiled ABI of the contract
    • options.from: The caller address. Use your public ethereum address here.
    • options.fromKey: The private key belonging to the caller.
    • options.args: Array of arguments to be passed to the method.
    • options.maxGas: The maximum amount of gas to pay. Promise will reject if too low.

Returns

A promise that resolves to the transaction receipt when the transaction is mined.

Example

let options = {
    maxGas: 10000,
    methodName: 'sendTokens',
    contractAddress: '0x6dc1733d8c009e908274c055e2656ad3f45a860f',
    contractABI: fs.readFileSync("./mycontract.abi").toString(),
    from: '0x11b1EeC366d1e79923c15514f1B8C014Ce780c8D',
    fromKey: Buffer.from('f8ce489f073b6aa62b8841894e42b0fac0b522185dc350af0a4f2ce3b43633a9', 'hex'),
    args: ['0x11b1EeC366d1e79923c15514f1B8C014Ce780c8D', 100]
}

sendTransaction(options)
.then(function(receipt) {
  console.log('Done')
})
.catch(console.error)

Contributing

We could use some tests. Pull requests are welcome.