Create Core Contract
Installation
Install Forge from Foundry and add the modular contract framework:
Setup Core Contract
Create a Core Contract
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.Set Up Increment Function
Define a function to increment a counter.
Add a Callback Function
Introduce the
_beforeIncrement
function to use thebeforeIncrement
callback from a module.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 Supported Functions
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.