AppLayer
  • Welcome to AppLayer Docs
  • Introducing AppLayer
    • A Primer on Smart Contracts
    • The Problem With EVMs
    • What is AppLayer?
  • How AppLayer works
    • Validators
    • Sentinels
    • Application Chains
    • Bridging
      • AppLayer-to-AppLayer Data Bridging
      • AppLayer-to-AppLayer Token Bridging
      • AppLayer-to-External Bridging (Ethereum, Solana, etc.)
  • Understanding rdPoS
    • Blockchains overview
    • How rdPoS works
    • Validator implementations
    • Slashing
  • BDK implementation
    • The utils folder
    • The contract folder
    • The core folder
    • Transactions and Blocks
    • Database
    • Contract call handling
    • RLP (Recursive-Length Prefix)
    • P2P Overview
    • P2P Encoding
  • Understanding contracts
    • Solidity ABI
    • Internal and external contract calls
    • Setting up the development environment
    • Contract Tester
  • Precompiled contracts
    • Types of pre-compiled contracts
    • Dynamic and Protocol Contracts
    • SafeVariables and commit/revert logic
    • How to code a precompiled contract
    • Creating a Dynamic Contract (Simple)
      • Simple Contract Header
      • Simple Contract Source
      • Deploying and testing
    • Creating a Dynamic Contract (Advanced)
    • Creating a Protocol Contract (Advanced)
  • EVM contracts
    • State management and VM instance creation
    • Seamless C++/EVM integration
    • C++ to other contract calls
    • EVM to other contract calls
    • Executing contract calls via EVMC
    • Calling EVM contracts from C++
    • Calling C++ contracts from EVM
  • Getting started with AppLayer Testnet
  • Join our Community
  • Get in Touch
  • Glossary
Powered by GitBook
On this page
  1. EVM contracts

EVM to other contract calls

How contract calls happen from the EVM side in AppLayer.

For calls from the EVM to another contract, the ContractHost::call() function plays a crucial role. It is tasked with creating and handling calls to other contracts, encapsulating the complexity of contract interaction within a simple interface:

evmc::Result call(const evmc_message& msg) noexcept final;

This function is designed to handle both C++ and EVM contract calls, as shown below:

evmc::Result ContractHost::call(const evmc_message& msg) noexcept {
  evmc::Result result;
  const bool isContractCall = isCall(msg);

  if (isContractCall) {
    this->traceCallStarted(msg);
  }

  switch (this->decodeContractCallType(msg))
  {
  case ContractType::CREATE: {
    result = this->callEVMCreate(msg);
    break;
  }
  case ContractType::CREATE2: {
    result = this->callEVMCreate2(msg);
    break;
  }
  case ContractType::PRECOMPILED: {
    result = this->processBDKPrecompile(msg);
    break;
  }
  case ContractType::CPP: {
    result = this->callCPPContract(msg);
    break;
  }
  default:
    result = this->callEVMContract(msg);
    break;
  }

  if (isContractCall) {
    this->traceCallFinished(result.raw());
  }

  return result;
}
PreviousC++ to other contract callsNextExecuting contract calls via EVMC

Last updated 6 months ago