ModuleKit
Deploy
Deployment

Deployment

The ModuleKit comes with a helper contract called RegistryDeployer that allows you to easily deploy a module and register it in the Module Registry. If you are using the module template repository (opens in a new tab), you can skip the setup step and follow the instructions in the the usage section.

Setup

To use the RegistryDeployer, you need to create a new Foundry script (opens in a new tab) and import the following objects:

import "forge-std/Script.sol";
import { RegistryDeployer } from "modulekit/deployment/RegistryDeployer.sol";
 
// Import modules here
...

Then, create a new contract, like the following example:

/// @title DeployModuleScript
contract DeployModuleScript is Script, RegistryDeployer {
    function run() public {
        // Setup module bytecode, deploy params, and data
        bytes memory bytecode = type(MODULE_CONTRACT).creationCode;
        bytes memory deployParams = "";
        bytes memory data = "";
 
        // Get private key for deployment
        vm.startBroadcast(vm.envUint("PK"));
 
        // Deploy module
        address module = deployModule({
            code: bytecode,
            deployParams: deployParams,
            salt: bytes32(0),
            data: data
        });
 
        // Stop broadcast and log module address
        vm.stopBroadcast();
        console.log("Deploying module at: %s", module);
    }
}

Where the MODULE_CONTRACT is the module you want to deploy. You can also add a deployParams, data and salt to the deployModule function if you need to. The deployParams are the parameters that are passed to the module's constructor, the data additional data to be stored on the Registry (you can ignore this for most cases) and the salt is the CREATE2 salt used to create the module's address.

Usage

First, make sure you have imported and set up your module correctly in the deployment script. Then, follow the steps below:

  1. Create a .env file in the root directory based on the .env.example (if you are using the module template) file and fill in the variables:
PK=
DEPLOYMENT_SENDER=
DEPLOYMENT_RPC=
ETHERSCAN_API_KEY=
  1. Then, run the following command:
source .env && forge script script/DeployModule.s.sol:DeployModuleScript --rpc-url $DEPLOYMENT_RPC --broadcast --sender $DEPLOYMENT_SENDER --verify

Note: you might need to adjust the script path and name to match your setup.

Your module is now deployed to the blockchain and verified on Etherscan.

If the verification on the blockexplorer fails, you can manually verify it on Etherscan using the following command (replace the placeholders with your actual values):

source .env && forge verify-contract --chain-id [YOUR_CHAIN_ID] --watch --etherscan-api-key $ETHERSCAN_API_KEY [YOUR_MODULE_ADDRESS] src/[PATH_TO_MODULE].sol:[MODULE_CONTRACT_NAME]