Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/OpShin/opshin-pioneer-program
This repository hosts an opshin/python implementation of the lectures of the Plutus Pioneers Program, a training course for Cardano Smart Contract Engineers.
https://github.com/OpShin/opshin-pioneer-program
cardano cryptocurrency plutus plutus-pioneer-program python smart-contracts
Last synced: 4 months ago
JSON representation
This repository hosts an opshin/python implementation of the lectures of the Plutus Pioneers Program, a training course for Cardano Smart Contract Engineers.
- Host: GitHub
- URL: https://github.com/OpShin/opshin-pioneer-program
- Owner: OpShin
- License: mit
- Created: 2023-03-04T05:47:49.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T16:56:08.000Z (10 months ago)
- Last Synced: 2024-08-01T04:02:07.638Z (7 months ago)
- Topics: cardano, cryptocurrency, plutus, plutus-pioneer-program, python, smart-contracts
- Language: Python
- Homepage:
- Size: 2.9 MB
- Stars: 43
- Watchers: 5
- Forks: 11
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This repository implements many educational Cardano Smart Contracts in Python using [opshin](https://github.com/OpShin/opshin).
It also comes with off-chain code using [PyCardano](https://github.com/Python-Cardano/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](https://github.com/input-output-hk/plutus-pioneer-program).
Join the opshin [discord server](https://discord.com/invite/umR3A2g4uw) for Q/A and interact with other opshin pioneers!## How to Follow the Pioneer Lectures and Code
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](https://www.youtube.com/playlist?list=PLTh2dOp0i8OKn3H45KH7EqdI4wmkOjeCM).
### Week 1
- [Welcome and Introduction](https://youtu.be/vMTi1TS8jec)
- [Setting up Our Development Environment](https://youtu.be/gETaVhZz0Mw)
- [Kuber Marketplace Demo](https://youtu.be/ZaB-7ZYBi3g)
- [Hashing & Digital Signatures](https://youtu.be/f-WKPWbk9Jg)
- [The EUTxO-Model](https://youtu.be/ulYDNaEKf4g)
- [Homework](https://youtu.be/9XwBk6IsNuM)Recommended Reading: [A Python Language Tour focusing on OpShin](https://book.opshin.dev/language_tour/index.html)
### Week 2
- [Low-Level, Untyped Validation Scripts](https://youtu.be/8oBZeOcJUTk)
- [Using the PyCardano to Interact with Smart Contracts](https://youtu.be/TQ8VZvhivEs)
- [Using the Cardano CLI to Interact with Smart Contracts](https://youtu.be/2MbzKzoBiak)
- [High-Level, Typed Validation Scripts](https://youtu.be/7XVeDXAgRPg)
- [Summary](https://youtu.be/MLfbaBZ10qE)
- [Homework](https://youtu.be/KFJMhNcMAuU)Complete the homework files in [`src/week02/homework/`](src/week02/homework/).
You can test your solution with `pytest src/week02/tests/test_homework.py`.
The solutions are available at on the [`solutions`](https://github.com/OpShin/opshin-pioneer-program/tree/solutions) branch.### Week 3
- [Script Contexts](https://youtu.be/HJt_Oli7e10)
- [Handling Time](https://youtu.be/gObATD-dzrA)
- [A Vesting Example](https://youtu.be/L3NPepcqTWE)
- [Parameterized Contracts](https://youtu.be/1cBkQIufjTA)
- [Offchain Code with PyCardano](https://youtu.be/ILJ_mlOwuUQ)
- If you want to look at an example in Lucid, check out the original PPP video: [Offchain Code with Lucid](https://youtu.be/C8TuGSzhqXU)
- [Reference Scripts](https://youtu.be/b45MMtuby-U)
- [Homework](https://youtu.be/NQIqCozYkss)
- [Summary](https://youtu.be/g28zeIRExeg)Complete the homework files in [`src/week03/homework/`](src/week03/homework/). Like before, you can run tests with `pytest src/week03/tests`.
### Week 4
This week is about alternative offchain solutions.
We use pycardano, but you can compare and contrast alternatives.- [On-chain VS Off-chain](https://youtu.be/pTc_BJby5GU)
- [Off-chain Code with Cardano CLI and GUI](https://youtu.be/gsgQ-xmzbpA)
- [Off-chain Code with Kuber](https://youtu.be/fzib9ALlL2M)
- [Off-chain Code with Lucid](https://youtu.be/BXz5V2rjbiE)
- [Homework](https://youtu.be/2Qm2xgmtbk4)
- Implement the offchain code for the files in [`src/week04/homework`](src/week04/homework).
- Although the contracts are implemented in opshin, you can use offchain code other than pycardano to complete this.
- There is no correct solution for this week as solutions can very widely.
So make sure to test your code!
- Feel free to submit your solution by making a PR to the `solutions` branch!
- We will continue to implement off-chain code in pycardano for this repository.### Week 5
- [Introduction](https://youtu.be/HgXYsMFqnb4)
- [Values](https://youtu.be/ThYByMLC0EI)
- [A Simple Minting Policy](https://youtu.be/g_VoKPK-tk0)
- [`src/week05/lecture/free.py`](src/week05/lecture/free.py)
- Off-chain minting script: `python src\week05\scripts\mint.py --script=free WALLET_NAME TOKEN_NAME`
- [A More Realistic Minting Policy](https://youtu.be/Faru8_Br2Xg)
- [`src/week05/lecture/signed.py`](src/week05/lecture/signed.py)
- Off-chain minting script: `python src\week05\scripts\mint.py --script=signed WALLET_NAME TOKEN_NAME`
- [NFT's](https://youtu.be/9kW-z_RuwEY)
- [`src/week05/lecture/nft.py`](src/week05/lecture/nft.py)
- Off-chain minting script: `python src\week05\scripts\mint.py --script=nft WALLET_NAME TOKEN_NAME`
- [Homework](https://youtu.be/nQC_GNPIRT8)
- Complete the minting policies in [`src/week05/homework`](src/week05/homework).
- Test your solution with `pytest src/week05/tests`### Week 6
- [The State Monad in practice](https://www.youtube.com/watch?v=8tWzG0ML6Z4&list=PLNEK_Ejlx3x08fHgl_ZTlowVO8bjqITEh&index=1)
- You can skip this for opshin.
- [Introduction to the Plutus Simple Model library](https://youtu.be/Sft02LeXA_U)
- We implement `MockChainContext` and `MockUser` in [`src/utils/mock.py`](src/utils/mock.py).
These classes allow us to easily test and evaluate our opshin contracts without the Cardano Node!
- Make sure you have the latest dependencies installed and pyaiken which we use to evaluate transactions without the node.
- `poetry install --sync --extras=pyaiken`
- We implement a simple test in [`src/week06/tests/test_mock.py`](src/week06/tests/test_mock.py) with simulated spending and multiple users.
- [Unit Testing a Smart Contract](https://youtu.be/vB8hyVq3HVo)
- Unit tests located in [`src/week06/tests/test_negative_r_timed.py`](src/week06/tests/test_negative_r_timed.py)
- [Property Testing a Smart Contract](https://youtu.be/pF8HpKmaQi4)
- Property tests also located in [`src/week06/tests/test_negative_r_timed.py`](src/week06/tests/test_negative_r_timed.py)
- Read the documentation on [hypothesis](https://hypothesis.readthedocs.io/en/latest/)
to get familiar with property testing in Python.
- [Testing Smart Contracts with Lucid](https://youtu.be/aUrIuDQgg5c)
- N/A.
- [Double Spending and Homework](https://youtu.be/AZVpkwRhEaY)
- Complete the following test [`src/week06/homework/test_exploitable_swap.py`](src/week06/homework/test_exploitable_swap.py)
- Use your completed test to implement a fix to the swap script: [`src/week06/homework/fixed_swap.py`](src/week06/homework/fixed_swap.py)### Week 7
This week introduces Marlowe. There won't be any relevant opshin code for this week.- [Introduction](https://youtu.be/KCWuj2DXEY4)
- [Marlowe Playground Demo](https://youtu.be/fldaBHmYfqk)
- [Homework](https://youtu.be/C4WWnQZOAAM)
- [Marlowe Starter Kit: Docker](https://youtu.be/wgSvPlWUrf8)
- [Marlowe Starter Kit: Preliminaries](https://youtu.be/hGBmj9ZrYHs)
- [Marlowe Starter Kit: ZCB using the Marlowe Runtime command-line client](https://youtu.be/pjDtuD5rimI)
- [Marlowe Starter Kit: ZCB using the Marlowe Runtime REST API](https://youtu.be/wgJVdkM2pBY)
- [Marlowe Starter Kit: ZCB using the Marlowe Runtime CLI](https://youtu.be/ELc72BKf7ec)
- [Marlowe Starter Kit: Escrow using the Marlowe Runtime's REST API](https://youtu.be/E8m-PKbS9TI)
- [Marlowe Starter Kit: Swap contract using the Marlowe Runtime's REST API](https://youtu.be/sSrVCRNoytU)### Week 8
- [Introduction](https://youtu.be/07ATzubeHjo)
- [The Private Testnet](https://youtu.be/BBqOZAuMx1c)
- [Plutus & Staking](https://youtu.be/1Hs6bU9pXi4)
- [Trying it on the Testnet](https://youtu.be/fzYXwdrfu44)
- [Homework](https://youtu.be/rO3FVGsuzUg)### Week 9
- [Creating our own Stablecoin Dapp](https://youtu.be/KDzyMy0WN9M)
- [Using our Stablecoin UI](https://youtu.be/MVq51lZkutA)
- [Stablecoin's Oracle](https://youtu.be/XfbEsFPbzCI)
- [Deploying Stablecoin's Reference scripts](https://youtu.be/AokRj-upwlY)
- [Minting Stablecoins](https://youtu.be/mUa9sztfPKs)
- [Burning Stablecoins and Liquidating positions](https://youtu.be/u2cUeD72MrQ)
- [Testing our Stablecoin's scripts](https://youtu.be/-MBebK33FOU)
- [Homework](https://youtu.be/yfmLaLcDjtc)### Week 10
- [Introduction](https://www.youtube.com/watch?v=Vp4UGDUv8BM&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=2)
- [Developing a Dapp with MeshJS and PluTs (Typescript)](https://www.youtube.com/watch?v=tazyJWUL0nM&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=1)
- [Developing smart contracts with PluTs (Typescript)](https://www.youtube.com/watch?v=WN4yxa-ISyk&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=5)
- [Developing smart contracts with OpShin and PyCardano (Python)](https://www.youtube.com/watch?v=Ale01hnxZEg&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=3)
- [Developing smart contracts with Plutarch (Haskell)](https://www.youtube.com/watch?v=2PNTJLzcP2k&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=4)
- [Developing smart contracts with Aiken](https://www.youtube.com/watch?v=Y6x46s60bks&list=PLNEK_Ejlx3x0ivViR3g9lAkB4Qj3iejp1&index=5)## Installation
1. Install Python 3.9, 3.10 or 3.11 (if it not already installed on your operating system).
Python3.11 Installer [download](https://www.python.org/downloads/release/python-3112/).2. Install python poetry.
Follow the official documentation [here](https://python-poetry.org/docs/#installation).3. Install a python virtual environment with poetry:
```bash
# 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# Optional. Use a specific python version
# replace with 3.8, 3.9, 3.10, or 3.11
# for this to work, python must be accessible in your command line
# alternatively provide the path to your python executable
poetry env use# install python dependencies
poetry install# run a shell with the virtual environment activated
poetry shell# If you're not in a shell, you can run python scripts with `poetry run`
poetry run python
```### Cardano Node and Ogmios
Simply run the following to use some publicly available nodes hosted by [demeter.run](https://demeter.run).
These nodes are already fully synced and ready to use. Note that as public endpoints, these nodes may be slow to respond and occasionally fail.Note also that production environments should *always* host their own node in order to guard themselves from failures.
```bash
export OGMIOS_API_PROTOCOL=wss
export OGMIOS_API_HOST=ogmios-preview-api-public-e79b24.us1.demeter.run
export OGMIOS_API_PORT=443
export KUPO_API_PROTOCOL=https
export KUPO_API_HOST=kupo-preview-api-public-e79b24.us1.demeter.run
export KUPO_API_PORT=443
export CHAIN_BACKEND=kupo
```If you want to host the node on your local computer, follow the steps in [Local Setup](#Local-Setup)
### Additional Material
#### Local setup
Minimum Specs for Preview Network:
- 2 Core CPU
- 4GB memory
- 16GB free storageFirst 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:
```bash
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 (Optional)
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.```bash
# 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/