user3025417
user3025417

Reputation: 395

Cannot mint ERC223 token

Hello I have a simple implementation for a ERC223 Token. I use this repository: ERC223-token-standard

Here is my contract Code:

pragma solidity ^0.5.8;

import "./ERC223-token-standard-development/token/ERC223/ERC223Burnable.sol";
import "./ERC223-token-standard-development/token/ERC223/ERC223Mintable.sol";

contract MyToken is ERC223Burnable, ERC223Mintable{
}

The first strange Thing is that I get this warning when compiling:

Warning: Function state mutability can be restricted to view
    function mint(address account, uint256 amount) public onlyMinter returns (bool) {
    ^ (Relevant source part starts here and spans across multiple lines).

I think this is weird because to my understanding it changes the state of the contract and should not be a view function

However after creating my contract and using the mint function the totalSupply is still 0 even though isMinter(myaddr) returns true. I thought that I was just doing something wrong in the truffle testfile but after I pushed my code into Remix I still get the same warning and the total supply is still 0.

I hope you can help me with this issue.

Upvotes: 0

Views: 196

Answers (1)

Yegor
Yegor

Reputation: 3950

thanks for your question, it looks like a bug in your _mint function:

function mint(address account, uint256 amount) public onlyMinter returns (bool) {
    _totalSupply.add(amount);
    balances[msg.sender].add(amount);
    return true;
}

Let's see how add method of SafeMath lib works:

function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    require(c >= a, "SafeMath: addition overflow");

    return c;
}

First of all, its pure function, which doesn't modify the state of contract. It just returns amount of addition. So, it's expected behavior for your code ‘cause you don't save a result

But if you take a look at open-zeppelin's implementation of _mint method, they change contract's state

function _mint(address account, uint256 amount) internal {
    require(account != address(0), "ERC20: mint to the zero address");

    _totalSupply = _totalSupply.add(amount);
    _balances[account] = _balances[account].add(amount);
    emit Transfer(address(0), account, amount);
}

I believe it's better to use OpenZeppelin's contracts for your development 'cause they have a lot of auditors

P.S. Also you don't use address account variable in _mint() and always add amount to msg.sender (yourself) in your implementation

Upvotes: 2

Related Questions