ERC20Detailed.sol not found in @openzeppelin/contracts/token/ERC20 on GitHub

:computer: Environment

I’m using Truffle v5.1.32

:memo:Details

After installing openzepplin package from npm, I tried importing the above contracts but it reverted with TypeError in the terminal complaining about import “@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol” file.
Error: Could not find @openzeppelin/contracts/token/ERC20/ERC20Detailed.sol from any sources. Could there an update on openzepplin repo removing or renaming the ERC20Detailed.sol file?

:1234: Code to reproduce

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";

contract Dai is ERC20, ERC20Detailed {
    constructor() public ERC20Detailed("Dai Stablecoin", "DAI", 18) {
    }
}
1 Like

Hi @Sam-Devs,

Welcome to the community :wave:

I assume you are looking at a tutorial or guide which uses OpenZeppelin Contracts v2.x whilst installing OpenZeppelin Contracts v3.x.

The latest version of OpenZeppelin Contracts is v3.1.0

See the release notes for v3.0.0

Migrating From OpenZeppelin Contracts v2.5

...
If you're using the ERC20 or ERC721 tokens however, you'll have to remove all references to optional extensions ( ERC20Detailed , ERC721Enumerable , etc.) - these have been included in the base contracts.

A Simple Token using OpenZeppelin Contracts v3.x is as follows:

SimpleToken.sol

// contracts/SimpleToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 */
contract SimpleToken is ERC20 {

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor () public ERC20("Simple Token", "SIM") {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

Alternatively you can install OpenZeppelin Contracts v2.x

$ npm install @openzeppelin/contracts@2.5.1

Thank you, I had to install @openzeppelin/contracts@2.4.0 to fix this problem.

2 Likes

Hi @Sam-Devs,

Glad you were able to resolve.

If you were following a tutorial, do you mind sharing the link?

A post was split to a new topic: Upgradeable token

@abcoathup if Detailed is included, would you please include an example how to set decimals in latest release? I landed here from: Understanding decimals for ERC20 token creation? - #2 by abcoathup

found sample of overriding decimal but not of overloading, tried:

    constructor(
        string memory name,
        string memory symbol,
        uint256 initialSupply,
        uint8 decimal
    ) public ERC20(name, symbol) {
        // _setupDecimals(6); (not available in 4.x)
        _mint(owner, initialSupply);
    }

deployed Token.deploy('My Token', 'MT6', 1000, 6) but doesn't register on decimals:

      AssertionError: expected 18 to equal 6
      + expected - actual

      -18
      +6