Skip to content

Instantly share code, notes, and snippets.

@ihorbond
Created December 22, 2021 00:19
Show Gist options
  • Save ihorbond/31691c65594ec5009bdc114e96707901 to your computer and use it in GitHub Desktop.
Save ihorbond/31691c65594ec5009bdc114e96707901 to your computer and use it in GitHub Desktop.
Solc compiler js
function findImports(missingImport) {
if (missingImport.startsWith('@openzeppelin')) {
console.log(`reading import ${missingImport}`)
return {
contents: fs.readFileSync(path.join('../node_modules', missingImport), 'utf8')
};
}
else {
console.log(`import ${missingImport} not found`);
return { error: 'File not found' };
}
}
const input = {
language: 'Solidity',
sources: {
[templateName]: {
content: contractContents
}
},
settings: {
outputSelection: { // return everything
'*': {
'*': ['*']
}
}
}
}
const output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment