As a context I am trying to fork uniswap v2 contracts using my own compiler and deploy files. I am not using truffle, as I want to deeply understand before using a framework.
When I run my compiler, I get this error :
formattedMessage: 'Contract:3:1: ParserError: Source "interfaces/IUniswapV2Factory.sol" not found: File import callback not supported\n' +
"import './interfaces/IUniswapV2Factory.sol';\r\n" +
'^------------------------------------------^\n',
message: 'Source "interfaces/IUniswapV2Factory.sol" not found: File import callback not supported',
I tried to copy all contracts into the contract that I was trying to deploy, and it worked. But I can't do this for every contract …
Here is my compiler file :
`
const path = require("path");
const solc = require("solc"); //don't forget to install the right solc version !
const fs = require("fs-extra");
const buildPath = path.resolve(__dirname, "build");
fs.removeSync(buildPath);
function compileContract(Contract) {
const contractPath = path.resolve(__dirname, "./", Contract);
const contractSourceCode = fs.readFileSync(contractPath, "utf8");
fs.ensureDirSync(buildPath);
var input = {
language: 'Solidity',
sources: {
Contract : {
content: contractSourceCode
}
},
settings: {
optimizer: {
enabled: true
},
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
console.log(output);
for(let contractName in output.contracts.Contract) {
fs.outputJsonSync(
path.resolve(buildPath, `${contractName}.json`),
output.contracts.Contract[contractName]
);
}
}
// compileContract("UniswapV2Pair.sol");
compileContract("UniswapV2Factory.sol");
compileContract("UniswapV2ERC20.sol");
I am using solc@0.5.16
And here are the files I am trying to deploy : https://github.com/Uniswap/uniswap-v2-core/tree/master/contracts
Best Answer
Here is the code that I wrote to compile files with import statements with solc@0.5.16. The script compile the files and put them into a build folder as a json file.
Thanks for helping me making this !