diff --git a/docs/contracts.rst b/docs/contracts.rst index 25111b7301..ef0e235cd9 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -14,57 +14,57 @@ for a proper introduction. Contract Deployment Example --------------------------- -To run this example, you will need to install a few extra features: +To run this example, you will need to install ``py-solc-x``. This is the supported route to installing the solidity compiler ``solc``. -- The sandbox node provided by eth-tester. You can install it with ``pip install -U web3[tester]``. -- The ``solc`` solidity compiler. See `Installing the Solidity Compiler - `_ +.. code-block:: bash + + $ pip install py-solc-x + +After ``py-solc-x`` is installed, you will need to install a version of ``solc``. You can install the latest version via a new REPL with: .. code-block:: python - >>> import json + >>> from solcx import install_solc + >>> install_solc(version='latest') + +You should now be set up to run the contract deployment example below: + +.. code-block:: python >>> from web3 import Web3 - >>> from solc import compile_standard + >>> from solcx import compile_source # Solidity source code - >>> compiled_sol = compile_standard({ - ... "language": "Solidity", - ... "sources": { - ... "Greeter.sol": { - ... "content": ''' - ... pragma solidity ^0.5.0; - ... - ... contract Greeter { - ... string public greeting; + >>> compiled_sol = compile_source( + ... ''' + ... pragma solidity >0.5.0; ... - ... constructor() public { - ... greeting = 'Hello'; - ... } + ... contract Greeter { + ... string public greeting; ... - ... function setGreeting(string memory _greeting) public { - ... greeting = _greeting; - ... } + ... constructor() public { + ... greeting = 'Hello'; + ... } ... - ... function greet() view public returns (string memory) { - ... return greeting; - ... } - ... } - ... ''' + ... function setGreeting(string memory _greeting) public { + ... greeting = _greeting; ... } - ... }, - ... "settings": - ... { - ... "outputSelection": { - ... "*": { - ... "*": [ - ... "metadata", "evm.bytecode" - ... , "evm.bytecode.sourceMap" - ... ] - ... } - ... } + ... + .. . function greet() view public returns (string memory) { + ... return greeting; ... } - ... }) + ... } + ... ''' + ... ) + + # retrieve the contract interface + >>> contract_id, contract_interface = compiled_sol.popitem() + + # get bytecode / bin + >>> bytecode = contract_interface['bin'] + + # get abi + >>> abi = contract_interface['abi'] # web3.py instance >>> w3 = Web3(Web3.EthereumTesterProvider()) @@ -72,12 +72,6 @@ To run this example, you will need to install a few extra features: # set pre-funded account as sender >>> w3.eth.default_account = w3.eth.accounts[0] - # get bytecode - >>> bytecode = compiled_sol['contracts']['Greeter.sol']['Greeter']['evm']['bytecode']['object'] - - # get abi - >>> abi = json.loads(compiled_sol['contracts']['Greeter.sol']['Greeter']['metadata'])['output']['abi'] - >>> Greeter = w3.eth.contract(abi=abi, bytecode=bytecode) # Submit the transaction that deploys the contract diff --git a/newsfragments/2020.doc.rst b/newsfragments/2020.doc.rst new file mode 100644 index 0000000000..2e10847aa1 --- /dev/null +++ b/newsfragments/2020.doc.rst @@ -0,0 +1 @@ +Update "Contract Deployment Example" docs to use ``py-solc-x`` as ``solc`` is no longer maintained. \ No newline at end of file