1

Hello i have this question in my mind now :

How to publish in ethereum with "imports" ? or how to do ?

why i say this ?

answer : when i wanna "verify and publish Contract Source Code" with a normal code without "import" the verify is successful

the problem : but when i try to do the same with a code has a "import" in the code , the "verify" fails and say me this error

Error! Unable to generate Contract ByteCode and ABI (Compiler Exception)

the abi is fine but i think they cant generate the bytecode for this warnning :

myc:9:1: ParserError: Source "MyToken.sol" not found: File import callback not supported
import './MyToken.sol'
^-------------------------^

i trying to solving but nothing works for me and i don't know what i need to read to solve this problem and publish my contract, if somebody have documentation for solve this problem please help me

i am searching that errors but i don't see information to how solve them

here is a example of the running code

pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

import './MyToken.sol';

contract test1 {

    /* Variables */
    MyToken isMyToken;

    /* Constructor to define things */
    constructor(MyToken _myToken) public {

        isMyToken = _myToken;

    }


}

thanks a lot for read

1

Etherscan has introduced some multifile methods that might help with this.

The good old-fashioned method is to create a flat version of the contract for verification purposes. That can be done manually or with the help of a utility (google Solidity Flattener).

A flat version would be a single file Test1.sol where you remove the import and simply append the source code of MyToken.sol in the same file. It compiles to the same bytecode, which is what the verifier is trying to confirm.

Hope it helps.

| improve this answer | |
0

You can use Truffle-Flattener.

In your package.json file, add this:

  "dependencies": {
    "truffle-flattener": "1.4.2"
  }

Then, run the following NodeJS script passing your file name (without .sol) as input:

const WORK_DIR = "<YourProjectDir>";   // Fill your project's directory here
const NODE_DIR = "<node_modules Dir>"; // Fill your node_module directory here
const CONTRACT_NAME = process.argv[2];

const fs        = require("fs");
const path      = require("path");
const spawnSync = require("child_process").spawnSync;

function getPathNames(dirName) {
    let pathNames = [];
    for (const fileName of fs.readdirSync(WORK_DIR + "/" + dirName)) {
        if (fs.statSync(WORK_DIR + "/" + dirName + "/" + fileName).isDirectory())
            pathNames = pathNames.concat(getPathNames(dirName + "/" + fileName));
        else if (fileName.endsWith(".sol"))
            pathNames.push(dirName + "/" + fileName);
    }
    return pathNames;
}

function getSourceCode(pathName) {
    const result = spawnSync("node", [NODE_DIR + "/truffle-flattener/index.js", pathName], {cwd: WORK_DIR});
    return result.output.toString().slice(1, -1);
}

for (const pathName of getPathNames("contracts")) {
    const contractName = path.basename(pathName, ".sol");
    if (CONTRACT_NAME == contractName)
        console.log(getSourceCode(pathName))
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.