Unable to flatten my ERC 20 token using Remix

Please help me to flatten this contract

    pragma solidity ^0.5.0;

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

contract Token is ERC20, ERC20Detailed, ERC20Burnable {

    constructor () public ERC20Detailed("Token", "TKN", 18) {
        _mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
    }
}

I used this in truffle

    rohankundu@Rohans-MacBook-Air ~ % cd Desktop
    rohankundu@Rohans-MacBook-Air Desktop % mkdir remixverify
    rohankundu@Rohans-MacBook-Air Desktop % cd remixverify
    rohankundu@Rohans-MacBook-Air remixverify % npm init -y
    Wrote to /Users/rohankundu/Desktop/remixverify/package.json:

    {
      "name": "remixverify",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
    }


    rohankundu@Rohans-MacBook-Air remixverify % npm i @openzeppelin/contracts@2.5.0
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN remixverify@1.0.0 No description
    npm WARN remixverify@1.0.0 No repository field.

    + @openzeppelin/contracts@2.5.0
    added 1 package from 1 contributor and audited 1 package in 4.486s
    found 0 vulnerabilities

    rohankundu@Rohans-MacBook-Air remixverify % truffle init

    Starting init...
    ================

    > Copying project files to /Users/rohankundu/Desktop/remixverify

    Init successful, sweet!

    rohankundu@Rohans-MacBook-Air remixverify % npm install openzeppelin-solidity
    npm WARN remixverify@1.0.0 No description
    npm WARN remixverify@1.0.0 No repository field.

    + openzeppelin-solidity@3.4.0
    added 1 package from 1 contributor and audited 2 packages in 5.597s
    found 0 vulnerabilities

    rohankundu@Rohans-MacBook-Air remixverify % npm install -g truffle-flattener
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
    npm WARN deprecated har-validator@5.1.5: this library is no longer supported
    /Users/rohankundu/.nvm/versions/node/v10.16.3/bin/truffle-flattener -> /Users/rohankundu/.nvm/versions/node/v10.16.3/lib/node_modules/truffle-flattener/index.js
    + truffle-flattener@1.5.0
    updated 1 package in 7.232s
    rohankundu@Rohans-MacBook-Air remixverify % touch contracts/SimpleToken.sol
    rohankundu@Rohans-MacBook-Air remixverify % atom .
    zsh: command not found: atom
    rohankundu@Rohans-MacBook-Air remixverify % atom .
    rohankundu@Rohans-MacBook-Air remixverify % truffle-flattener contracts/SimpleToken.sol > FlattenedSimpleToken.sol
    { Error: ENOENT: no such file or directory, open 'https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v2.5.0/contracts/token/ERC20/ERC20.sol'
        at Object.openSync (fs.js:443:3)
        at Object.readFileSync (fs.js:343:35)
        at resolve (/Users/rohankundu/.nvm/versions/node/v10.16.3/lib/node_modules/truffle-flattener/index.js:23:27)
      errno: -2,
      syscall: 'open',
      code: 'ENOENT',
      path:
       'https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v2.5.0/contracts/token/ERC20/ERC20.sol' }
    rohankundu@Rohans-MacBook-Air remixverify %
1 Like

By the Remix, you can import the dependency just like so:

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

But when you try to flatten contracts by the local env, I think you should use like following:

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

Then try to run your command truffle-flattener contracts/SimpleToken.sol > FlattenedSimpleToken.sol

1 Like

Thanks a lot it worked

2 Likes