$ npm install ethereumjs-vm
Implements Ethereum's VM in Javascript.
The VM currently supports the following hardfork rules:
ByzantiumConstantinoplePetersburg (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).
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:
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.
npm install ethereumjs-vm
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),
},
function(err, results) {
console.log('Returned : ' + results.return.toString('hex'))
console.log('gasUsed : ' + results.gasUsed.toString())
console.log('Error : ' + err)
},
)
Also more examples can be found here
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.
For documentation on VM instantiation, exposed API and emitted events see generated API docs.
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.
The VM processes state changes at many levels.
The opFns for CREATE, CALL, and CALLCODE call back up to runCall.
Developer documentation - currently mainly with information on testing and debugging - can be found here.
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.
© 2010 - cnpmjs.org x YWFE | Home | YWFE