[Ethereum] File import callback not supported in solcjs

solcjssolidity

Running E:\projects\Greeter-Contract-master\contracts>solcjs --abi Greeter.sol gives:

Greeter.sol:3:1: ParserError:
Source "contracts/Mortal.sol" not found: File import callback not supported
import "contracts/Mortal.sol";
^----------------------------^

Greeter.sol:

pragma solidity ^0.6.4;

import "contracts/Mortal.sol";

contract Greeter is Mortal {
    string greeting;
   constructor( string memory _greeting) public {
        greeting = _greeting;
    }

    function changeGreeting(  string memory _greeting) public {
        greeting = _greeting;
    }

    function greet() public view returns (string memory) {
        return greeting;
    }
}

Mortal.sol:

pragma solidity ^0.6.4;

contract Mortal {
    /* Define variable owner of the type address */
    address payable owner;

    /* This function is executed at initialization and sets the owner of the contract */
    constructor() public { owner = msg.sender; }

    /* Function to recover the funds on the contract */
    function kill() public {
        if (msg.sender == owner) 
            selfdestruct(owner); 
    }
}

Best Answer

There are essentially two different problems in import "contracts/Mortal.sol":

  1. For a local files, the input path name must start with ./
  2. Since your files reside under folder contracts, you should not add it to the relative path

So in short, change this:

import "contracts/Mortal.sol";

To this:

import "./Mortal.sol";