This is a prototypical implementation of smart contracts for Cardano which are written in a subset of valid Python.
Important note This project is a PoC and not ready for use. For a project that is already workable, check out OpShin
The general philosphy of this project is to write a compiler that ensure the following:
If the program compiles then:
- it is a valid Python program
- the output running it with python is the same as running it on-chain.
This specificially means that not every valid python program is a valid smart contract.
Not all language features of python will or can be supported.
The reasons are mainly of practical nature (i.e. we can't infer types when functions like eval
are allowed).
For your program to be accepted, make sure to only make use of language constructs supported by the compiler. You will be notified of which constructs are not supported when trying to compile.
This program consists of a few independent components:
- An aggressive static type inferencer
- Rewriting tools to simplify complex python expressions
- A compiler from a subset of python into UPLC/pluto
- The UPLC/pluto toolchain in python
Write your program in python. You may start with the example.py
.
Then run
python3 -m uplc compile example.py
Note: this is the final desired state. I am currently too lazy to both with setting up the module so just put your code into the string at
test.py
and runpython3 test.py