PyCardano will provide developers with APIs to write entire off-chain code for their dApps in Python. For Python developers, it means instead of spending weeks or even months in learning advanced Haskell, they can now build dApps in days (see more details and explanations in next section).
The library will have core functionalities that enable developers to:
-
compose datums and redeemers, which are used in transactions that interact with Plutus script
-
query and deserialize datums and redeemers to Python object
-
build transactions to interact with Plutus script
-
stake ADA locked in Plutus scripts to designated pools
-
test different use cases and scenarios on a local chain
-
deploy Plutus scripts to testnet and mainnet
Apart from core functionalities, we will also create two end-to-end educational dApps that can be directly deployed to testnet or mainnet. The dApps will be similar to the ones in Plutus pioneer program [1], but with all off-chain code written in Python. To get a sense of sample dApp, check out this example dApp built by the proposer: https://github.com/cffls/pycardano/tree/main/examples/full_stack. The linked dApp is built with PyCardano. Users can send ADA to multiple addresses with Nami wallet, which is impossible with Nami wallet alone.
[1] Plutus pioneer program: <https://testnets.cardano.org/en/plutus-pioneer-program/>
A complete Cardano dApp usually consist of two main components: 1) on-chain Plutus script(s), which usually defines the core business logic of the dApp, and 2) off-chain code through with users' wallets will interact with the Plutus script.
Plutus application backend (PAB) provides an all-in-one solution where developers can write Haskell code for both on-chain and off-chain code. However, off-chain code requires non-trivial understanding of Haskell, such as Monad [1] and type families [2], which means weeks, if not months, of learning for new Haskell developers to fully master. Additionally, off-chain code is usually more complex and longer than on-chain code, because it is responsible for handling all use cases and scenarios for users to interact with Plutus scripts. Hence, for developers without prior Haskell experience, it will take a significant amount of time to learn, write, and debug off-chain code. A supporting evidence is that Plutus pioneer program is a ten-week long program, and there is a week dedicated to Monad [3]. The steep learning curve of Haskell does not only affect development speed, but also discourages new developers who want to build on Cardano, and could potentially slow down developer adoption.
What if we provide developers with a library by which they can write all off-chain code in one of the most popular programming languages, Python? Instead of spending time on learning advanced Haskell, developers can write simple Python code, and building dApps suddenly becomes much easier! Thousands of Python developers will be able to quickly learn, understand, and build Cardano dApps, not in weeks or months, but in days.
Some people might ask if using Python will jeopardize the security of Cardano's smart contract in a certain degree. The short answer is no. As a reminder, on-chain code will still need to be written in Haskell/Plutus, and only the gigantic off-chain code will be written in Python. The main security of Plutus script is coming from its on-chain part, which basically determines Who, How, and When could the locked fund be spent. This part is intact and therefore secured. Only the off-chain part will be written in Python. A resulting benefit of such combination is that developers can enjoy the security brought by Plutus and the easiness and simplicity brought by Python.
[1] Monad: https://wiki.haskell.org/All_About_Monads
[2] Type families: https://wiki.haskell.org/GHC/Type_families
[3] Plutus-pioneer-program, Monad: <https://github.com/input-output-hk/plutus-pioneer-program#lecture-4>
Potential challenges:
- Changes in Cardano's ledger in future hard folks. We will address this by closely following the latest ledger changes and update the library accordingly.