State

BaseState

class eth.vm.state.BaseState(db: AtomicDatabaseAPI, execution_context: ExecutionContextAPI, state_root: Hash32)
account_exists(address: Address) bool

Return True if an account exists at address.

account_is_empty(address: Address) bool

Return True if the account at address is empty, otherwise False.

apply_all_withdrawals(withdrawals: Sequence[WithdrawalAPI]) None
apply_withdrawal(withdrawal: WithdrawalAPI) None
clear_transient_storage() None

Clear the transient storage. Should be done at the start of every transaction

commit(snapshot: Tuple[Hash32, JournalDBCheckpoint]) None

Commit the journal to the point where the snapshot was taken. This merges in any changes that were recorded since the snapshot.

costless_execute_transaction(transaction: SignedTransactionAPI) ComputationAPI

Execute the given transaction with a gas price of 0.

delete_account(address: Address) None

Delete the account at the given address.

delete_code(address: Address) None

Delete the code at address.

delete_storage(address: Address) None

Delete the storage at address

delta_balance(address: Address, delta: int) None

Apply delta to the balance at address.

classmethod get_account_db_class() Type[AccountDatabaseAPI]

Return the AccountDatabaseAPI class that the state class uses.

get_ancestor_hash(block_number: int) Hash32

Return the hash for the ancestor block with number block_number. Return the empty bytestring b'' if the block number is outside of the range of available block numbers (typically the last 255 blocks).

get_balance(address: Address) int

Return the balance for the account at address.

get_code(address: Address) bytes

Return the code at address.

get_code_hash(address: Address) Hash32

Return the hash of the code at address.

get_computation(message: MessageAPI, transaction_context: TransactionContextAPI) ComputationAPI

Return a computation instance for the given message and transaction_context

get_gas_price(transaction: SignedTransactionAPI) int

Return the gas price of the given transaction.

Factor in the current block’s base gas price, if appropriate. (See EIP-1559)

get_nonce(address: Address) int

Return the nonce at address.

get_storage(address: Address, slot: int, from_journal: bool = True) int

Return the storage at slot for address.

get_tip(transaction: SignedTransactionAPI) int

Return the gas price that gets allocated to the miner/validator.

Pre-EIP-1559 that would be the full transaction gas price. After, it would be the tip price (potentially reduced, if the base fee is so high that it surpasses the transaction’s maximum gas price after adding the tip).

get_transaction_context(transaction: SignedTransactionAPI) TransactionContextAPI

Return the TransactionContextAPI for the given transaction

classmethod get_transaction_context_class() Type[TransactionContextAPI]

Return the BaseTransactionContext class that the state class uses.

get_transaction_executor() TransactionExecutorAPI

Return the transaction executor.

get_transient_storage(address: Address, slot: int) bytes

Return the transient storage for address at slot slot.

has_code_or_nonce(address: Address) bool

Return True if either a nonce or code exists at the given address.

increment_nonce(address: Address) None

Increment the nonce at address.

is_address_warm(address: Address) bool

Was the account accessed during this transaction?

See EIP-2929

is_storage_warm(address: Address, slot: int) bool

Was the storage slot accessed during this transaction?

See EIP-2929

lock_changes() None

Locks in all changes to state, typically just as a transaction starts.

This is used, for example, to look up the storage value from the start of the transaction, when calculating gas costs in EIP-2200: net gas metering.

make_state_root() Hash32

Create and return the state root.

mark_address_warm(address: Address) None

Mark the account as accessed during this transaction.

See EIP-2929

mark_storage_warm(address: Address, slot: int) None

Mark the storage slot as accessed during this transaction.

See EIP-2929

override_transaction_context(gas_price: int) Iterator[None]

Return a ContextManager that overwrites the current transaction context, applying the given gas_price.

persist() MetaWitnessAPI

Persist the current state to the database.

revert(snapshot: Tuple[Hash32, JournalDBCheckpoint]) None

Revert the VM to the state at the snapshot

set_balance(address: Address, balance: int) None

Set balance to the balance at address.

set_code(address: Address, code: bytes) None

Set code as the new code at address.

set_nonce(address: Address, nonce: int) None

Set nonce as the new nonce at address.

set_storage(address: Address, slot: int, value: int) None

Write value to the given slot at address.

set_transient_storage(address: Address, slot: int, value: bytes) None

Return the transient storage for address at slot slot.

snapshot() Tuple[Hash32, JournalDBCheckpoint]

Perform a full snapshot of the current state.

Snapshots are a combination of the state_root at the time of the snapshot and the checkpoint from the journaled DB.

touch_account(address: Address) None

Touch the account at the given address.

account_db_class: Type[AccountDatabaseAPI] = None
property base_fee: int

Return the current base_fee from the current execution_context

Raises a NotImplementedError if called in an execution context prior to the London hard fork.

property blob_base_fee: int

Return the current blob_base_fee from the current execution_context

Raises a NotImplementedError if called in an execution context prior to the Cancun hard fork.

property block_number: BlockNumber

Return the current block_number from the current execution_context

property coinbase: Address

Return the current coinbase from the current execution_context

computation_class: Type[ComputationAPI] = None
property difficulty: int

Return the current difficulty from the current execution_context

execution_context: ExecutionContextAPI
property gas_limit: int

Return the current gas_limit from the current transaction_context

property logger: ExtendedDebugLogger

Return the logger.

property mix_hash: Hash32

Return the current mix_hash from the current execution_context

property state_root: Hash32

Return the current state_root from the underlying database

property timestamp: int

Return the current timestamp from the current execution_context

transaction_context_class: Type[TransactionContextAPI] = None
transaction_executor_class: Type[TransactionExecutorAPI] = None

BaseTransactionExecutor

class eth.vm.state.BaseTransactionExecutor(vm_state: StateAPI)