Hello there,
Structure of my folder:
- package.json
- node_modules/
- ethereum/
-
- compile.js
-
- contracts/
-
-
- TokenSwap.sol
-
Import in my TokenSwap.sol contract:
pragma solidity ^0.8.11;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
I am trying to compile my contract locally with solc but I get the following error:
ParserError: Source "@openzeppelin/contracts/token/ERC20/IERC20.sol" not found: File import callback not supported
I used npm i @openzeppelin/contracts
The command I use in my package.json file:
"compileContract": "node ethereum/compile.js",
Dependencies:
"dependencies": {
"@openzeppelin/contracts": "^4.4.2",
"solc": "^0.8.11",
My compile.js script:
const path = require("path");
const solc = require("solc");
const fs = require("fs-extra");
const tokenswapPath = path.resolve(__dirname, "contracts", "TokenSwap.sol");
const source = fs.readFileSync(tokenswapPath, "utf8");
var input = {
language: "Solidity",
sources: {
"TokenSwap.sol": {
content: source,
},
},
settings: {
outputSelection: {
"*": {
"*": ["*"],
},
},
},
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
console.log(output);
No matter how I format the import path for OpenZeppelin I get the same error
Please help