Skip to content

Commit

Permalink
Adjust required-redeemer.plutus to require an inline datum of 42
Browse files Browse the repository at this point in the history
Add documentation for inline datum usage
  • Loading branch information
Jimbo4350 committed Jun 7, 2022
1 parent 7608488 commit a2234f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@

A reference script is a script that exists at a particular transaction output. It can be used to witness, for example, a UTxO at the corresponding script address of said reference script. This is useful because the script does not have to be included in the transaction anymore, which significantly reduces the transaction size.

## What is an inline datum?

An inline datum, is a datum that exists at a transaction output. 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.

### An example of using a Plutus V2 reference script

Below is an example that shows how to use a Plutus spending script. Here we discuss a [shell script example of how to use a reference script to spend a tx input](scripts/plutus/example-reference-script-usage.sh). This is a step-by-step process involving:
Below is an example that shows how to use a Plutus spending script and an inline datum. Here we discuss a [shell script example of how to use a reference script to spend a tx input](scripts/plutus/example-babbage-script-usage.sh). This is a step-by-step process involving:

+ the creation of the `Required Redeemer` Plutus txin script
+ the creation of the `Required Redeemer` Plutus script at a transaction output (creation of the reference script)
+ sending ada and a datum to the Plutus script address
+ the creation of the inline datum at a transaction output
+ sending ada to the Plutus script address
+ spending ada at the Plutus script address using the Plutus reference script

In this example we will use the [Required Redeemer](scripts/plutus/scripts/v2/required-redeemer.plutus) Plutus spending script. In order to execute a reference Plutus spending script, we require the following:

- Collateral tx input(s) - these are provided and are forfeited in the event the Plutus script fails to execute.
- A Plutus tx output with accompanying datum hash. This is the tx output that sits at the Plutus script address. It must have a datum hash, otherwise, it is unspendable.
- A Plutus tx output. This is the tx output that sits at the Plutus script address. Note because we are using an inline datum, it is not mandatory that the utxo at the plutus script address has a datum hash.
- The reference transaction input containing the corresponding Plutus script. We must create the transaction output containing the reference Plutus script.
- An inline datum at a transaction output. The Plutus spending script requires a datum/datum hash.

#### Creating the `Required Redeemer` Plutus spending script

Expand Down Expand Up @@ -48,10 +54,10 @@ cabal install cardano-node
```

To start your babbage cluster, you need to run the `example/run/all.sh` shell script.
The remainder of this guide provides a brief walkthrough of the [shell script example](scripts/plutus/example-reference-script-usage.sh) that automatically creates a reference script and spends the utxo at
The remainder of this guide provides a brief walkthrough of the [shell script example](scripts/plutus/example-babbage-script-usage.sh) that automatically creates a reference script and spends the utxo at
the reference script's corresponding script address.

#### Creating a reference script at a transaction output and
#### Creating a reference script at a transaction output, inline datum and
#### sending ada to the script address (with a datum)

In order to use a reference script, we must first create this script at a particular transaction output.
Expand All @@ -65,36 +71,36 @@ cardano-cli transaction build \
--tx-in "$txin" \
--tx-out "$utxoaddr+$lovelace" \
--tx-out "$plutusscriptaddr+$lovelace" \
--tx-out-datum-hash "$scriptdatumhash" \
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
--tx-out-inline-datum-file "$datumfilepath" \
--tx-out-reference-script-file "$plutusscriptinuse" \
--protocol-params-file "$WORK/pparams.json" \
--out-file "$WORK/create-datum-output.body"
```

The following should be noted about this build command:

Firstly, we are sending ada to the plutus script address along with a datum hash. This is reflected in the following lines:
Firstly, we are sending ada to the plutus script address. Note again we do not need to include a datum hash because we will use an inline datum that sits at a different transaction output. This is reflected in the following lines:

```bash
...
--tx-out "$plutusscriptaddr+$lovelace" \
--tx-out-datum-hash "$scriptdatumhash" \
...
```

We have seen this before in the [plutus-spending-script-example.md](doc/reference/plutus/plutus-spending-script-example.md).

Secondly, we are creating a reference script at a tx output:
Secondly, we are creating a reference script and an inline datum at a tx output:

```bash
...
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
--tx-out-inline-datum-file "$datumfilepath" \
--tx-out-reference-script-file "$plutusscriptinuse" \
...
```

Specifying the `--reference-script-file` after the `--tx-out` option will construct a transaction that creates a reference script at that transaction output.
Specifying the `--reference-script-file` after the `--tx-out` option will construct a transaction that creates a reference script at that transaction output. Likewise when you specify `--tx-out-inline-datum-file` you will also create an inline datum at that transaction output.

We sign and then submit as usual:

Expand All @@ -113,7 +119,7 @@ Now that there is ada at our script address, we must construct the appropriate t
Because we are using the `build` command, we should only note the following:

