0

I have a token created using OpenZeppelin library. I use the CappedToken contract.

My code is :

pragma solidity ^0.4.18;

import 'openzeppelin-solidity/contracts/token/ERC20/CappedToken.sol';

contract YLBToken is CappedToken {
    string public name = "My Token Beta";
    string public symbol = "MTB";
    uint8 public decimals = 18;

    function YLBToken(uint256 cap) CappedToken(cap) {
    }
}

Using truffle I compile and test it. I migrated to Ropsten.

I created a web page to run it.

<html>
    <head>
        <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
        <script type='text/javascript'>
            var deployedContract;
            const ADDRESS = "0xcbcc819866a24a777b0c076d4922c127de9ecb06";
            const ABI = MY_ABI;

            // Init and detect metamask
            window.addEventListener('load', function () {
                if (typeof web3 !== 'undefined') {
                    web3 = new Web3(web3.currentProvider);
                    currentAccount = web3.eth.accounts[0];
                } else {
                    // set the provider you want from Web3.providers
                    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
                    console.log("Metamask or similar not detected");
                }

                deployedContract = web3.eth.contract(ABI).at(ADDRESS);
                deployedContract.mint(currentAccount, parseInt(1000) * 1000000000000000000, { from: currentAccount, gasPrice: web3.toWei(1, 'gwei') }, function (error, result) {
                    if (!error) {
                        console.log("Mint result = " + result);
                    }
                    else {
                        console.log(error);                        
                    }
                });
            })
        </script>
    </head>
    <body>  
    </body>
</html>

I expect Metamask to open and after clicking submit to mint 1000 tokens on the owner address, just to test is working fine. I have it running into a webserver.

But this is what Metamask shows :

Metamask showing the message "Transaction error. Exception thrown in contract code

I have no clue why Metamask shows this message. Using truffle test the mint function works fine. Using Metamask pointing to localhost:8545 and running testrpc in a console also worked fine.

Can someone point me to a solution?

1

Answering my own question:

The message "Transaction error. Exception thrown in contract code" appears when some of the "requires" in your solidity code is triggered.

In my case, I was setting a cap in the migration file of truffle of 10.000 and when minting I was using :

parseInt(1000) * 1000000000000000000

because of the 18 decimals.

So 100000000000000000000000 > cap and the error was thrown

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.