The qsolc Python script creates a standard-JSON compiler input based on the provided input flags provided as key=value pairs. Then it runs solc on the created compiler input. qsolc uses the locally installed solc version (see solc --version
). You can save the output to a file by using the --output
flag. If no output flag is given, the result will be printed to the standard output. You can observe the generated compiler_input.json by setting the --debug
flag. It will generate a compiler_input.json.
You provide compiler input flags as key-value parameters. Use "\." to escape "." (dot). For instance the following key=value pair is used to define the source contract: sources.example/BeerBar\.sol.urls[0]='example/BeerBar.sol'
.
Which will be translated to:
{
"sources": {
"example/BeerBar.sol": {
"urls": ["example/BeerBar.sol"]
}
}
}
Follow this scheme to set any arbritrary parameter for the compiler input. Refer to the solidity documentation for further information about Input Description.
After you installed the library contracts for the example BeerBar.sol using npm i @openzeppelin/contracts
in the example folder, you can run qsolc.py from the "workdir/quick-solc" folder as follows:
.\qsolc
language='Solidity'
settings.metadata.useLiteralContent=true
settings.outputSelection.*.*[0]='evm.deployedBytecode.sourceMap'
settings.outputSelection.*.*[1]='evm.deployedBytecode.object'
settings.outputSelection.*.*[2]='evm.deployedBytecode.opcodes'
settings.outputSelection.*.*[3]='metadata'
settings.remappings[0]='./=example/'
settings.remappings[1]='@openzeppelin/=example/node_modules/@openzeppelin/'
sources.example/BeerBar\.sol.urls[0]='example/BeerBar.sol'
The command will run solc with the following compiler input.json:
{
"language": "Solidity",
"settings": {
"metadata": {
"useLiteralContent": true
},
"outputSelection": {
"*": {
"*": [
"evm.deployedBytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.opcodes",
"metadata"
]
}
},
"remappings": [
"./=example/",
"@openzeppelin/=example/node_modules/@openzeppelin/"
]
},
"sources": {
"example/BeerBar.sol": {
"urls": [
"example/BeerBar.sol"
]
}
}
}
Note: The name of the contract source will be changed from "Beerbar.sol" to "example/Beerbar.sol." If you don't want this, you have to move qsolc.py into the "example" folder and run it like this:
python .\qsolc.py
...
settings.remappings[0]='@openzeppelin/=node_modules/@openzeppelin/'
sources.BeerBar\.sol.urls[0]='BeerBar.sol'
Refer to the solidity documentation for further information about Base Path and Import Remapping.