Twitter: Jack Lee|Conflux DAO
Community: JackLee.io |Conflux Forum
All code and tutorials are open source on GitHub: https://github.com/jackleeio/CoinCraft
A capped token is a type of mintable token that has a maximum minting limit set. When the minting reaches this cap, an exception will be thrown.
Capped Token: ERC20WithCapped.sol
To deploy the ERC20WithCapped token using Foundry, follow these steps:
-
Make sure you have Foundry installed. If not, refer to the Foundry Installation Guide.
-
Create a
.env
file in the project root directory and add the following content:PRIVATE_KEY=your_private_key RPC_URL=your_target_network_rpc_url
-
Create a deployment script
script/DeployERC20WithCapped.s.sol
:// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import "forge-std/Script.sol"; import "../src/ERC20/ERC20WithCapped.sol"; contract DeployERC20WithCapped is Script { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); ERC20WithCapped token = new ERC20WithCapped( "Capped Token", "CAP", 18, 1000000 * 10**18 // Set cap to 1,000,000 tokens ); vm.stopBroadcast(); } }
-
Run the following command to deploy:
forge script script/DeployERC20WithCapped.s.sol:DeployERC20WithCapped --rpc-url $RPC_URL --broadcast --verify
-
After deployment, you will see the deployed contract address in the console output. Save this address for future use.
Note: Before deploying, ensure your account has enough native tokens (e.g., ETH, CFX) to cover gas fees.