Contract Debugging – Fixing ‘Error Encountered During Contract Execution’

contract-debuggingetherscan

I have created a smart contract to issue an ERC20 token, but when I try to send the token from one address to another I get a "Warning! Error encountered during contract execution [Bad instruction]" message on etherscan.io. The token is already created and the contract is validated.

Also, I´m able to send tokens from the address holding the tokens but once I try to send from a receiver address, I get the error.

You can see the failed transactions here.

Best Answer

Your contract has a bug

/* Internal transfer, only can be called by this contract */
    function _transfer(address _from, address _to, uint _value) internal {
        require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
        require (balanceOf[_from] > _value);                // Check if the sender has enough
        require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
        balanceOf[_from] -= _value;                         // Subtract from the sender
        balanceOf[_to] += _value;                            // Add the same to the recipient
        Transfer(_from, _to, _value);
    }

It will not allow to transfer the full amount of tokens, it has to be strictly less. Instead of 12000, try 11999.

You have to modify your contract to

require (balanceOf[_from] >= _value);
Related Topic