Unable to import Address.sol in ERC20 token using Remix?

Hello everybody,
I am using remix to create my erc20 token and everything is ok except, when I try to compile, this message appears and I don’t understand it :

“Unable to import “utils/Address.sol”: File not found”

What does it mean ? How to remedy to this problem ?

Thank you very much for helping people.

Hello @GerardM, would you mind sharing your contract code and project’s directory structure so we can diagnose what’s the issue?

Hello,
Actually it finally worked :slight_smile: Thank you Sir.

Sorry i didn’t see you asked me to share the code. It’s a very basic token with fixed supply, not mint, burn, or pausable functions :

    pragma solidity 0.6.0;

    import "../../GSN/Context.sol";
    import "./IERC20.sol";
    import "../../math/SafeMath.sol";
    import "../../utils/Address.sol";


    contract  ERC20 is tfsc, IERC20 {
        using SafeMath for uint256;
        using Address for address;

        mapping (address => uint256) private _balances;

        mapping (address => mapping (address => uint256)) private _allowances;

        uint256 private _100000000;

        string private _name;
        string private _symbol;
        uint8 private _decimals;

        
        constructor (string memory tfsc, string memory TFS) public {
            _name = tfsc;
            _symbol = tfs;
            _decimals = 18;
        }

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

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

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

        /**
         * @dev See {IERC20-totalSupply}.
         */
        function totalSupply() public view override returns (uint256) {
            return _totalSupply;
        }

        
        function balanceOf(address account) public view override returns (uint256) {
            return _balances[account];
        }

        
        function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
            _transfer(_msgSender(), recipient, amount);
            return true;
        }

        
        function allowance(address owner, address spender) public view virtual override returns (uint256) {
            return _allowances[owner][spender];
        }

        
        function approve(address spender, uint256 amount) public virtual override returns (bool) {
            _approve(_msgSender(), spender, amount);
            return true;
        }

        
        function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
            _transfer(sender, recipient, amount);
            _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
            return true;
        }

        
        function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
            _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
            return true;
        }

        
        function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
            _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
            return true;
        }

       
        function _transfer(address sender, address recipient, uint256 amount) internal virtual {
            require(sender != address(0), "ERC20: transfer from the zero address");
            require(recipient != address(0), "ERC20: transfer to the zero address");

            _beforeTokenTransfer(sender, recipient, amount);

            _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
            _balances[recipient] = _balances[recipient].add(amount);
            emit Transfer(sender, recipient, amount);
        }


        
        function _approve(address owner, address spender, uint256 amount) internal virtual {
            require(owner != address(0), "ERC20: approve from the zero address");
            require(spender != address(0), "ERC20: approve to the zero address");

            _allowances[owner][spender] = amount;
            emit Approval(owner, spender, amount);
        }

        function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
    }

Great that you made it work! It seemed to be an import path mistake, right?

1 Like

Thank you :slight_smile: Yes indeed. I saw it on a youtube tuto.

1 Like

Hi @GerardM,

I wasn't sure how you had installed OpenZeppelin Contracts.

We recommend installing OpenZeppelin Contracts via npm. See Installation for details.

To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself.

For a fixed supply ERC20 token please see the example in the documentation: Constructing an ERC20 Token Contract

1 Like

Hello :slightly_smiling_face:
The npm installation never works for me. I installed the contract as bellow :slight_smile:

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/GSN/Context.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol";


contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

  constructor (string memory tokentest, string memory tkt) public {
        _name = tokentest;
        _symbol = tkt;
        _decimals = 18;
        _mint(msg.sender, 1e18);
    }
    
    function name() public view returns (string memory) {
        return _name;
    }

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

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

    
    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }

    
    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }

    
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    

    
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

   

  
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

Thanks to everybody here :smiley:

1 Like

Hi @GerardM,

Are you using Remix?

:warning: When importing via GitHub, you should specify the release tag, otherwise you will get the latest code in the master branch. For OpenZeppelin Contracts you should only use code published in an official release. The latest release is OpenZeppelin Contracts v3.1.0 . (see Importing from GitHub in the Remix documentation).

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/presets/ERC20PresetMinterPauser.sol";
1 Like

Thank you,
Yes, I do use Remix

1 Like

I think i have corrected here as you said

:slight_smile:

1 Like

Hi @GerardM,

That looks ok to me. Though on the IERC20.sol it looks like you have a space between v3.1.0 and /

As you are using Remix, you may like to go through this tutorial:
Create an ERC20 using Remix, without writing Solidity

1 Like