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

   Deploying 'ERC20Mintable'
   > transaction hash:    0x02c7b8e1dbde226304614ceeea48e1d4eb123bd1a70e73b1955d8718f3d49e08
   > Blocks: 0            Seconds: 0
   > contract address:    0x25CcB91c6643a0679591F888c3a16B12745b9594
   > block number:        3
   > block timestamp:     1562326476
   > account:             0x6D04f90886E0651381c174B2752C6c0F06626a54
   > balance:             99.96399902
   > gas used:            1496633
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.02993266 ETH
   > Saving migration to chain.
   > Saving artifacts
   > Total cost:          0.02993266 ETH

the 2_mintable.js code is:

const ERC20Mintable = artifacts.require("ERC20Mintable.sol");
module.exports = function(deployer) {

I want to check whether accounts[0] is minter, and call function as below:

let instance = await ERC20Mintable.deployed()//It can display correct contract info.
let accounts = await web3.eth.getAccounts()

there is an error information like below, how to fix the problem, many thanks!

truffle(develop)> instance.MinterRole.isMinter(accounts[0])

TypeError: Cannot read property 'isMinter' of undefined
    at evalmachine.<anonymous>:0:21
    at sigintHandlersWrap (vm.js:285:15)
    at Script.runInContext (vm.js:127:14)
    at runScript (/usr/local/lib/nodejs/node-v10.15.3-linux-x64/lib/node_modules/truffle/build/cli.bundled.js:368533:21)
    at Console.interpret (/usr/local/lib/nodejs/node-v10.15.3-linux-x64/lib/node_modules/truffle/build/cli.bundled.js:368548:21)
    at ReplManager.interpret (/usr/local/lib/nodejs/node-v10.15.3-linux-x64/lib/node_modules/truffle/build/cli.bundled.js:369389:18)
    at bound (domain.js:395:14)
    at REPLServer.runBound [as eval] (domain.js:408:12)
    at REPLServer.onLine (repl.js:639:10)
    at REPLServer.emit (events.js:189:13)
  • do you need .MinterRole between instance and isMinter(accounts[0]) ? – Majd TL Jul 5 '19 at 12:30
  • I need assign a miner address,for instance,accounts[0]. but from the source code, I can not found how to do it. – Ntydrm Jul 7 '19 at 2:07

Read the top of the ERC20Mintable.sol file (which you have linked at the top of your own question):

contract ERC20Mintable is ERC20, MinterRole ...

Contract ERC20Mintable IS MinterRole (in contrast with HAS MinterRole).

This mean that ERC20Mintable inherits all the (non-private) functions and variables of MinterRole.

Hence you should call the function directly:

  • Thanks, It works now. Function instance.isMinter() will return correct value. the accounts[0] is miner, the other nince accounts are not. But when I try to call instance.mint(accounts[1],1000), it also can mint coin.The minted coin will be go into account[1]. I can not understand why it happens even the mint() function has modifer onlyMinter. so how to control the right who can call mint() function indeed? Thanks for your help. – Ntydrm Jul 7 '19 at 4:50
  • @Ntydrm: This sounds like a completely different problem, so I suggest that you post it as a separate question. – goodvibration Jul 7 '19 at 6:11
  • Done.Thanks for you comment.The link for new question is ethereum.stackexchange.com/questions/72667/… – Ntydrm Jul 8 '19 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.