Executing contract calls via EVMC
How to use AppLayer's EVM directly to call contracts.
To execute a contract call within AppLayer's EVM environment, we use the evmc_execute()
function from the EVMC library. This function orchestrates the execution of contract bytecode, interfacing directly with the Ethereum Virtual Machine:
It's crucial to understand that the VM itself is stateless—it does not maintain any information about the contracts' states or their data. The VM's role is strictly to interpret and execute bytecode according to the Ethereum protocol specifications.
To enable the stateless VM to interact with the state (such as storage keys, account balances, or initiating further contract calls), we must provide it with access to the state through the evmc_host_interface
and evmc_host_context
structs. The evmc_host_interface
struct contains a set of callback functions that the VM can use to query or modify the state:
Within AppLayer's BDK, we use evmc_execute()
like this:
ContractHost
is casted into evmc_host_interface
to provide the VM with the necessary state access functions. This allows the VM to interact with the state and execute contract calls within AppLayer's environment.
Last updated