This repository implements many educational Cardano Smart Contracts in Python using opshin. It also comes with off-chain code using PyCardano and a host of test cases to ensure high quality of the resulting contracts. Most of the code is in a similar format to the plutus-pioneer-program. Join the opshin discord server for Q/A and interact with other opshin pioneers!
Install Python 3.9, 3.10 or 3.11 (if it not already installed on your operating system). Python3.11 Installer download.
Install python poetry. Follow the official documentation here.
Install a python virtual environment with poetry:
# clone the repository including the config submodule necessary for running the node
git clone --recurse-submodules -j8 https://github.com/OpShin/opshin-pioneer-program.git
cd opshin-pioneer-program
poetry env use
poetry install
poetry shell
poetry run
poetry run python
### Cardano Node and Ogmios
#### Quick setup
> TBD: If you would like to contribute a hosted Ogmios endpoint, please feel free to contribute!
#### Local setup
Minimum Specs for Preview Network:
- 2 Core CPU
- 4GB memory
- 16GB free storage
First install Docker.
Follow the official documentation [here](https://docs.docker.com/get-docker/).
To start a [Cardano Node](https://github.com/input-output-hk/cardano-node) and [Ogmios API](https://ogmios.dev/) use [docker-compose](https://docs.docker.com/get-started/08_using_compose/) in your terminal:
```bash
# make sure your node configurations are up to date
git submodule update --init
# starts a cardano node and ogmios api on the preview testnet
docker compose up
You can then access the cardano-cli
using the docker image:
docker run --rm -it \
--entrypoint cardano-cli \
-e CARDANO_NODE_SOCKET_PATH=/ipc/node.socket \
-v opshin-pioneer-program_node-db:/data \
-v opshin-pioneer-program_node-ipc:/ipc \
inputoutput/cardano-node
Kupo is a database that supports fast queries to the Cardano blockchain. Although not needed for simple use cases, it can offer more speed in exchange for more storage and memory usage. This adds ~2GB storage and ~2GB memory on the preview network.
# starts the cardano node and ogmios with kupo (disabled by default)
docker compose --profile kupo up
# set the environment variable to use the ogmios + kupo backend
export CHAIN_BACKEND=kupo
You can check kupo synchronization by checking comparing the last slot number in http://localhost:1442/checkpoints to ogmios at http://localhost:1337/
As mentioned before, this repository follows the official Plutus Pioneer Program. The lectures/videos are the same as in the Plutus Pioneer Program, but we have recorded custom versions for sessions that rely on writing code and provide a version that focuses on OpShin for them. All covered contracts are (to be) implemented in OpShin in this repository. The repository contains presented contracts and empty files for homework in the main branch and a correct solution for homework in the solution branch.
Here's a mapping of the lecture videos on each week and what parts of this repository you can work on for each week. Feel free to follow along in your own pace.
The entire playlist for the OpShin Pioneer Program can be found here.
Recommended Reading: A Python Language Tour focusing on OpShin
Complete the homework files in src/week02/homework/
.
You can test your solution with pytest src/week02/tests/test_homework.py
.
The solutions are available at on the solutions
branch.
Complete the homework files in src/week03/homework/
. Like before, you can run tests with pytest src/week03/tests
.
This week is about alternative offchain solutions. We use pycardano, but you can compare and contrast alternatives.
src/week04/homework
.solutions
branch!src/week05/lecture/free.py
python src\week05\scripts\mint.py --script=free WALLET_NAME TOKEN_NAME
src/week05/lecture/signed.py
python src\week05\scripts\mint.py --script=signed WALLET_NAME TOKEN_NAME
src/week05/lecture/nft.py
python src\week05\scripts\mint.py --script=nft WALLET_NAME TOKEN_NAME
src/week05/homework
.pytest src/week05/tests
MockChainContext
and MockUser
in src/utils/mock.py
.
These classes allow us to easily test and evaluate our opshin contracts without the Cardano Node!poetry install --sync --extras=pyaiken
src/week06/tests/test_mock.py
with simulated spending and multiple users.src/week06/tests/test_negative_r_timed.py
src/week06/tests/test_negative_r_timed.py
src/week06/homework/test_exploitable_swap.py
src/week06/homework/fixed_swap.py
This week introduces Marlowe. There won't be any relevant opshin code for this week.