Skip to content

labteral/easysolc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easysolc

Tested with solc 0.5.2+commit.1df8f40c

Easysolc is a simple wrapper for the Solidity compiler (solc). You can specify a custom solc binary or use the first available following the paths specified under the $PATH environment variable.

This library also faciliates the creation of web3 contract instances directly from the source code or from previously generated files containing the ABI and the bytecode.

All the solc parameters are supported and they can be set when invoking the compile method. However, you can also specify all the arguments directly with the args parameter.

Usage

Installation

pip install easysolc

Create an instance of the compiler

If a path is not indicated, the binary used will be the first accesible following the paths of the $PATH environment variable:

from easysolc import Solc
solc = Solc()

It is also possible to load the compiler from custom paths:

solc = Solc('/usr/local/bin/solc')
solc = Solc('/usr/local/bin')
solc = Solc('/usr/local/bin/')

Functionalities

Compile the source code using files as output in the current directory:

solc.compile('ballot.sol', output_dir='.')

Do the same but manually indicating the arguments:

solc.compile('ballot.sol', '--abi --bin -o .')
solc.compile(args='--overwrite --abi --bin -o . ballot.sol')
solc.compile(args=['--overwrite', '--abi', '--bin', '-o', '.', 'ballot.sol'])

Get a web3 contract instance given the source code:

contract = solc.get_contract_instance(source='ballot.sol',
                                      contract_name='Ballot')

Get a web3 contract instance given the files containing the ABI and bytecode:

contract = solc.get_contract_instance(abi_file='ballot.abi',
                                      bytecode_file='ballot.bin')

Get a web3 contract instance given the ABI file and the contract address:

from web3 import Web3
w3 = Web3(Web3.IPCProvider("~/Library/Ethereum/geth.ipc"))
contract = solc.get_contract_instance(w3=w3,
                                      abi_file='ballot.abi',
                                      address="0x0")

Note. If you are going to interact with the contract, instead of deploying it, fill the web3 parameter with your instance.

Get a dictionary with the ABI and bytecode given the source code:

contract_dict = solc.compile('ballot.sol')

Get a web3 contract instance given a dictionary with the ABI and bytecode of the contract:

contract = solc.get_contract_instance(contract_dict['Ballot'])

List of parameters and default values of the compile method

source='*.sol'
args=None
optimize=False
optimize_runs=200
pretty_json=False
libraries=None
output_dir=None
overwrite=True
combined_json=None
gas=False
standard_json=False
assemble=False
yul=False
strict_assembly=False
machine=None
link=False
metadata_literal=False
allow_paths=None
ignore_missing=False
ast=False
ast_json=False
ast_compact_json=False
asm=False
asm_json=False
opcodes=False
bin_=True
bin_runtime=False
abi=True
hashes=False
userdoc=False
devdoc=False
metadata=False