Managing Imports with the Sol C compiler

Hi OZ community,

I am creating a dapp to generate daos. I want to use the OZ erc20, Governor etc. contracts to achieve this. I need the contracts to compile and deploy after a form on the front end is submitted. I have this working fine with the code below when i do not use the OZ contracts as I cannot figure out how to correctly configure the compiler to handle imports

const solc = require('solc');


function contractCompiler(contractData, name) {
  var input = {
    language: 'Solidity',
    sources: {
      "name": {
        content: contractData
      }
    },
    settings: {
      outputSelection: {
        '*': {
          '*': ['*']
        }
      }
    }
  };
  
  const output = JSON.parse(solc.compile(JSON.stringify(input)));
  
  let res;

  switch(name) {
    case 'Token.sol':
      res = [output.contracts.name.Token.abi, output.contracts.name.Token.evm.bytecode];
      break;
    case 'Timelock.sol':
      res = [output.contracts.name.Timelock.abi, output.contracts.name.Timelock.evm.bytecode];
      break;
      case 'Box.sol':
      res = [output.contracts.name.Box.abi, output.contracts.name.Box.evm.bytecode];
      break;
    case 'Governance.sol':
      res = [output.contracts.name.Governance.abi, output.contracts.name.Governance.evm.bytecode];
      break;
  }

  return res;
};

module.exports = contractCompiler;

The Sol C github has provided an example on handling a single import but how would i work this to handle multiple imports for multiple contracts? (https://github.com/ethereum/solc-js#example-usage-with-import-callback)

Any help would be greatly appreciated

Hi @shanedunne. You should look into adding additional entries to the sources field in the input object, one for each possible dependendency that the code may import. In your case it's probably possible to enumerate them. But it will be a lot of entries. You should look at the input generated by Hardhat, look for the files in artifacts/build-info after you comiple.