-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support imports in solcjs CLI #114
Comments
Just seen this note in readme:
Which answers my question! What's the reason for this/any scope for improving it in the future? |
@lukehedger someone needs to do implement it. If you are interested adding support for it, please make a PR and we're happy to help to finish and include that feature. |
Happy to look at adding support but would you be able to point me in the right direction to get started? Would the feature be added to the JS bindings or to the compiler itself? |
This is a feature missing in the |
Just came across this tool which may be of use in the meantime: https://github.com/TiesNetwork/solidify |
I solved this by doing the below as things have been improved as of 0.2.1: var solc = require('solc');
var fs = require('fs');
var inputs = {
'auction.sol': fs.readFileSync('auction.sol').toString(),
};
// Assumes imported files are in the same folder/local path
function findImports(path) {
return {
'contents': fs.readFileSync(path).toString()
}
}
var compiledCode = solc.compile({sources: inputs}, 1, findImports)
fs.writeFile('compiled.json', JSON.stringify(compiledCode), function(err) {
if (err) throw err;
console.log('Compiled & saved');
}); I then read in compiled.json later in a .js file using web3 to use it via a browser using browserify: compiledCode = JSON.parse(fs.readFileSync('compiled.json').toString());
//console.log(compiledCode);
abi = JSON.parse(compiledCode.contracts['auction.sol:ContractName'].interface);
bytecode = compiledCode.contracts['auction.sol:ContractName'].bytecode; Hope this is helpful to someone else. |
so writing import is just a fun activity that solc dont understand ? |
It looks like if var fs = require('fs')
var path = require('path')
function findImports(importPath, sourcePath) {
try {
var filePath = path.resolve(sourcePath, importPath)
return { contents: fs.readFileSync(filePath).toString() }
} catch (e) {
return { error: e.message }
}
}
solc.compile(..., findImports) Is there a way to receive the source path too? I tried looking in the |
solcjs --abi contract.sol |
@kangdao try it: solcjs --bin contract.sol |
@axic I tried to include all imported contracts, but it still fails for me (Windows, version
|
The feature is not implemented yet. Passing multiple contracts will work unfortunately. |
Bingo! I have a fix that works!! This will simply compile all the
and in solc.compile just pass this as the last parameter like so
|
wer shld be the utilis.js and compile.js shld be added? |
@akiabi Could be at the project root dir? |
Hi |
Can you come to the solidity gitter / matrix channel as described in the readme: https://github.com/ethereum/solidity#readme ? |
Given the following directory structure:
Where
Source.sol
:Running the following command:
Based on the docs, I would expect the compiler to resolve the import but instead it throws:
If I include
Imported.sol
as a source file it will compile without error:Could you clarify my understanding here or is this a bug? Thanks! 🙃
The text was updated successfully, but these errors were encountered: