This is a skeleton for confidential Oasis dApps in Python.
This project was tested on python 3.10, but should work with most python3 versions. Use pyenv to handle multiple python installations.
-
Initialize an environment using preferred environment manager (venv, pipx...)
python3 -m venv my_env
and install the python sapphire wrapper. The library is currently NOT included in the PyPI repository so make sure to only install the local .whl version. -
Make sure to follow the instructions and build the .whl file correctly. In the Py client wrapper dist/ folder, find the .whl file and install it by running
pip install <path_to_whl_file>
. -
Install the packages in requirements.txt
pip install -r requirements.txt
- If running sapphire-localnet make sure to launch the local node.
- Add your deployer private key to the environment variables
export PRIVATE_KEY=<my_private_key>
.
Some inital unit tests are located in ./test folder. Run pytest
in the terminal.
The ./src folder contains the .py files which are used to compile, deploy and interact with the contracts inside
./contracts folder. It also contains the main.py
for command line development.
Again make sure to follow the setup instructions before running scripts.
Open main.py which contains a simple starter example.
After saving the .sol contract in ./contracts folder, we can continue with compilation step.
To compile use class method setup_and_compile_contract()
from ContractUtility.py.
from src.ContractUtility import ContractUtility
ContractUtility.setup_and_compile_contract("MessageBox")
contract_utility.deploy_contract("MessageBox")
Provide the contract name, in the starter example case we use the provided MessageBox without the .sol extension.
To help you get started with development, main.py
contains some functionality that showcases web3.py contract abstraction interaction.
It contains set_message()
and get_message()
functions that set message and query the contract view function message()
respectively.
To run: python3 main.py
To compile, deploy and call the interact_with_contract() function from the terminal:
python3 main.py compile
python3 main.py deploy --network sapphire-localnet
python3 main.py setMessage --address <contract_address> --message "Hello world" --network sapphire-localnet
python3 main.py message --address <contract_address> --network sapphire-localnet