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?
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) {
}
}
...
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