Open ltfschoen opened 6 years ago
I tried changing to the following in https://github.com/ltfschoen/geth-node/blob/master/scripts/main.py and passed additional arguments defined in https://github.com/ethereum/py-solc/blob/master/solc/wrapper.py to the compile_files
function. I also modified https://github.com/ethereum/py-solc/blob/master/solc/wrapper.py, moving the conditional check for source_files
after the conditional check for abi
to try and get it to run
solc --output-dir ./ --allow-paths ./ --bin ./contracts/FixedSupplyToken.sol
Changes to https://github.com/ethereum/py-solc/blob/master/solc/wrapper.py
...
if abi:
command.append('--abi')
if source_files is not None:
# command.extend(source_files)
command.append(source_files['sources']['FixedSupplyToken.sol']['urls'][0])
...
Changes to https://github.com/ltfschoen/geth-node/blob/master/scripts/main.py
# Standard JSON Compilation - https://github.com/ethereum/py-solc#standard-json-compilation
compiled_sol = compile_files({
"language": "Solidity",
"sources": {
"FixedSupplyToken.sol": {
"urls": ["../contracts/FixedSupplyToken.sol"]
}
}
},
output_dir="./",
bin=True,
allow_paths="./")
But it just outputs binary files in the current directory instead of assigning to the variable
py-solc
Version: 2.1.0 (shown when runningpip list
)solc
Version: 0.4.18+commit.9cf6e910.Emscripten.clang (shown when runningsolc --version
)python --version
)What was wrong?
I used PyEnv to install and switch to the latest Python version 3.6.4rc1 https://github.com/pyenv/pyenv. I then installed the following Python packages:
I then created and executed a Python file i.e. main.py with
python main.py
: main.pyNote that the Solidity file I am using is in my repo here https://github.com/ltfschoen/geth-node/blob/master/contracts/FixedSupplyToken.sol, and it compiles successfully with solc v0.4.18, as I've done so in MIST and deployed it to a Private Network previously already.
I'm trying to replicate using Web3.py and py-solc the same functionality that worked when I used Web3.js and solc-js here: https://github.com/ltfschoen/geth-node/blob/master/scripts/main.js
In the file I use py-solc to compile Solidity source code from a file using the function
compile_files
, but I get a full output error in Bash terminal as follows:I then looked closer at the Py-Solc documentation here: https://github.com/ethereum/py-solc#standard-json-compilation, and changed my code to use the same syntax as the second example under the heading "Standard JSON Compilation": main.py
But when I run this it gives another error in the Bash terminal, which is because the example is missing a
{
just before'urls'
:So I added the missing
{
, and I used a JSON Validator to make sure the argument was valid json format:main.py
But then it gave me error:
So then I clicked the link that says "Solidity Documentation for Standard JSON input and ouptup format" (FYI, note the typo here in the word "output") http://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description, specifically the section http://solidity.readthedocs.io/en/develop/using-the-compiler.html#input-description.
It highlighted that that object we are passing to
compile_standard
is an Input JSON Description, which the compiler API expects to be in JSON format, and it outputs the compilation result in a JSON formatted output.When looked more closely at the error, which says
solc --allow-paths file:///Users/Ls/code/blockchain/geth-node/contracts/ --standard-json
, it's clearly missing a JSON file as an input argument at the end. Is this something that the compiler is supposed to automatically generate? A similar error was raised in the solc-js repo issues here https://github.com/ethereum/solc-js/issues/126I tried experimenting a bit more trying to find an alternative and found that I'm able to manually created ABI files in Bash terminal with the command:
solc --abi FixedSupplyToken.sol --output-dir ./build
, which generates the following in the ./build/ folder:But I don't know how to load these generated ABI files into the variable
contract_interface
in main.py. Currently my code iscontract_interface = compiled_sol['<stdin>:FixedSupplyToken']
,I then tried copying the JSON argument into a file called test.json. test.json
I then ran the following:
But it just returned the following;
So I don't even understand how to use the CLI. Any help greatly appreciated I've pushed my latest code here: https://github.com/ltfschoen/geth-node/blob/master/scripts/main.py
Cute Animal Picture