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
  • ABI
  • CallTracer
  • BaseContract
  • ContractFactory
  • ContractHost
  • ContractManager
  • ContractStack
  • CustomContracts
  • DynamicContract
  • Event
  • The variables subfolder
  • The templates subfolder
  1. BDK implementation

The contract folder

The base for smart contract support in Blockchain Development Kit (BDK).

PreviousThe utils folderNextThe core folder

Last updated 5 months ago

This subchapter contains a brief overview of each one of the components inside the src/contract folder.

ABI

The abi.h file contains the ABI namespace - helper functions for handling Solidity ABI types and data natively, as well as the encoding and decoding of said data, also used for C++ <-> EVM inter-operability.

CallTracer

The calltracer.h file contains the Call struct and the CallTracer class respectively, both under the trace namespace - those are used specifically for debugging purposes, tracing the flux of a contract call and collecting specific details about it, such as the call type, the sender and receiver addresses, the value sent, the gas used, inputs and outputs, errors and any related subcalls.

BaseContract

The contract.h file contains the BaseContract class - the base from which all smart contracts are derived - as well as the ContractGlobals and ContractLocals helper classes that provide access to global and local variables, respectively, for those contracts to work.

ContractFactory

The contractfactory.h file contains the ContractFactory namespace - helper functions for aiding contract creation, typically used by ContractManager.

ContractHost

The contracthost.h file contains the ContractHost class - responsible for managing a single chain of contract execution from beginning to end (including nested calls), including the EVMC host implementation for EVM contracts, holding the execution stack and commit/revert during or at the end of the call (via ContractStack), and allowing both C++ and EVM contract calls and inter-operability.

ContractManager

The contractmanager.h contains the ContractManager class - responsible solely for creating and deploying contracts, passing their ownership to State when done.

ContractStack

The contractstack.h file contains the ContractStack class - responsible for managing temporary data from contract nested call chains, such as used SafeVariables and altered balances, acting as the one who effectively decides whether those changes are committed or reverted during a contract call. Only one instance of ContractStack is spawned per ContractHost during a call - this ensures the contract call lifecycle is properly contained and state data doesn't spill over other calls.

CustomContracts

The customcontracts.h file contains a tuple that holds all the registered contracts within the blockchain. It is also used as a reference for generating the ABI of said contracts.

DynamicContract

The dynamiccontract.h file contains the DynamicContract class - the base from which all Dynamic Contracts are derived (while BaseContract is mainly used for Protocol Contracts).

Event

The event.h file contains the Event class - an abstraction of a Solidity event's structure and data, used extensively by contracts. Events are managed within the blockchain by the Storage class and are supported for both C++ and EVM contracts.

The variables subfolder

The variables subfolder contains implementations for SafeVariables - special classes that abstract safe versions of variables used within contracts.

The templates subfolder

The templates subfolder contains several contracts used as templates, examples and for internal testing purposes. It's also meant to be the folder where user-coded contracts are stored.