`$plutusutxotxin` - This is the tx input that sits at the Plutus script address (NB: It has a datum hash).
`tx-in-reference` - This specifies the reference input you are using to witness a transaction input.
`tx-in-reference` - This specifies the reference input you are using to witness a transaction input. In this case the reference input contains both a reference script and an inline datum.
`plutus-script-v2`- This specifies the version of the reference script at the reference input.
`reference-tx-in-datum-file` - This is the datum to be used with the reference script.
`reference-tx-in-redeemer-file` - This is the redeemer to be used with the reference script.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $CARDANO_CLI transaction build \
--tx-out "$plutusscriptaddr+$lovelaceattxindiv3" \
--tx-out-datum-hash "$scriptdatumhash" \
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
--tx-out-inline-datum-file "$datumfilepath" \
--tx-out-reference-script-file "$plutusscriptinuse" \
--protocol-params-file "$WORK/pparams.json" \
--out-file "$WORK/create-datum-output.body"
Expand Down
2 changes: 1 addition & 1 deletion scripts/plutus/scripts/v2/required-redeemer.plutus
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "PlutusScriptV2",
"description": "",
"cborHex": "59077e59077b010000323322323232323232323232323232332232323232322223232533532325335333573466e3c00522010001c01b101b101c376600a6666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8c8c8c8c8c8c8c8c8c8c8cccd5cd19b8735573aa018900011999999999999111111111110919999999999980080680600580500480400380300280200180119a80a80b1aba1500c33501501635742a01666a02a02e6ae854028ccd54065d7280c1aba150093335501975ca0306ae854020cd4054080d5d0a803999aa80c810bad35742a00c6464646666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a815bad35742a00460586ae84d5d1280111931901719ab9c02f02e02c135573ca00226ea8004d5d0a8011919191999ab9a3370e6aae754009200023322123300100300233502b75a6ae854008c0b0d5d09aba2500223263202e33573805e05c05826aae7940044dd50009aba135744a004464c6405466ae700ac0a80a04d55cf280089baa00135742a00a66a02aeb8d5d0a802199aa80c80e90009aba150033335501975c40026ae854008c07cd5d09aba2500223263202633573804e04c04826ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aab9e5001137540026ae854008c03cd5d09aba2500223263201833573803203002c202e264c6402e66ae7124010350543500017135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080508c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8050cd5ce00a80a00909aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c8064cd5ce00d00c80b89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403666ae7007006c06406005c4d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201533573802c02a02626ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301213574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900819ab9c01101000e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200823333573466e1d40092000200823263200633573800e00c00800626aae74dd5000a4c240029210350543100122002122001112323001001223300330020020011"
"cborHex": "5908765908730100003232332232332232323232323232323232323232323232323232322223232533532323253350021001101d33355301e120013232123300122333500522002002001002350012200112330012253350021020100101d23253335002153335001101f2101f2101f2153335002101f21333573466ebc00800408408084080854ccd4008407c8408084cc07c008004c030cd540888004dd4240a866aa0426aa6034240024646a00244440046a00244002646a0024444444444440166a0044400464a66a6603600291100101c101d376600a6666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8c8c8c8c8c8c8c8c8c8c8cccd5cd19b8735573aa018900011999999999999111111111110919999999999980080680600580500480400380300280200180119a80a80b1aba1500c33501501635742a01666a02a02e6ae854028ccd54069d7280c9aba150093335501a75ca0326ae854020cd405407cd5d0a803999aa80d0103ad35742a00c6464646666ae68cdc39aab9d5002480008cc8848cc00400c008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a8153ad35742a00460566ae84d5d1280111931901699ab9c02e02d02b135573ca00226ea8004d5d0a8011919191999ab9a3370e6aae754009200023322123300100300233502a75a6ae854008c0acd5d09aba2500223263202d33573805c05a05626aae7940044dd50009aba135744a004464c6405266ae700a80a409c4d55cf280089baa00135742a00a66a02aeb8d5d0a802199aa80d00e10009aba150033335501a75c40026ae854008c078d5d09aba2500223263202533573804c04a04626ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aab9e5001137540026ae854008c038d5d09aba2500223263201733573803002e02a202c264c6402c66ae7124010350543500016135573ca00226ea800448c88c008dd6000990009aa80d911999aab9f0012501c233501b30043574200460066ae8800804c8c8c8cccd5cd19b8735573aa004900011991091980080180118059aba150023005357426ae8940088c98c804ccd5ce00a00980889aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a1aba1500233500e013357426ae8940088c98c8060cd5ce00c80c00b09aab9e5001137540026ae854010ccd54025d728041aba150033232323333573466e1d400520042300b357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403466ae7006c06806005c0584d55cea80089baa00135742a00466a014eb8d5d09aba2500223263201433573802a02802426ae8940044d5d1280089aab9e500113754002424446004008266aa002eb9d6889119118011bab00132001355017223233335573e0044a032466a03066442466002006004600c6aae754008c014d55cf280118021aba200301013574200224464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900819ab9c01101000e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200a23333573466e1d40092000200a23263200633573800e00c00800626aae74dd5000a4c24002920103505431003200135500822112253350011500a22133500b3004002335530061200100400122333573466e3c00800401000c488008488004c8004d5401088448894cd40044d400c88004884ccd401488008c010008ccd54c01c480040140100044488008488488cc00401000c4488c008004448c8c00400488cc00cc0080080041"
}

0 comments on commit a2234f9

Please sign in to comment.