0

I'm trying to compile two different sol file with 1 smart contract each and output the compiled code of each one in two different json file. But when i run the code the .json file return empty, i dont find the problem. Here is my code

const path = require('path');
const fs = require('fs-extra');
const solc = require('solc');

const buildPath = path.resolve(__dirname,'Contracts', 'build');
fs.removeSync(buildPath);

const pathA = path.resolve(__dirname,'Contracts','StoreFactory.sol');
const sourceA = fs.readFileSync(pathA,'utf8');
const pathB = path.resolve(__dirname,'Contracts','Store.sol');
const sourceB = fs.readFileSync(pathB,'utf8');


const input = {
  sources : {
    'StoreFactory.sol' : sourceA,
    'Store.sol' : sourceB
}
}

const output = solc.compile(input,1).contracts;
console.log(output);


fs.ensureDirSync(buildPath);

for(let contract in output){
  fs.outputJsonSync(
    path.resolve(buildPath,contract.replace('.sol','.json')),
    output[contract]
  );
};


Your Answer

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

Browse other questions tagged or ask your own question.