1

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.

1 Answer 1

1

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);
2
  • And is it possible to modify the contract itself, or I have to create a new one?
    – Jabaco
    Commented Oct 14, 2017 at 1:14
  • 1
    @Jabaco it is not possible to directly modify the source code of smart contracts. You have to deploy a new one.
    – Alex
    Commented Oct 14, 2017 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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