|
| 1 | +# Plutus Minting Scripts |
| 2 | + |
| 3 | +## What is a Plutus minting script? |
| 4 | + |
| 5 | +A Plutus minting script is required to validate the minting of multi-asset tokens. Unlike Mary-era scripts, Plutus scripts support more logic beyond required signatures and timelocks. |
| 6 | + |
| 7 | +### An example of using a Plutus minting script |
| 8 | + |
| 9 | +Below is an example that shows how to use a Plutus minting script. This is a step-by-step |
| 10 | +process involving: |
| 11 | + |
| 12 | ++ the creation of the `AlwaysSucceeds` Plutus minting script (i.e. anybody can mint) |
| 13 | ++ the creation of a transaction that mints multi-assets using the `AlwaysSucceeds` Plutus minting script |
| 14 | + |
| 15 | +In this example we will use the [anyone can mint](../../../plutus-example/plutus-example/src/Cardano/PlutusExample/MintingScript.hs) Plutus minting script. To execute it, we require the following: |
| 16 | + |
| 17 | +- Collateral tx input(s) that are provided and forfeited if the Plutus script fails to execute. |
| 18 | +- Serialization of the Plutus script in the text envelope format (required for cardano-cli). |
| 19 | +- A redeemer. |
| 20 | + |
| 21 | +#### Creating the `AlwaysSucceeds` Plutus minting script |
| 22 | + |
| 23 | +The plutus-example executable will automagically generate several Plutus scripts in the CLI-compatible text envelope format. |
| 24 | + |
| 25 | +Run the following commands: |
| 26 | + |
| 27 | +```bash |
| 28 | +cd plutus-example |
| 29 | + |
| 30 | +cabal run exe:plutus-example |
| 31 | +``` |
| 32 | + |
| 33 | +This will output `anyone-can-mint.plutus` in the `generated-plutus-scripts` dir. |
| 34 | + |
| 35 | +#### Setting up a local Alonzo node cluster |
| 36 | + |
| 37 | +First follow the [install doc](../../../doc/getting-started/install.md) if you haven't. This convenient script will set up an Alonzo cluster immediately on your local machine: |
| 38 | + |
| 39 | +```bash |
| 40 | +./scripts/byron-to-alonzo/mkfiles.sh alonzo |
| 41 | +``` |
| 42 | + |
| 43 | +Follow the instructions displayed in the terminal to start your Alonzo cluster. |
| 44 | + |
| 45 | +#### Minting multi-assets using the Plutus minting script |
| 46 | + |
| 47 | +To mint a multi-asset, you need the Plutus script policy ID and a redeemer. Because this minting script always succeeds, you can use any redeemer: |
| 48 | + |
| 49 | +``` |
| 50 | +$ cardano-cli transaction policyid --script-file scripts/plutus/scripts/anyone-can-mint.plutus |
| 51 | +> $policyid |
| 52 | +``` |
| 53 | + |
| 54 | +You can find an example redeemer at: `scripts/plutus/data/42.redeemer` |
| 55 | + |
| 56 | +For more information regarding `tx-in-collateral` see [here](plutus-spending-script-example.md). |
| 57 | + |
| 58 | +```bash |
| 59 | +cardano-cli transaction build \ |
| 60 | + --babbage-era \ |
| 61 | + --cardano-mode \ |
| 62 | + --tx-in "$txin" \ |
| 63 | + --tx-in-collateral "$txinCollateral" \ |
| 64 | + --mint "5 $policyid.4D696C6C6172436F696E0A" \ |
| 65 | + --mint-script-file "scripts/plutus/scripts/anyone-can-mint.plutus" \ |
| 66 | + --mint-redeemer-file "scripts/plutus/data/42.redeemer" \ |
| 67 | + --tx-out "$dummyaddress+$spendable + 5 $policyid.4D696C6C6172436F696E0A" \ |
| 68 | + --protocol-params-file pparams.json \ |
| 69 | + --out-file "plutusmint.body" |
| 70 | + |
| 71 | +cardano-cli transaction sign \ |
| 72 | + --tx-body-file "plutusmint.body" \ |
| 73 | + --testnet-magic 42 \ |
| 74 | + --signing-key-file "$skey" \ |
| 75 | + --out-file "plutusmint.tx" |
| 76 | +``` |
| 77 | + |
| 78 | +You can use the [simple-minting-policy.sh](../../../scripts/plutus/simple-minting-policy.sh) in conjunction with the [mkfiles.sh alonzo](../../../scripts/byron-to-alonzo/mkfiles.sh) script to automagically run the `AlwaysSucceeds` minting script. |
| 79 | + |
| 80 | + |
0 commit comments