1

I am creating simple ERC20 token which involves functions like

transfer burn totalsupply transferFrom burnFrom How can I check function transferFrom and burnFrom from remix browser because it involves approve and allowance and whenever I run these function I am getting error . Here is my contract

```

pragma solidity ^ 0.4.21;

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

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


contract MyFirsttoken is ERC20Interface {

    address public owner;
    uint256 totalsupply;
    string tokenname;
    string tokensymbol;
    uint8 decimal;

    event Burn(address,uint256 amount);

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

    function MyFirsttoken(uint256 tokensupply, string symbol, string name){

    owner = msg.sender;
    totalsupply = tokensupply;
    tokenname =   name;  
    tokensymbol = symbol;    
    balances[owner] = totalsupply;
    }

    function totalSupply() public constant returns(uint){
        return totalsupply;
    }

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

    function transfer(address tos,uint amount) public returns(bool)  {
    require(amount <= balances[msg.sender]);
    balances[msg.sender]-= amount;
    balances[tos] +=amount;
    emit Transfer(msg.sender,tos,amount);   
    }    


    function transferFrom(address from, address to ,uint256 tokens)public returns (bool success){
        uint256 allowedbalance = allowance(from ,to);
        require(tokens <= allowedbalance);
        balances[from] -= tokens;
        balances[to] += tokens;
        emit Transfer(from,to,tokens);
    }

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

    function approve(address spender,uint256 amount) public returns(bool success){
        allowed[msg.sender][spender]=amount;
        emit Approval(msg.sender,spender,amount);
    }


    function burnabletoken(uint256 burnableamount)returns (bool){
        require(msg.sender == owner);
        require(balances[msg.sender]>=burnableamount);
        balances[msg.sender] -= burnableamount ;
        totalsupply -= burnableamount;
        emit Burn(msg.sender,burnableamount);


    }


    function burnfrom(address from , uint256 burnableamount){

        require(balances[from] >= burnableamount);
        require(burnableamount <= allowed[from][msg.sender]);
        allowed[from][msg.sender] -= burnableamount;
        balances[from] -= burnableamount;
        totalsupply -= burnableamount;
        emit Burn(from,burnableamount);

    }

}

```

1
  • 1
    what error do you get?
    – Jaime
    Jul 30, 2018 at 13:35

2 Answers 2

0

In order to call transferFrom() you first have to call approve().

Let's say you have users A and B

  • User A approves user B

    token.approve(B, 1000, { from: A })
    
  • User B now is able to access up to 1000 tokens from A and transfer them to C

    token.transferFrom(A, C, 500, { from: B })
    
0

The problem is your functions transfer, transferFrom, approve, burnabletoken are not returning any value but these functions are expected to return bool. Also consider the order of execution as mentioned by @ismael in above answer.

Hope it will solve the issue.

Your Answer

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

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