ERC20 - How to split the initial token supply on multiple accounts?

695 Views Asked by At

Can someone explain to me why it's not possible to split the initial total supply with the Transfer event to multiple address that are not the _msgSender() address ?

The goal here is to "mint" with the 0x00 address the tokens on multiple wallets (12% in devs wallet, 5% in marketing wallet and 3% in another wallet) but directly in the constructor not using an external function that I will have to call in a script during the deployment.

But it's not working and I'm not getting any errors... Really don't understand

This is my code :

constructor () public payable{
    uint256 _tTotransfer = _tTotal;

    uint256 _tToDevs = (_tTotal.mul(12)).div(100);
    _tTotransfer = _tTotransfer.sub((_tTotal.mul(12)).div(100));

    uint256 _tToMarketing = (_tTotal.mul(5)).div(100);
    _tTotransfer = _tTotransfer.sub((_tTotal.mul(5)).div(100));

    uint256 _tToApes = (_tTotal.mul(3)).div(100);
    _tTotransfer = _tTotransfer.sub((_tTotal.mul(3)).div(100));

    _rOwned[_msgSender()] = _rTotal;

    emit Transfer(address(0), _msgSender(), _tTotransfer); 
    emit Transfer(address(0), _devsWallet, _tToDevs); 
    emit Transfer(address(0), _marketingWallet, _tToMarketing); 
    emit Transfer(address(0), _apesWallet, _tToApes);
    
}

Also I don't understand why it's not possible to directly "mint" the total supply on another wallet (not to split but the entire) than the _msgSender.

Thx guys hope someone would help me...

1

There are 1 best solutions below

1
On BEST ANSWER

Assuming _rOwned holds the actual token balance of each address:

You're correctly emitting the Transfer events, but need to update the token balances as well.


This line sets the _msgSender() balance to _tTotal, which you don't want according to your description.

_rOwned[_msgSender()] = _rTotal; // incorrect

You want them to have the remaining _tTotransfer.


And the same goes for other initial owners

_rOwned[_msgSender()] = _tTotransfer; // replace the above line to this
emit Transfer(address(0), _msgSender(), _tTotransfer);

_rOwned[_devsWallet] = _tToDevs;
emit Transfer(address(0), _devsWallet, _tToDevs);

rOwned[_marketingWallet] = _tToMarketing;
emit Transfer(address(0), _marketingWallet, _tToMarketing);

rOwned[_apesWallet] = _tToApes;
emit Transfer(address(0), _apesWallet, _tToApes);