New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ethereumjs-vm

Package Overview
Dependencies
Maintainers
6
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereumjs-vm

An Ethereum VM implementation

  • 4.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is ethereumjs-vm?

The ethereumjs-vm package is a JavaScript implementation of the Ethereum Virtual Machine (EVM). It allows developers to execute smart contracts, run Ethereum transactions, and simulate the Ethereum blockchain environment. This package is useful for testing, development, and research purposes.

What are ethereumjs-vm's main functionalities?

Execute Smart Contracts

This feature allows you to execute smart contracts within the Ethereum Virtual Machine. The code sample demonstrates how to set up the VM, create an account, and run a simple contract code.

const { VM } = require('ethereumjs-vm');
const { Account, Address } = require('ethereumjs-util');
const { default: Common } = require('@ethereumjs/common');

const common = new Common({ chain: 'mainnet' });
const vm = new VM({ common });

const runCode = async () => {
  const code = '0x6001600101600055'; // Simple contract code
  const address = Address.fromString('0x1234567890123456789012345678901234567890');
  const account = new Account({ balance: '0x10000000000000' });

  await vm.stateManager.putAccount(address, account);

  const result = await vm.runCode({
    code: Buffer.from(code, 'hex'),
    gasLimit: Buffer.from('ffffffff', 'hex'),
    address,
  });

  console.log(result);
};

runCode();

Run Ethereum Transactions

This feature allows you to run Ethereum transactions within the VM. The code sample demonstrates how to create a transaction and execute it using the VM.

const { VM } = require('ethereumjs-vm');
const { Transaction } = require('ethereumjs-tx');
const { default: Common } = require('@ethereumjs/common');

const common = new Common({ chain: 'mainnet' });
const vm = new VM({ common });

const runTransaction = async () => {
  const txData = {
    nonce: '0x00',
    gasPrice: '0x09184e72a000',
    gasLimit: '0x2710',
    to: '0x0000000000000000000000000000000000000000',
    value: '0x00',
    data: '0x',
  };

  const tx = new Transaction(txData, { common });

  const result = await vm.runTx({ tx });

  console.log(result);
};

runTransaction();

Simulate Blockchain Environment

This feature allows you to simulate a blockchain environment by running blocks within the VM. The code sample demonstrates how to create a block and execute it using the VM.

const { VM } = require('ethereumjs-vm');
const { Block } = require('@ethereumjs/block');
const { default: Common } = require('@ethereumjs/common');

const common = new Common({ chain: 'mainnet' });
const vm = new VM({ common });

const simulateBlockchain = async () => {
  const block = Block.fromBlockData({}, { common });

  const result = await vm.runBlock({ block, generate: true, skipBlockValidation: true });

  console.log(result);
};

simulateBlockchain();

Other packages similar to ethereumjs-vm

Keywords

FAQs

Package last updated on 06 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc