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

@0yi0/ethereumjs-vm

v4.0.0-0.0.1

Published

An Ethereum VM implementation

Downloads

7

Readme

SYNOPSIS

NPM Package Build Status Coverage Status Gitter

js-standard-style

Implements Ethereum's VM in Javascript.

Fork Support

The VM currently supports the following hardfork rules:

  • Byzantium
  • Constantinople
  • Petersburg (default)
  • Istanbul (DRAFT)

If you are still looking for a Spurious Dragon compatible version of this library install the latest of the 2.2.x series (see Changelog).

Istanbul Harfork Support

With the v4.0.0 release we are starting to add implementations of EIPs being candidates or accepted for inclusion within the Istanbul hardfork. You can activate a preliminary Istanbul VM by using the istanbul hardfork option flag.

Currently supported Istanbul EIPs:

  • EIP-1108 (Candidate): alt_bn128 Gas Cost Reductions, see PR #540

Note that this is highly experimental and solely meant for experimental purposes, since Istanbul scope is not yet finalized and most EIPs are still in a DRAFT state and likely subject to updates and changes.

A final Istanbul VM will be released along a major version bump to likely v5.0.0 or v6.0.0.

Have a look at the corresponding issue to follow the discussion and current state on Istanbul planning.

INSTALL

npm install ethereumjs-vm

USAGE

const BN = require('bn.js')
var VM = require('ethereumjs-vm').default

// Create a new VM instance
// For explicity setting the HF use e.g. `new VM({ hardfork: 'petersburg' })`
const vm = new VM()

const STOP = '00'
const ADD = '01'
const PUSH1 = '60'

// Note that numbers added are hex values, so '20' would be '32' as decimal e.g.
const code = [PUSH1, '03', PUSH1, '05', ADD, STOP]

vm.on('step', function(data) {
  console.log(`Opcode: ${data.opcode.name}\tStack: ${data.stack}`)
})

vm.runCode({
  code: Buffer.from(code.join(''), 'hex'),
  gasLimit: new BN(0xffff),
})
  .then(results => {
    console.log('Returned : ' + results.returnValue.toString('hex'))
    console.log('gasUsed  : ' + results.gasUsed.toString())
  })
  .catch(err => console.log('Error    : ' + err))

Example

This projects contain the following examples:

  1. ./examples/run-blockchain: Loads tests data, including accounts and blocks, and runs all of them in the VM.
  2. ./examples/run-code-browser: Show how to use this library in a browser.
  3. ./examples/run-solidity-contract: Compiles a Solidity contract, and calls constant and non-constant functions.
  4. ./examples/run-transactions-complete: Runs a contract-deployment transaction and then calls one of its functions.
  5. ./examples/decode-opcodes: Decodes a binary EVM program into its opcodes.

All of the examples have their own README.md explaining how to run them.

BROWSER

To build for standalone use in the browser, install browserify and check run-transactions-simple example. This will give you a global variable EthVM to use. The generated file will be at ./examples/run-transactions-simple/build.js.

API

VM

For documentation on VM instantiation, exposed API and emitted events see generated API docs.

StateManger

The API for the StateManager is currently in Beta, separate documentation can be found here, see also release notes from the v2.5.0 VM release for details on the StateManager rewrite.

Internal Structure

The VM processes state changes at many levels.

  • runBlockchain
    • for every block, runBlock
  • runBlock
    • for every tx, runTx
    • pay miner and uncles
  • runTx
    • check sender balance
    • check sender nonce
    • runCall
    • transfer gas charges
  • runCall
    • checkpoint state
    • transfer value
    • load code
    • runCode
    • materialize created contracts
    • revert or commit checkpoint
  • runCode
    • iterate over code
    • run op codes
    • track gas usage
  • OpFns
    • run individual op code
    • modify stack
    • modify memory
    • calculate fee

The opFns for CREATE, CALL, and CALLCODE call back up to runCall.

DEVELOPMENT

Developer documentation - currently mainly with information on testing and debugging - can be found here.

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices.

If you want to join for work or do improvements on the libraries have a look at our contribution guidelines.

LICENSE

MPL-2.0