1

had an earlier version of this contract work fine. After peer review mods, it wont allow the contract- EEKER4 to create. Says the contract needs all functions to be implemented yet it passes compilation.

Any Insights would be well appreciated as am a noob.

pragma solidity ^0.4.14;
//Fixed Base EAee supply token contract
// (c) 7/7/2017. The MIT Licence.;
// define standard fields for ERC20 contract
contract ERC20 {
   // uint public totalSupply; // NOTE(en): this should not be exposed, use a getter function instead
   // NOTE from Jacks: almost every token contract uses public uint variable. Total supply of your tokens is not a big secret I think. 
    string public standard = 'ERC20';
    function balanceOf(address who) constant returns (uint);
    function allowance(address owner, address spender) constant returns (uint);
    function transfer(address to, uint value) returns (bool ok);
    function transferFrom(address from, address to, uint value) returns (bool ok);
    function approve(address spender, uint value) returns (bool ok); 
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}
// needed to add restrictions who could execute commands (in this case owner - person who deployed the contract)
contract Ownable {
    address public owner;
    function Ownable() {
        owner = msg.sender;
    }

        modifier onlyOwner {
        assert(msg.sender == owner);
        _;
    }

    function transferOwnership(address newOwner) onlyOwner {
        if (newOwner != address(0)) owner = newOwner;
    }
}
// best practice to use safe mathematic operations to avoid major problems
library SafeMath { // NOTE (hen): use "library" contract is better
    function safeMul(uint a, uint b) internal returns (uint) {
        uint c = a * b;
        assert(a == 0 || c / a == b);
        return c;
    }

    function safeDiv(uint a, uint b) internal returns (uint) {
        // assert(b > 0); // NOTE (ihen): solidity will automatically throws when divided by 0
        uint c = a / b;
        // assert(a == b * c + a % b); NOTE (izgzhen): unnecessary
        return c;
    }

    function safeSub(uint a, uint b) internal returns (uint) {
        assert(b <= a);
        return a - b;
    }

    function safeAdd(uint a, uint b) internal returns (uint) {
        uint c = a + b;
        assert(c >= a); // a + b can't be larger than or equal to a when overflowed
        return c;
    }

    function max64(uint64 a, uint64 b) internal constant returns (uint64) {
        return a >= b ? a : b;
    }

    function min64(uint64 a, uint64 b) internal constant returns (uint64) {
        return a < b ? a : b;
    }

    function max256(uint256 a, uint256 b) internal constant returns (uint256) {
        return a >= b ? a : b;
    }

    function min256(uint256 a, uint256 b) internal constant returns (uint256) {
        return a < b ? a : b;


    }
  }
contract TokenSpender {
    function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);
}
contract EEKER4 is ERC20, Ownable {
    using SafeMath for uint256;
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;
    string public version = 'v1.0';
    // uint public initialSupply; // useless if it is hardcoded in constructor
    uint public totalSupply;
    mapping (address => uint) public balances; // NOTE(hen): those should be public
    mapping (address => mapping (address => uint)) public allowed;

    function EEKER4() {
        totalSupply = 1000000;

        balances[msg.sender] = 1000000;
        name = 'EEKER4';
        symbol = 'EK4';
        decimals = 18;
    }
    function transfer(address _to, uint _value) returns (bool) {
        if (balances[msg.sender] >= _value &&
            _value > 0 /* zero transfer is not allowed */ &&
            balances[_to] + _value > balances[_to] /* check overflow */) {


             balances[msg.sender] = balances[msg.sender] - _value;
            balances[_to] = balances[_to] + _value;
            Transfer(msg.sender, _to, _value);
            return true;
        } else {
            return false;
        }
    }
    function transferFrom(address _from, address _to, uint _value) returns (bool) {
        if (balances[_from] >= _value &&
            allowed[_from][msg.sender] >= _value &&
            _value > 0 &&
            balances[_to] + _value > balances[_to]) {
             balances[_from] -= _value;
             allowed[_from][msg.sender] -= _value;
             balances[_to] += _value;
             return true;
          } else {
             return false;
         }
    }

     /* Approve and then comunicate the approved contract in a single tx */
        function approveAndCall(address _spender, uint256 _value, bytes _extraData) {
         TokenSpender spender = TokenSpender(_spender);
         if (approve(_spender, _value)) {
             spender.receiveApproval(msg.sender, _value, this, _extraData);
         }
    }
    function allowance(address _owner, address _spender) constant returns (uint remaining) {
    return allowed[_owner][_spender];
  }
}

1 Answer 1

1

Under contract TokenSpender, the function

function `receiveApproval`(address _from, uint256 _value, address _token, bytes _extraData);

signature is provided but the function body, i.e., the body implementation is not given(what the function has to do). Due to which it will compile since there is no code error but gives the functions are not implemented so instance of the contract is not generated (contract instance of TokenSpender is being used in EEKER4).

Just define the function body of receiveApproval

1
  • Thanks Aviral. The prior edition worked with that same call like that though. On further hunting, it appears that function is complete as seen in Ethereum site -ethereum.org/token#the-code and this other guy confirmed too its a fallback function ethereum.stackexchange.com/questions/12852/…. I think am getting warmer, just wanted to avoid the grinding..am running out of runway soon.
    – oncebitten
    Commented Aug 10, 2017 at 20:43

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.