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

truffle-ext

v0.1.8

Published

Extends truffle artifacts to provide state and event logging

Downloads

6

Readme

truffle-ext

Extends truffle artifacts to provide state and event logging

Installation

yarn install

Usage

import the truffle-ext function and call it with your web3 instance. Use the requireContract function by passing it a truffle contract artifact.

  import truffleExt from 'truffle-ext'
  const { requireContract } = truffleExt(web3)
  const MyContract = requireContract(
    artifacts.require('./MyContract.sol')
  )

The returned contract instance provides the same functions as the truffle artifact. For example, call .new() to deploy a new instance of the contract

  const myContract = await MyContract.new()

You can also use .at() or .deployed()

State Logging

Use the asynchronous state() function to get current contract state

  let state = await myContract.state()

The state object provides an output() function, which returns human readable output for the state object

  console.log(state.output())
  # example output

  MyContract
  -----------------
  Address:     0x8a7dcafdda1707289a40a6bd701a6b8fb788cd34
  Balance:     0
  Calls:
    fooInt(): 0
    fooAddress(): 
      Address: 0xc32de2edac1bec88174b15dc0b6c412b4b23c302
      Balance: 48080040500000000000
    bar(): true

Options can be passed to the state() function to make multiple parameterized calls

  state = await myToken.state({
    calls: [
      ['balanceOf', '0x6704fbfcd5ef766b287262fa2281c105d57246a6'],
      ['balanceOf', '0x9e1ef1ec212f5dffb41d35d9e5c14054f26c6560'],
      ['balanceOf', '0xce42bdb34189a93c55de250e011c68faee374dd3']
    ]
  })
  console.log(state.output())
  # example output

  MyToken
  ----------
  Address:     0x6b9857484ce82c9cc053b18c07841631b8e74fe2
  Balance:     150000000000000000000
  Calls:
    name(): My Token
    totalSupply(): 50000000000000000000
    decimals(): 18
    symbol(): TKN
    balanceOf(0x6704fbfcd5ef766b287262fa2281c105d57246a6): 50000000000000000000
    balanceOf(0x9e1ef1ec212f5dffb41d35d9e5c14054f26c6560): 50000000000000000000
    balanceOf(0xce42bdb34189a93c55de250e011c68faee374dd3): 50000000000000000000

Transaction Logging

Execute transactions as you would with truffle

  let tx = await myContract.updateSomeState(1000)

Transactions return an object that provides an output() function to get human readable output for the events that were called during the transaction

  console.log(tx.output())
  # example output

  Events
  ------
  
  SomeStateUpdated (
    stateValue: 1000
  )

  OtherStateUpdated (
    someOtherState: true
  )

Event logging

Log all events for an instance of a contract by calling logAllEvents()

  myContract.logAllEvents()

Or log all events for all contract instances by calling truffleExt with logEvents: true option

  const { requireContract } = truffleExt(web3, { logEvents: true })
  # example output

  MyContract.SomeEvent (
    fooAddress: 0xf9c1705fd0945258023af32ddc911bbedb6ca123
    barInt: 0
  )

  OtherContract.SomeOtherEvent (
    foo: false
  )