This project is a Token Factory smart contract system that enables users to deploy custom ERC20 tokens on-demand with advanced features. Built with Hardhat 3 Beta, it provides a flexible and secure platform for creating tokens with configurable minting, burning, pause, and blacklist capabilities.
To learn more about the Hardhat 3 Beta, please visit the Getting Started guide. To share your feedback, join our Hardhat 3 Beta Telegram group or open an issue in our GitHub issue tracker.
- On-Demand Token Creation: Deploy custom ERC20 tokens with a single transaction
- Fee Management: Configurable creation fees with automatic refunding of excess ETH
- Token Tracking: Track all tokens created by address and globally
- Admin Controls: Owner can update creation fees and fee recipient
Each token created through the factory includes:
- Standard ERC20: Full compliance with ERC20 standard
- Custom Decimals: Support for 0-18 decimal places
- Optional Minting: Enable/disable minting with max supply enforcement
- Optional Burning: Enable/disable token burning
- Pause/Unpause: Owner can pause all transfers
- Blacklist Management: Block specific addresses from sending/receiving tokens
- Max Supply Control: Enforce maximum token supply limits
contracts/
├── TokenFactory.sol # Factory contract for deploying tokens
├── ERC20Token.sol # Custom ERC20 implementation with advanced features
├── Ownable.sol # Custom ownership management
└── test/
├── TokenFactory.t.sol # Factory unit tests (Forge)
└── ERC20Token.t.sol # Token unit tests (Node.js)
ignition/
└── modules/
└── TokenFactory.ts # Hardhat Ignition deployment module
Ensure you have Node.js installed, then install dependencies:
npm install
# or
yarn installRun all tests in the project:
npx hardhat testRun only Solidity tests (Forge-style):
npx hardhat test solidityRun only Node.js integration tests:
npx hardhat test nodejsDeploy the TokenFactory to a local Hardhat network:
npx hardhat ignition deploy ignition/modules/TokenFactory.tsFirst, configure your private key using the hardhat-keystore plugin:
npx hardhat keystore set SEPOLIA_PRIVATE_KEYThen deploy to Sepolia:
npx hardhat ignition deploy --network sepolia ignition/modules/TokenFactory.tsConfigure your private key:
npx hardhat keystore set AMOY_PRIVATE_KEYDeploy to Amoy:
npx hardhat ignition deploy --network amoy ignition/modules/TokenFactory.tsAfter deploying the TokenFactory, you can create tokens by calling the createToken function with the following parameters:
interface TokenParams {
name: string; // Token name (e.g., "My Token")
symbol: string; // Token symbol (e.g., "MTK")
decimals: uint8; // Decimal places (0-18)
initialSupply: uint256; // Initial token supply
initialHolder: address; // Address to receive initial supply
maxSupply: uint256; // Maximum supply (0 for unlimited)
config: {
_isMintable: boolean; // Enable minting
_isBurnable: boolean; // Enable burning
_isSetTotalSupply: boolean; // Enforce max supply
_hasChangeOwner: boolean; // Reserved for future use
_isLimitTokenPerAddress: boolean; // Reserved for future use
}
}Example interaction using ethers/viem:
const tokenParams = {
name: "My Custom Token",
symbol: "MCT",
decimals: 18,
initialSupply: ethers.parseEther("1000000"),
initialHolder: "0xYourAddress",
maxSupply: ethers.parseEther("10000000"),
config: {
_isMintable: true,
_isBurnable: true,
_isSetTotalSupply: true,
_hasChangeOwner: false,
_isLimitTokenPerAddress: false
}
};
// Send transaction with creation fee
await tokenFactory.createToken(tokenParams, {
value: await tokenFactory.creationFee()
});Deploys a new ERC20 token with specified parameters. Requires sending the creation fee as ETH.
Events: Emits TokenCreated(address indexed tokenAddress, address indexed creator)
Updates the token creation fee.
Updates the address that receives creation fees.
Returns all token addresses created by a specific address.
Returns all token addresses created through the factory.
In addition to standard ERC20 functions (transfer, approve, transferFrom, balanceOf, etc.), each token includes:
Mints new tokens (if minting is enabled and max supply not exceeded).
Burns tokens from owner's balance (if burning is enabled).
Pauses all token transfers.
Resumes token transfers.
Adds or removes an address from the blacklist.
Checks if an address is blacklisted.
The project supports multiple networks:
- hardhatMainnet: Simulated Ethereum mainnet
- hardhatOp: Simulated Optimism L2
- sepolia: Ethereum Sepolia testnet (Chain ID: 11155111)
- amoy: Polygon Amoy testnet (Chain ID: 80002)
Network configurations can be found in hardhat.config.ts.
- Hardhat 3 Beta: Development framework
- Solidity 0.8.28: Smart contract language
- OpenZeppelin Contracts v5.4.0: Secure contract libraries
- Viem: TypeScript library for Ethereum interactions
- Node.js Test Runner: Native testing framework
- Forge (Foundry): Solidity testing framework
- Hardhat Ignition: Deployment system
- Fee Validation: Ensures sufficient ETH sent for token creation
- Zero Address Checks: Prevents deployment with invalid addresses
- Access Control: Owner-only functions for sensitive operations
- Max Supply Enforcement: Prevents minting beyond configured limits
- Decimal Limits: Restricts decimals to 0-18 range
- Blacklist Protection: Prevents blacklisted addresses from transfers
- Pause Mechanism: Emergency stop for token transfers
The project includes comprehensive test coverage:
- Initial state validation
- Token creation and deployment
- Fee collection and refunding
- Access control and ownership
- Token tracking by creator
- Event emission verification
- Initial setup and configuration
- Minting and burning functionality
- Blacklist enforcement
- Pause/unpause mechanics
- Max supply enforcement
- Invalid parameter validation
The project uses Solidity 0.8.28 with optimizer enabled (200 runs) for production deployments.
After deployment, verify your contracts on Etherscan:
npx hardhat verify --network sepolia <CONTRACT_ADDRESS>Ensure you have set your ETHERSCAN_API_KEY in the environment or configuration variables.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please ensure all tests pass before submitting pull requests:
npx hardhat testFor issues related to:
- Hardhat 3 Beta: Join the Hardhat 3 Beta Telegram group
- This Project: Open an issue in the project repository