Deploying to the Dukong Testnet

Now that we've built and tested our Solidity contracts, it's time to deploy them to to the Dukong testnet. Again, Foundry makes this a straighforward process with its scritping capabilities. Foundry's deployment script provides a declarative deployment process which we can use to deploy all of our contracts at once.

To deploy your compiled contracts you'll need an Dukong testnet account that has been funded with OM. If you've skipped that step go back and do it now.

Foundry script files have the following naming convention ScriptFileName.s.sol. Here's our Foundry deployment script:

DeployWhitelistAndFactory.s.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

import "forge-std/Script.sol";
import {Whitelist} from "../src/Whitelist.sol";
import {RealEstateFactory} from "../src/RealEstateFactory.sol";

contract DeployWhitelistAndFactory is Script {
    function run() external {
        uint256 deployerPk = vm.envUint("PRIVATE_KEY");

        vm.startBroadcast(deployerPk);

        // 1) Deploy Whitelist (owner = deployer)
        Whitelist wl = new Whitelist();

        // 2) Deploy Factory wired to the Whitelist
        RealEstateFactory factory = new RealEstateFactory(address(wl));

        vm.stopBroadcast();

        console2.log("Whitelist:", address(wl));
        console2.log("Factory  :", address(factory));
    }
}

As you can see, it is quite simple. It basically does three things:

  1. Deploys the Whitelist contract with Whitelist wl = new Whitelist();

  2. Deploys the RealEstateFactory contract with RealEstateFactory factory = new RealEstateFactory(address(wl));

  3. Outputs the deployed contract addresses to the console.

You'll notice that the wl variable is assigned the address of the deployed Whitelist contract, which can then be passed to the constructor of the RealEstateToken contract. This establishes the link between these two contracts for whitelist management.

You can run the deployment script with:

forge script --chain 5887 script/DeployWhitelistAndFactory.s.sol:DeployWhitelistAndFactory --rpc-url $DUKONG_RPC_URL --broadcast  -vvv --interactives 1

The --chain 5887 parameter we set up earlier in the Foundry's foundry.toml configuration file. You'll also notice the $DUKONG_RPC_URL environment variable used to pass the url of the Dukpong RPC endpoint.

The --broadcast flag is responsible for publishing your transaction to the network. And the final piece of magic, the --interactives 1 will cause the script to prompt you for the private key of the account being used for the deployment. Script execution will pause and you'll be asked to enter the private key.

Warning

Foundry provides more sohpisticated methods to manage private keys for deployments. We use a simple method here for demonstration. However, we strongly suggest reading the Foundry documentation on production grade private key management capabilities.

You should see something like this when you execute the deployment script:

Deployment with Foundry

Now head over to the MANTRASCAN Dukong Testnet explorer and verify that your contracts have been deployed.

Last updated