Sample repository implemented in regards to the Cardano blockchain.
Copilot: Smart contracts are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code. They are stored on a blockchain network and automatically execute when certain conditions are met. Here are some examples of smart contract use cases:
- Finance: Smart contracts can be used for trading, investing, lending, and borrowing
- Healthcare: Smart contracts can be used to store and share medical records securely and efficiently
- Gaming: Smart contracts can be used to create decentralized gaming platforms that allow players to earn cryptocurrency rewards
- Real Estate: Smart contracts can be used to automate the process of buying and selling real estate, reducing the need for intermediaries
- Legal Industry: Smart contracts can be used to automate legal agreements, such as wills and trusts
- Python cardano-tools pip package
- Cardano Python Module quickstart
- cardano-wallet
- Getting started with Cardano testnets
- The official Cardano Environment configuration files
- Smart Contracts
- Plutus Pioneer Program - Part 2: How to “deploy” a Smart Contract in Cardano
- how to deploy smart contract on cardano
- Install the Docker Engine
- Install Python 3 from the official site or via package manager (apt, choco, brew)
Ramp up the docker-compose cluster containing the cardano-node container and cardano-wallet container
Refer to Quickstart
section here. Ramp up the docker-compose and select one of the Cardano Environment:
# On Unix systems or on Windows OS 10 with Git Bash or WSL
NETWORK=preview docker-compose up -d --build # Preview Testnet (preferred for development)
NETWORK=preprod docker-compose up -d --build # Pre-Production Testnet
NETWORK=mainnet docker-compose up -d --build # Production (Mainnet)
# This will start up the Cardano node and wallet applications and connect to the specified network (mainnet, preview, preprod)
docker exec -it <cardano-wallet or cardano-node container id> sh
# with curl
curl http://localhost:8090/v2/network/information
# with cli in cardano-wallet container
docker run --network host --rm cardanofoundation/cardano-wallet network information
# Wallet operations
docker run --network host --rm cardanofoundation/cardano-wallet wallet list
docker run --network host --rm cardanofoundation/cardano-wallet wallet delete <wallet id>
Execute sample app:
cd cardano-wallet-app
pip install -r requirements.txt
python main.py
Execute sample app in a docker container:
cd cardano-wallet-app
docker build -t python-cardano-sample-app:stable . # Build docker image
docker run --network host --rm python-cardano-sample-app:stable sh "python main.py" # Start a container
Compile contract:
cd cardano-smart-contract
pip install -r requirements.txt
opshin build simple-withdraw-contract.py # It checks the presence of a specific signature in the transaction to approve spending funds
opshin build simple-healthcare-contract.py # This smart contract defines a HealthDatum data class that inherits from PlutusData. The HealthDatum class has five attributes: patient_id, doctor_id, diagnosis, treatment, and cost. The validator function checks if the cost attribute of the datum object is greater than zero and if the length of the patient_id and doctor_id attributes is 32 bytes. If any of these conditions are not met, the function raises an AssertionError with an appropriate message.
Compile contract in a docker container:
cd cardano-smart-contract
docker build -t python-cardano-sample-smart-contract:stable . # Build docker image
docker run --rm -v $(pwd)/contract/:/app/build/simple-withdraw-contract/ python-cardano-sample-smart-contract:stable sh "opshin build simple-withdraw-contract.py" # Start a container, It checks the presence of a specific signature in the transaction to approve spending funds
docker run --rm -v $(pwd)/contract/:/app/build/simple-healthcare-contract/ python-cardano-sample-smart-contract:stable sh "opshin build simple-healthcare-contract.py" # Start a container, It checks the presence of a specific signature in the transaction to approve spending funds
Smart contracts need to be deployed to the Cardano blockchain. See Plutus Pioneer Program - Part 2: How to “deploy” a Smart Contract in Cardano.
docker rm -f $(docker ps -qa)
docker system prune --volumes --force