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
. - Install the
oasis-sapphire-py
client library and other dependencies from requirements.txtpip 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>
. Make sure you have enough funds to cover the gas fees.
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.
The ContractUtility
class is used to compile and deploy the contracts,
based on the network name (sapphire, sapphire-testnet, sapphire-localnet).
The private key used to deploy the contract is fetched from the PRIVATE_KEY
environment variable.
contract_utility = ContractUtility("sapphire-localnet")
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. Message is fetched using the EIP-712 signed queries which allows for
private data retrieval (msg.sender == author access control).
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
Some inital unit tests are located in ./tests folder.
Run pytest
in the terminal.
End-to-end tests are set to sapphire-localnet
,
check tests/test_ContractUtility.py
if you want to change the network.