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. Understanding contracts

Internal and external contract calls

Not all contract calls are equal.

In the context of interacting with smart contracts, calls can be classified into two types: external and internal.

External calls occur when a contract is invoked from an external source, which can be either a user transaction (e.g. a block and its transactions are being processed) or a remote procedure call (RPC, e.g. an eth_call request). External calls serve as entry points into the smart contract from the outside world, initiating a transaction or a query. Within AppLayer's BDK, to process an external call, a ContractHost object is created, which establishes the execution context based on the specified parameters.

Internal calls occur when a smart contract, already running as part of an ongoing transaction/chain of execution, calls another contract or a function within another contract. This is considered an internal process, as it happens within the chain of execution started by an external call. In AppLayer's BDK, internal calls utilize the same ContractHost object created for the initial external call. This maintains consistency and control over the execution environment, allowing for functions like commits or rollbacks within the same transactional context.

Basically, an external call creates a new "chain of execution", while internal calls only exist within that same given chain of execution, thus they cannot create new chains by themselves. A chain of execution is a sequence of calls that are executed in a given external call, always composed of an initial external call and a set of internal calls (if applicable).

PreviousSolidity ABINextSetting up the development environment

Last updated 1 year ago