Skip to content

Commit 1b3c2df

Browse files
update plutus guide with vasil
1 parent d4168ab commit 1b3c2df

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

docs/source/guides/plutus.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,71 @@ Taker/Unlocker provides collateral. Collateral has been introduced in Alonzo tra
161161

162162
The funds locked in script address is successfully retrieved to the taker address.
163163

164+
-------------
165+
Vasil Upgrade
166+
-------------
167+
As part of the Basho phase of Cardano roadmap, the Vasil upgrade brings new capabilities on Plutus, namely reference inputs, inline datums, reference scripts, collateral output and Plutus V2 primitives.
168+
169+
- **Reference inputs** (`CIP-31 <https://cips.cardano.org/cips/cip31/>`_): This upgrade enables data sharing on-chain. Previously, datums were carried in transaction outputs; they stored and provided access to information on the blockchain. However, to access information in this datum, one had to spend the output that the datum was attached to. This required the re-creation of a spent output. The addition of reference inputs now allows developers to look at the datum without extra steps. This facilitates access to information stored on the blockchain without the need for spending and re-creating UTXOs. This can be useful for oracles and other use cases where state need to be inspected.
170+
171+
- **Inline datums** (`CIP-32 <https://cips.cardano.org/cips/cip32/>`_): Transaction datums were previously attached to outputs as hashes. With the implementation of inline datums, developers can now create scripts and attach datums directly to outputs instead of using their hashes. This simplifies how datums are used – a user can see the actual datum rather than supply it to match the given hash.
172+
173+
- **Reference scripts** (`CIP-33 <https://cips.cardano.org/cips/cip33/>`_): In Alonzo, when spending an output locked within a Plutus script, one had to include the script in the spending transaction. This increased the size of the script and caused certain delays in its processing. The reference scripts upgrade allows developers to reference a script without including it in each transaction. This significantly reduces transaction size, improves throughput, and reduces script execution costs (since the script only needs to be paid for once).
174+
175+
- **Explicit collateral output** (`CIP-40 <https://cips.cardano.org/cips/cip40/>`_): Transactions that call Plutus smart contracts are required to put up collateral to cover the potential cost of smart contract execution failure. If contract execution fails during phase 2 validation, all the funds stored in the chose UTXO for the collateral will be lost. After Vasil, user can specify a change address for the script collateral. If the script fails phase-2 validation, only the collateral amount will be taken, and the remaining funds will be sent to the change address.
176+
177+
- **Plutus V2 scripts**: The Vasil upgrade includes a new cost model that's lower than before, and developers will be able to see redeemers for all inputs rather than just the one being passed to the currently executing script.
178+
179+
Using the same FortyTwo example, now in Vasil, we show how reference scripts can be used. Reference script exists at a particular transaction output, and it can be used to witness UTxO at the corresponding script address::
180+
181+
>>> builder = TransactionBuilder(context)
182+
>>> builder.add_input_address(giver_address)
183+
>>> datum = 42
184+
>>> # Include scripts in the script address
185+
>>> builder.add_output(
186+
>>> TransactionOutput(script_address, 50000000, script=forty_two_script)
187+
>>> )
188+
189+
With reference script, actual script doesn't need to be included in the transaction anymore in order to spend UTxO sitting at script address::
190+
191+
>>> utxo_to_spend = None
192+
>>> # Spend the utxo that has datum/datum hash but no script
193+
>>> for utxo in chain_context.utxos(str(script_address)):
194+
>>> if not utxo.output.script and (
195+
>>> utxo.output.datum_hash == datum_hash(datum)
196+
>>> or utxo.output.datum == datum
197+
>>> ):
198+
>>> utxo_to_spend = utxo
199+
>>> break
200+
201+
>>> builder = TransactionBuilder(context)
202+
>>> builder.add_script_input(utxo_to_spend, datum=datum, redeemer=redeemer)
203+
>>> take_output = TransactionOutput(taker_address, 25123456)
204+
>>> builder.add_output(take_output)
205+
>>> signed_tx = builder.build_and_sign([extended_payment_skey], taker_address)
206+
207+
Again, with the same example, we show that you can send funds to script address with inline datums directly::
208+
209+
>>> builder = TransactionBuilder(context)
210+
>>> builder.add_input_address(giver_address)
211+
>>> datum = 42
212+
>>> builder.add_output(
213+
>>> TransactionOutput(script_address, 50000000, datum=datum, script=forty_two_script)
214+
>>> )
215+
216+
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::
217+
218+
>>> utxo_to_spend = None
219+
>>> # Speed the utxo that has both inline script and inline datum
220+
>>> for utxo in chain_context.utxos(str(script_address)):
221+
>>> if utxo.output.datum and utxo.output.script:
222+
>>> utxo_to_spend = utxo
223+
>>> break
224+
225+
>>> builder = TransactionBuilder(context)
226+
>>> builder.add_script_input(utxo_to_spend, redeemer=redeemer)
227+
>>> take_output = TransactionOutput(taker_address, 25123456)
228+
>>> builder.add_output(take_output)
229+
>>> signed_tx = builder.build_and_sign([extended_payment_skey], taker_address)
230+
231+

0 commit comments

Comments
 (0)