Skip to content

Latest commit

 

History

History
257 lines (148 loc) · 6.26 KB

File metadata and controls

257 lines (148 loc) · 6.26 KB

@ethereumjs/vm / VM

Class: VM

Execution engine which can be used to run a blockchain, individual blocks, individual transactions, or snippets of EVM bytecode.

This class is an AsyncEventEmitter, please consult the README to learn how to use it.

Table of contents

Properties

Methods

Properties

blockchain

Readonly blockchain: BlockchainInterface

The blockchain the VM operates on

Defined in

vm/src/vm.ts:42


common

Readonly common: Common

Defined in

vm/src/vm.ts:44


events

Readonly events: AsyncEventEmitter<VMEvents>

Defined in

vm/src/vm.ts:46


evm

Readonly evm: EVMInterface

The EVM used for bytecode execution

Defined in

vm/src/vm.ts:50


stateManager

Readonly stateManager: EVMStateManagerInterface

The StateManager used by the VM

Defined in

vm/src/vm.ts:37

Methods

buildBlock

buildBlock(opts): Promise<BlockBuilder>

Build a block on top of the current state by adding one transaction at a time.

Creates a checkpoint on the StateManager and modifies the state as transactions are run. The checkpoint is committed on build or discarded with revert.

Parameters

Name Type
opts BuildBlockOpts

Returns

Promise<BlockBuilder>

An instance of BlockBuilder with methods:

Defined in

vm/src/vm.ts:235


errorStr

errorStr(): string

Return a compact error string representation of the object

Returns

string

Defined in

vm/src/vm.ts:277


init

init(__namedParameters?): Promise<void>

Parameters

Name Type
__namedParameters Object
__namedParameters.genesisState? GenesisState

Returns

Promise<void>

Defined in

vm/src/vm.ts:159


runBlock

runBlock(opts): Promise<RunBlockResult>

Processes the block running all of the transactions it contains and updating the miner's account

This method modifies the state. If generate is true, the state modifications will be reverted if an exception is raised. If it's false, it won't revert if the block's header is invalid. If an error is thrown from an event handler, the state may or may not be reverted.

Parameters

Name Type Description
opts RunBlockOpts Default values for options: - generate: false

Returns

Promise<RunBlockResult>

Defined in

vm/src/vm.ts:204


runTx

runTx(opts): Promise<RunTxResult>

Process a transaction. Run the vm. Transfers eth. Checks balances.

This method modifies the state. If an error is thrown, the modifications are reverted, except when the error is thrown from an event handler. In the latter case the state may or may not be reverted.

Parameters

Name Type
opts RunTxOpts

Returns

Promise<RunTxResult>

Defined in

vm/src/vm.ts:217


shallowCopy

shallowCopy(downlevelCaches?): Promise<VM>

Returns a copy of the VM instance.

Note that the returned copy will share the same db as the original for the blockchain and the statemanager.

Associated caches will be deleted and caches will be re-initialized for a more short-term focused usage, being less memory intense (the statemanager caches will switch to using an ORDERED_MAP cache datastructure more suitable for short-term usage, the trie node LRU cache will not be activated at all). To fine-tune this behavior (if the shallow-copy-returned object has a longer life span e.g.) you can set the downlevelCaches option to false.

Parameters

Name Type Default value Description
downlevelCaches boolean true Downlevel (so: adopted for short-term usage) associated state caches (default: true)

Returns

Promise<VM>

Defined in

vm/src/vm.ts:252


create

Static create(opts?): Promise<VM>

VM async constructor. Creates engine instance and initializes it.

Parameters

Name Type Description
opts VMOpts VM engine constructor options

Returns

Promise<VM>

Defined in

vm/src/vm.ts:79