0

I have deployed my first coin, a ERC20 contract, on Rinkeby. But when I send ether to the contracts address, the transactions get cancelled with a state called "fail".

Code:

pragma solidity ^0.4.10;

import 'zeppelin-solidity/contracts/math/SafeMath.sol';
import 'zeppelin-solidity/contracts/token/ERC20.sol';

contract StandardToken is ERC20 {
  using SafeMath for uint;

    string internal _name;
    string internal _symbol;
    uint8 internal _decimals;
    uint256 internal __totalSupply;

    mapping (address => uint256) internal balances;
    mapping (address => mapping (address => uint256)) internal allowed;

    constructor(string name, string symbol, uint8 decimals, uint256 totalSupply) public {
        _symbol = symbol;
        _name = name;
        _decimals = decimals;
        __totalSupply = totalSupply;
        balances[msg.sender] = totalSupply;
    }

    function name()
        public
        view
        returns (string) {
        return _name;
    }

    function symbol()
        public
        view
        returns (string) {
        return _symbol;
    }

    function decimals()
        public
        view
        returns (uint8) {
        return _decimals;
    }

   function transfer(address _to, uint256 _value) public returns (bool) {
     require(_to != address(0));
     require(_value <= balances[msg.sender]);
     balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value);
     balances[_to] = SafeMath.add(balances[_to], _value);
     Transfer(msg.sender, _to, _value);
     return true;
   }

  function balanceOf(address _owner) public view returns (uint256 balance) {
    return balances[_owner];
   }

  function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
    require(_to != address(0));
     require(_value <= balances[_from]);
     require(_value <= allowed[_from][msg.sender]);

    balances[_from] = SafeMath.sub(balances[_from], _value);
     balances[_to] = SafeMath.add(balances[_to], _value);
     allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value);
    Transfer(_from, _to, _value);
     return true;
   }

   function approve(address _spender, uint256 _value) public returns (bool) {
     allowed[msg.sender][_spender] = _value;
     Approval(msg.sender, _spender, _value);
     return true;
   }

  function allowance(address _owner, address _spender) public view returns (uint256) {
     return allowed[_owner][_spender];
   }

   function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
     allowed[msg.sender][_spender] = SafeMath.add(allowed[msg.sender][_spender], _addedValue);
     Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
     return true;
   }

  function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
     uint oldValue = allowed[msg.sender][_spender];
     if (_subtractedValue > oldValue) {
       allowed[msg.sender][_spender] = 0;
     } else {
       allowed[msg.sender][_spender] = SafeMath.sub(oldValue, _subtractedValue);
    }
     Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
     return true;
   }

}

I deployed this contract with truffle:

$ truffle migrate --network rinkeby
Using network 'rinkeby'.

Running migration: 2_standard_sale.js
  Deploying StandardToken...
  ... 0xbbeddd52e9c1c648d1cc4b0203c457e2ac65f0c52e32954552c699d32fab4b4b
  StandardToken: 0xf0a1b11c9742eccbfd6aa659359328bcb814edd5
Saving successful migration to network...
  ... 0xa567aa47e110338f60c45f3207fe9b7d5e5aba07165ba6d0179f7bcd8da6eee6
Saving artifacts...

and send some Ether to 0xf0a1b11c9742eccbfd6aa659359328bcb814edd5.

However, the transaction gots cancelled: https://rinkeby.etherscan.io/tx/0x34c8d36783bbdf54cd5f34808dac58c14c0ee77eaed0ce74621b9bf4fa5d6ab0

Unfortunately, the sent Ether is gone and wasn't refunded.

What could be wrong here?

1 Answer 1

1

You do not have a payable function, hence your contract cannot accept transactions including ether.

Concerning the ether that is gone, I don't get why. Normally, if your contract doesn't include a payable function, any ether sent to it is rejected. It could be because of the version of solidity you are using.

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.