Installing

1) Install Ganache

Ganache is the Ethereum blockchain simulator that runs on your local system. It must be running whenever you use simpleth.

To install:

_images/section_separator.png

2) Install simpleth package

$ pip install simpleth

Note

attributedict and HexBytes will be installed as pre-reqs. web3.py uses these for the transaction receipt data structure.

_images/section_separator.png

3) Verify directories

Besides installing simpleth, ` pip` creates three directories for your use:

  1. artifacts - smart contract-related files that are needed when deploying or using the contracts.

  2. examples - Python programs used for the Hello Worlds and one program that you will see in the Using document.

  3. contracts - Solidity source code for Hello Worlds and Test contracts.

pip places these directories in your Python sys.prefix directory.

Let’s check for the presence of the directories. (Note, your path will be different than the one shown.)

Use Python interpreter to get sys.prefix
 $ python

 >>> import sys
 >>> sys.prefix
 'C:\\Users\\snewe\\OneDrive\\Desktop\\simpleth-test\\venv'
 >>> exit()
Use DOS Window to check for examples and artifacts
 $ cd C:\\Users\\snewe\\OneDrive\\Desktop\\simpleth-test\\venv

 $ C:\Users\snewe\OneDrive\Desktop\simpleth-test\venv>dir
 ... snip ...
 06/07/2022  05:26 PM    <DIR>          artifacts
 06/07/2022  05:26 PM    <DIR>          contracts
 06/07/2022  05:26 PM    <DIR>          examples
 ... snip ...
_images/section_separator.png

3) Set artifacts environment variable

The environment variable, SIMPLETH_ARTIFACTS_DIR, needs to have the path to your artifacts directory.

You can set it in a DOS window. This takes effect immediately but only work in that window and lasts for the life of that window.

Set artifacts variable in DOS window
 $ set SIMPLETH_ARTIFACTS_DIR=C:\Users\snewe\OneDrive\Desktop\simpleth-test\venv\artifacts

Or, you can make it a permanent setting by editing the User environment variables to add it and then start a new DOS window to pick up the change.

Adding artifacts to user environment variables

Screenshot of adding artifacts as a user environment variable

After either way of setting it you can confirm it works:

Confirm the environment variable value
 $ cd %SIMPLETH_ARTIFACTS_DIR%
 $ cd
 C:\Users\snewe\OneDrive\Desktop\simpleth-test\venv\artifacts
_images/section_separator.png

4) Download Solidity compiler

You can run the Hello World contracts and do all the examples in the Using document without installing the Solidity compiler. If that is the extent of your planned use of simpleth, you can skip this step.

Otherwise, you will need to have a copy of the Solidity compiler to compile your contracts before using simpleth to deploy and use them. Download solc-windows.exe from Github page for ethereum//solidity.

It is safest to use the version found in tested levels .

If you prefer to use a different version, download it and save it as solc.exe in the solc directory.

_images/section_separator.png

5) Confirm installation

Make sure Ganache is running and try these commands. If your install is complete, they should run as shown and without error messages.

Confirming simpleth installation
 $ cd %SIMPLETH_ARTIFACTS_DIR%
 $ dir
 ... Artifact files ...

 $ cd ..\contracts
 $ dir
 ... Solidity smart contract programs ...

 $ cd ..\examples
 $ dir
 ... Python example programs ...

 $ python
 >>> from simpleth import Blockchain
 >>> Blockchain().block_number
     ... see sequence number of block at end of chain ...
 >>> exit()

 $ solc --version
 ... see the compiler version number ...

Note

The Python example programs:

  • event_poll.py

  • hello_world1.py

  • hello_world2.py

  • hello_world3.py

  • hello_world4.py

The Solidity smart contract files:

  • HelloWorld1.sol

  • HelloWorld2.sol

  • HelloWorld3.sol

  • HelloWorld4.sol

  • Test.sol

There are two Artifact files for each smart contract:

  1. <contract>.abi

  2. <contract>.bin

Congratulations! simpleth is ready for use.