Create Core Contract
Install Forge from Foundry and add the modular contract framework:
Add the Thirdweb modular contracts to foundry.toml
under remappings
:
Create a new file in the
src
folder calledCounterCore.sol
, and inherit theCore
contract.Note
TheCore
contract is the base contract that needs to be inherited for this contract to be recognized as a core contract.Implement the
getSupportedCallbackFunctions
function. The Core contract is abstract because this function is not implemented. To avoid compilation errors, declare the function with an empty body for now.Define a function to increment a counter.
Introduce the
_beforeIncrement
function to use thebeforeIncrement
callback from a module to achieve this, we'll introduce the interfaceBeforeIncrementCallback
Note
Callback functions are hook-like functionalities that can be used before or after the main functionality of a core contract.
In this example, thebeforeIncrement
callback is executed before the main increment functionality.Implement the
getSupportedCallbackFunctions
andsupportsInterface
functions to expose which callback functions and interfaces this core contract supports.
This guide will help you create a core contract that can increment a counter with optional callback functions for additional modular functionality.