Smart contract Token distribution solution

Viewed 186

I have a question regard to the token sale: How token distribution work?

An example:

10% for private sale
30% for public sale 
20% for dev team
40% for rewards 

The number of token will be transferred to these address at the time the token created or it will be transferred to these address after that?

1 Answers

It depends on the token contract implementation, can be both.

Example that mints 100 tokens to public sale available right after token creation, and reserves another 50 for later vesting by a dev team address:

pragma solidity ^0.8;

contract MyToken {
    mapping (address => uint256) _balances;
    mapping (address => Vesting) _vesting;
    
    struct Vesting {
        uint256 amount;
        uint64 unlockTime;
    }
    
    constructor() {
        address publicSaleAddress = address(0x123);
        address devTeamAddress = address(0x456);
        
        // set the `publicSaleAddress` balance right away
        _balances[publicSaleAddress] = 100;

        // don't set the `devTeamAddress` balance now
        // instead, allow them to claim it after some time
        uint64 deadline = uint64(block.timestamp) + 365 days;
        _vesting[devTeamAddress] = Vesting(
            50,
           deadline
        );
    }
    
    function unvest() external {
        // check if they have something to unvest
        require(_vesting[msg.sender].amount > 0, 'Nothing to unvest');
        
        // check if they are allowed to unvest yet
        require(_vesting[msg.sender].unlockTime >= block.timestamp, 'Not yet');
        
        // increase their balance
        _balances[msg.sender] += _vesting[msg.sender].amount;
        
        // prevent them from claiming the balance again
        _vesting[msg.sender] = Vesting(0, 0);
    }
}
Related