@ethereumjs/vm / 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.
• Readonly
blockchain: BlockchainInterface
The blockchain the VM operates on
• Readonly
common: Common
• Readonly
events: AsyncEventEmitter
<VMEvents
>
• Readonly
evm: EVMInterface
The EVM used for bytecode execution
• Readonly
stateManager: EVMStateManagerInterface
The StateManager used by the VM
▸ 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.
Name | Type |
---|---|
opts |
BuildBlockOpts |
Promise
<BlockBuilder
>
An instance of BlockBuilder with methods:
▸ errorStr(): string
Return a compact error string representation of the object
string
▸ 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.
Name | Type | Description |
---|---|---|
opts |
RunBlockOpts |
Default values for options: - generate : false |
Promise
<RunBlockResult
>
▸ 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.
Name | Type |
---|---|
opts |
RunTxOpts |
Promise
<RunTxResult
>
▸ 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
.
Name | Type | Default value | Description |
---|---|---|---|
downlevelCaches |
boolean |
true |
Downlevel (so: adopted for short-term usage) associated state caches (default: true) |
Promise
<VM
>
▸ Static
create(opts?
): Promise
<VM
>
VM async constructor. Creates engine instance and initializes it.
Name | Type | Description |
---|---|---|
opts |
VMOpts |
VM engine constructor options |
Promise
<VM
>