Created
December 22, 2021 00:19
-
-
Save ihorbond/31691c65594ec5009bdc114e96707901 to your computer and use it in GitHub Desktop.
Solc compiler js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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