1

I'm trying to deploy my first ERC20 token.

When I compile my basic code (that I write based on a guide) there is no problem but when I try to deploy him, there is an error: This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly.

I think it's a basic error but I don't understand why it's happening.

Can you please help me?

pragma solidity ^0.5.0;

contract ERC20Interface {
    function totalSupply() public  view returns (uint);
    function balanceOf(address tokenOwner) public  view returns (uint);
    function allowance(address tokenOwner, address spender) public  view returns (uint);
    function transfer(address to, uint tokens) public  returns (bool );
    function approve(address spender, uint tokens) public  returns (bool );
    function transferFrom(address from, address to, uint tokens) public  returns (bool);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}

contract SafeMath {
    function safeAdd(uint a, uint b) public pure returns (uint c) {
        c = a + b;
        require(c >= a);
    }
    function safeSub(uint a, uint b) public pure returns (uint c) {
        require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0);
        c = a / b;
    }

}


contract IPES_coin is ERC20Interface, SafeMath {
    string public name;
    string public symbol;
    uint8 public decimals; 

    uint256 public _totalSupply;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;

    constructor() public {
        name = "IPES_coin";
        symbol = "IPESC";
        decimals = 18;
        _totalSupply = 100000000000000000000000000;

        balances[msg.sender] = _totalSupply;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }

     function totalSupply() public  view returns (uint) {
        return _totalSupply  - balances[address(0)];
    }

    function balanceOf(address tokenOwner) public  view returns (uint) {
        return balances[tokenOwner];
    }

    function allowance(address tokenOwner, address spender) public view returns (uint) {
        return allowed[tokenOwner][spender];
    }

    function approve(address spender, uint tokens) public returns (bool) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }

    function transfer(address to, uint tokens) public returns (bool) {
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }

    function transferFrom(address from, address to, uint tokens) public returns (bool) {
        balances[from] = safeSub(balances[from], tokens);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(from, to, tokens);
        return true;
    }
}
0

Contract IPES_coin inherits from contract ERC20Interface, which declares the following functions:

function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

Hence it must implement each one of these functions in order to be deployable.

It seems that you have indeed implemented all of these functions, but then declared each one of them as public instead of external.

So change it in one place to match the other (I'd recommend changing external to public rather than vice-versa, because that's pretty much the standard in ERC20 tokens).

Also, in each one of the following functions:

function balanceOf(address tokenOwner) public view returns (uint balance) { ... }
function allowance(address tokenOwner, address spender) public view returns (uint remaining) { ... }
function approve(address spender, uint tokens) public returns (bool success) { ... }
function transfer(address to, uint tokens) public returns (bool success) { ... }
function transferFrom(address from, address to, uint tokens) public returns (bool success) { ... }

You need to get rid of the return-value name, because these functions otherwise return these (initialized-by-default-to-zero) variables, meaning in your case, 0s and falses.

| improve this answer | |
  • thank you for your answer but I don't get it, if I must get rid of the return-value name what must I return? a true or somthing else? And how can I change the contract of ERC20Interface to change it in public? P.S: I'm a real newbie and I don't really know what I'm doing so forgive me if I ask stupid question :) . – Endurs Mar 12 at 17:24
  • @Endurs: Just get rid of that name in the function declaration, for example, change returns(bool success) to returns(bool). Otherwise, the compiler ignores your return true statement at the end of the function, and returns the value of the success variable (which is false by default). BTW, as an alternative to that, you can replace the return true statement with success = true, and you'd get the same result (i.e., the compiler will return the value of the success variable even though you would have no return statement at the end of the function). Do you understand now? – goodvibration Mar 12 at 17:28
  • @Endurs: As to your second question - do you not have access to the source code of contract ERC20Interface??? – goodvibration Mar 12 at 17:28
  • no I don't have the sourc code but I temporarily change the public in external and make the change that you advised and my contract is still abstract. – Endurs Mar 12 at 18:58
  • @Endurs: No you didn't!!! I can see in that piece of code that you've posted as an answer (please delete it BTW), that you're still using returns (uint balance), returns (uint remaining), returns (bool success) and so forth!!! – goodvibration Mar 12 at 20:11

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.