Twitter: Jack Lee|Conflux DAO
Community: JackLee.io |Conflux Forum
All code and tutorials are open source on GitHub: https://github.com/jackleeio/TokenCraft
The Crowdsale contract allows project teams to raise funds by selling ERC20 tokens. This contract supports fixed supply tokens and provides flexible settings for crowdsale parameters.
Crowdsale Contract: Crowdsale.sol
forge test --match-contract SimpleCrowdsaleTest -vvv
Tests should cover the following scenarios:
- Initial token allocation
- Validation of crowdsale start and end times
- Token purchase behavior
- Withdrawal of unsold tokens
The SimpleCrowdsale contract inherits from Ownable. Here are the main method calls:
buyTokens()
: Allows users to purchase tokens.withdrawTokens()
: Allows the project team to withdraw unsold tokens.hasCrowdsaleStarted()
: Checks if the crowdsale has started.hasCrowdsaleEnded()
: Checks if the crowdsale has ended.
The ERC20Crowdsale.s.sol
script is used to deploy both the token and crowdsale contracts. It sets the following parameters:
- Initial token supply: 10,000,000 CRAFT
- Crowdsale allocation: 1,000,000 CRAFT
- Exchange rate: 1 ETH = 100 CRAFT
- Crowdsale start time: 1 day after deployment
- Crowdsale duration: 30 days