How to use ethereumjs-vm - 8 common examples

To help you get started, we’ve selected a few ethereumjs-vm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trufflesuite / truffle / packages / sawtooth-seth-provider / src / subproviders / vm.js View on Github external
VmSubprovider.prototype.runVm = function(payload, cb) {
  const self = this;

  var blockData = self.currentBlock;
  var block = blockFromBlockData(blockData);
  var blockNumber = ethUtil.addHexPrefix(blockData.number.toString("hex"));

  // create vm with state lookup intercepted
  var vm = (self.vm = createVm(self.engine, blockNumber, {
    enableHomestead: true
  }));

  if (self.opts.debug) {
    vm.on("step", function(data) {
      console.log(data.opcode.name);
    });
  }

  // create tx
  var txParams = payload.params[0];
  // console.log('params:', payload.params)

  const normalizedTxParams = {
    to: txParams.to ? ethUtil.addHexPrefix(txParams.to) : undefined,
    from: txParams.from ? ethUtil.addHexPrefix(txParams.from) : undefined,
github MetaMask / web3-provider-engine / subproviders / vm.js View on Github external
VmSubprovider.prototype.runVm = function(payload, cb){
  const self = this

  var blockData = self.currentBlock
  var block = blockFromBlockData(blockData)
  var blockNumber = ethUtil.addHexPrefix(blockData.number.toString('hex'))

  // create vm with state lookup intercepted
  var vm = self.vm = createVm(self.engine, blockNumber, {
    enableHomestead: true
  })

  if (self.opts.debug) {
    vm.on('step', function (data) {
      console.log(data.opcode.name)
    })
  }

  // create tx
  var txParams = payload.params[0]
  // console.log('params:', payload.params)

  const normalizedTxParams = {
    to: txParams.to ? ethUtil.addHexPrefix(txParams.to) : undefined,
    from: txParams.from ? ethUtil.addHexPrefix(txParams.from) : undefined,
github MetaMask / eth-json-rpc-middleware / vm.js View on Github external
function runVm (req, block, cb) {
    const txParams = Object.assign({}, req.params[0])
    const blockRef = req.params[1]
    // opting to use blockRef as specified
    // instead of hardening to resolved block's number
    // for compatiblity with eth-json-rpc-ipfs
    // const blockRef = block.number.toNumber()

    // create vm with state lookup intercepted
    const vm = createVm(provider, blockRef, {
      enableHomestead: true
    })

    // create tx
    txParams.from = txParams.from || '0x0000000000000000000000000000000000000000'
    txParams.gasLimit = txParams.gasLimit || ('0x' + block.header.gasLimit.toString('hex'))
    const tx = new FakeTransaction(txParams)

    vm.runTx({
      tx: tx,
      block: block,
      skipNonce: true,
      skipBalance: true
    }, function (err, results) {
      if (err) return cb(err)
      if (results.error) {
github trufflesuite / truffle / packages / sawtooth-seth-provider / src / monkeyPatches.js View on Github external
fields.forEach(function(field) {
        if (keys.indexOf(field.name) !== -1)
          self[field.name] = data[field.name];
        if (keys.indexOf(field.alias) !== -1)
          self[field.alias] = data[field.alias];
      });
    } else {
      throw new Error("invalid data");
    }
  }
};

const async = require("async");
let Cache = require("ethereumjs-vm/dist/cache");

Cache.prototype.warm = function(addresses, cb) {
  var self = this;
  // shim till async supports iterators
  var accountArr = [];
  addresses.forEach(function(val) {
    if (val) accountArr.push(val);
  });

  async.eachSeries(
    accountArr,
    function(addressHex, done) {
      var address = Buffer.from(addressHex.replace("0x", ""), "hex");
      self._lookupAccount(address, function(err, account) {
        if (err) return done(err);
        self._update(address, account, false, account.exists);
        done();
      });
github ethereum / remix / remix-lib / src / execution / execution-context.js View on Github external
/* global ethereum */
'use strict'
const Web3 = require('web3')
const EventManager = require('../eventManager')
const EthJSVM = require('ethereumjs-vm').default
const ethUtil = require('ethereumjs-util')
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
const Web3VMProvider = require('../web3Provider/web3VmProvider')

const LogsManager = require('./logsManager.js')

const rlp = ethUtil.rlp

if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
  var injectedProvider = window.web3.currentProvider
  var web3 = new Web3(injectedProvider)
} else {
  web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
}

const blankWeb3 = new Web3()
const currentFork = 'istanbul'
/*
github ethereum / remix / remix-lib / src / execution / execution-context.js View on Github external
function createVm (hardfork) {
  var stateManager = new StateManagerCommonStorageDump({})
  stateManager.checkpoint(() => {})
  var vm = new EthJSVM({
    activatePrecompiles: true,
    blockchain: stateManager.blockchain,
    stateManager: stateManager,
    hardfork: hardfork
  })
  vm.blockchain.validate = false
  var web3vm = new Web3VMProvider()
  web3vm.setVM(vm)
  return { vm, web3vm, stateManager }
}
github FabricLabs / fabric / services / ethereum.js View on Github external
constructor (settings = {}) {
    super(settings);

    this.status = 'constructing';
    this.settings = Object.assign({
      name: '@services/ethereum',
      stack: []
    }, settings);

    this._state = {
      stack: this.settings.stack
    };

    this.vm = new VM();
    this.status = 'constructed';
  }
github leapdao / leap-node / src / tx / applyTx / checkSpendCond.js View on Github external
} = require('jsbi-utils');
const isEqual = require('lodash/isEqual');
const getColors = require('../../api/methods/getColors');
const {
  NFT_COLOR_BASE,
  NST_COLOR_BASE,
} = require('../../api/methods/constants');
const {
  ERC20_BYTECODE,
  ERC721_BYTECODE,
  ERC1948_BYTECODE,
  ERC1948_BYTECODE_218508104,
} = require('./ercBytecode');
const { isNFT, isNST } = require('./../../utils');

const { Account } = VM.deps;

const REACTOR_ADDR = Buffer.from(
  '0000000000000000000000000000000000000001',
  'hex'
);

const ERC20_MINT_FUNCSIG = Buffer.from(
  '40c10f19000000000000000000000000',
  'hex'
);

const ERC721_MINT_FUNCSIG = Buffer.from(
  '40c10f19000000000000000000000000',
  'hex'
);

ethereumjs-vm

An Ethereum VM implementation

MPL-2.0
Latest version published 4 years ago

Package Health Score

61 / 100
Full package analysis