Skip to main content
Added OpenZeppelin tag, removed geth and contract deployment as they were less relevant to the question.
Link
Source Link
user53451
user53451

How to use function modifier to control contract function access right?

I deployed a ERC20Mintable token in truffle environment(the source file is ERC20Mintable.sol).

The mint function is declared with onlyMinter modifer:

contract ERC20Mintable is ERC20, MinterRole { function mint(address account, uint256 amount) public onlyMinter returns (bool) { _mint(account, amount); return true; } } 

Minter role info is:

truffle(develop)> instance.isMinter(accounts[0]) true truffle(develop)> instance.isMinter(accounts[1]) false truffle(develop)> instance.isMinter(accounts[2]) false truffle(develop)> instance.isMinter(accounts[3]) false 

However,when I try to mint token, I found the modifier can not take effect to control the function call right:

For the first account:

truffle(develop)> instance.mint(accounts[0],1000) { tx: '0x323ff19c7b79cbe545914465c9bda87aa5169cdaa3be6f4ccbebcd7e7eb76617', receipt: { transactionHash: ... truffle(develop)> instance.totalSupply() <BN: 3e8>//1000 

For the second account:

truffle(develop)> instance.mint(accounts[1],1000) { tx: '0xc13da9ca6ba8b74e998b4b158eb1be02208e2bc8f08c789f4a6a306bedadc7a1', receipt: { transactionHash: truffle(develop)> instance.totalSupply() <BN: 7d0>//2000 truffle(develop)> instance.balanceOf(accounts[0]) <BN: 3e8>//1000 truffle(develop)> instance.balanceOf(accounts[1]) <BN: 3e8>//1000 truffle(develop)> instance.balanceOf(accounts[2]) <BN: 0> 

From the result, every account is able to mint token, onlyMinter has no capability to control function call role.

How can I fix the problem? Thanks.