Creating fee on transfer ERC20 - ERC20Detailed not found

i have copied your code, but when i try to compile it on remix it gives me error… that not found openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";

1 Like

I think when you try to compile the contract, you should change the import, such as:

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Detailed.sol";

Or you can run npm i @openzeppelin/contracts@2.5.0 to install it in your local environment and then upload to the Remix.

1 Like

not working…say you are setting it into remix how would you do it

1 Like

So what is your source code?

1 Like

Hi @coderbang1,

The code in the forum uses OpenZeppelin Contracts 2.x. You could port it to OpenZeppelin Contracts 4.x

Please note, fee on transfer/deflationary tokens can cause issues, see: Points to consider when creating a fungible token (ERC20, ERC777)

Can i have a standard erc20 token with burn and mint functionality

1 Like

Hi @coderbang1,

You should be able to create a deflationary token.

To add functionality to an OpenZeppelin Contracts ERC20 you can use hooks: https://docs.openzeppelin.com/contracts/4.x/extending-contracts#using-hooks

I was asking if you give me any examples. I want to learn. It shouldn’t be a deflationary token.

Hi @coderbang1,

You can use the old example in the forum and update it to OpenZeppelin Contracts 4. If you get stuck, please post in the forum.

I won’t be able to write one for you.

i have created simple token… but burn functionality is not working. i have check multiple time but couldn’t find the error.

here is my code

    pragma solidity ^0.5.0;

// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
//
// ----------------------------------------------------------------------------

         contract IBEP20 {
          function totalSupply() public view returns (uint);
    function balanceOf(address tokenOwner) public view returns (uint balance);
    function allowance(address tokenOwner, address spender) public view 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);
}

// ----------------------------------------------------------------------------
// Safe Math Library
// ----------------------------------------------------------------------------

    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 MONK is IBEP20, SafeMath {
    string public name;
    string public symbol;
    uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it

    uint256 public _totalSupply;

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

    /**
     * Constrctor function
     *
     * Initializes contract with initial supply tokens to the creator of the contract
     */
    constructor() public {
        name = "MY";
        symbol = "My";
        decimals = 18;
        _totalSupply = 1000000000;

        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 balance) {
        return balances[tokenOwner];
    }

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

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

       
    function transfer(address to, uint tokens) public returns (bool success) {
        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 success) {
        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;
    }
    function burn(uint256 amount) external {
    _burn(msg.sender, amount);
  }

    function _burn(address account, uint256 amount) internal {
    require(amount != 0);
    require(amount <= _balances[account]);
    _totalSupply = _totalSupply.sub(amount);
    _balances[account] = _balances[account].sub(amount);
    emit Transfer(account, address(0), amount);
  }

    function burnFrom(address account, uint256 amount) external {
    require(amount <= _allowed[account][msg.sender]);
    _allowed[account][msg.sender] = _allowed[account][msg.sender].sub(amount);
    _burn(account, amount);
  }
    
}

It looks like your code is ok, and what is the wrong? Can not you call the function? What is the error message?

1 Like

Its giving error while compiling in remix.