You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/guides/plutus.rst
+73-19
Original file line number
Diff line number
Diff line change
@@ -70,14 +70,51 @@ Similarly, redeemer can be serialized like following::
70
70
Example - FortyTwo
71
71
------------------
72
72
73
-
We demonstrate how these concepts come into play using a simple example from PPP - FortyTwo. The original script in haskell can be found here `here <https://github.com/input-output-hk/plutus-pioneer-program/blob/28559d379df8b66c06d8fbd1e2a43f6a8351382a/code/week02/src/Week02/Typed.hs>`_. Using PyCardano, we will show one can send and lock funds at a script address, and how someone else with the correct redeemer value can unlock and receive the funds.
73
+
We demonstrate how these concepts come into play using a simple example from `eopsin <https://github.com/ImperatorLang/eopsin>`_.
74
+
A user can lock funds together with a public key hash.
75
+
The contract will make sure that only the owner of the matching private key can redeem the gift.
76
+
77
+
We will first compile the contract locally. For this, you will need to have installed python3.8.
74
78
75
79
Step 1
76
80
81
+
Open a file called ``gift.py`` and fill it with the following code:::
Install the python packages ``eopsin-lang`` and ``pyaiken``. We can then build the contract.
101
+
102
+
.. code:: bash
103
+
104
+
$ python3.8 -m venv venv
105
+
$ source venv/bin/activate
106
+
$ pip install eopsin-lang
107
+
$ eopsin build gift.py
108
+
109
+
This is it! You will now find all relevant artifacts for proceeding in the folder ``gift/``.
110
+
111
+
Step 3
112
+
113
+
Back into the python console.
77
114
Similar to `Transaction guide <../guides/transaction.html>`_, we build a chain context using `BlockFrostChainContext <../api/pycardano.backend.base.html#pycardano.backend.blockfrost.BlockFrostChainContext>`_::
78
115
79
116
>>> from pycardano import BlockFrostChainContext, Network
Taker/Unlocker sends transaction to consume funds. Here we specify the redeemer tag as spend and pass in the redeemer value of 42. If the redeemer value is anything else, the validator will fail and funds won't be retrieved::
177
+
Taker/Unlocker sends transaction to consume funds. Here we specify the redeemer tag as spend and pass in no special redeemer, as it is being ignored by the contract.::
131
178
132
-
>>> redeemer = Redeemer(RedeemerTag.SPEND, 42)
179
+
>>> redeemer = Redeemer(RedeemerTag.SPEND, PlutusData()) # The plutus equivalent of None
With inline datum, we no longer have to include a datum within our transaction for our plutus spending scripts. Instead we can specify the transaction output where our datum exists to be used in conjunction with our Plutus spending script. This reduces the overall size of our transaction::
0 commit comments