-
Notifications
You must be signed in to change notification settings - Fork 731
/
Copy pathsimple-minting-policy.sh
executable file
·108 lines (83 loc) · 3.6 KB
/
simple-minting-policy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -e
# Unofficial bash strict mode.
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -u
set -o pipefail
# This is an example plutus minting script derived from the validator in
# Cardano.CLI.Plutus.SimpleMintingScript. Essentially we demand that the
# script owner is allowed to mint "4D696C6C6172436F696E" and you can only mint
# a single "4D696C6C6172436F696E" per tx.
work=example/minting
mkdir -p $work
# Step 1 - Send ADA to token script owner
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/main.sock}"
export PV=v1 # Plutus Script Version
plutusscriptinuse="scripts/plutus/scripts/$PV/anyone-can-mint.plutus"
utxovkey=example/utxo-keys/utxo1.vkey
utxoskey=example/utxo-keys/utxo1.skey
utxoaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $utxovkey)
cardano-cli query utxo --address $utxoaddr --cardano-mode --testnet-magic 42 --out-file "$work/utxo.json"
txin=$(jq -r 'keys[]' "$work/utxo.json")
lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" "$work/utxo.json")
lovelaceattxindiv3=$(expr $lovelaceattxin / 3)
cardano-cli address key-gen \
--normal-key \
--verification-key-file "$work/minting.vkey" \
--signing-key-file "$work/minting.skey"
targetvkey="$work/minting.vkey"
targetskey="$work/minting.skey"
targetaddr=$(cardano-cli address build --testnet-magic 42 --payment-verification-key-file $targetvkey)
cardano-cli query protocol-parameters --testnet-magic 42 --out-file example/pparams.json
cardano-cli transaction build \
--alonzo-era \
--cardano-mode \
--testnet-magic 42 \
--change-address "$utxoaddr" \
--tx-in "$txin" \
--tx-out "$targetaddr+$lovelaceattxindiv3" \
--tx-out "$targetaddr+$lovelaceattxindiv3" \
--protocol-params-file example/pparams.json \
--out-file "$work/fund-script-owner.body"
cardano-cli transaction sign \
--tx-body-file "$work/fund-script-owner.body" \
--testnet-magic 42 \
--signing-key-file "$utxoskey" \
--out-file "$work/fund-script-owner.tx"
# SUBMIT
cardano-cli transaction submit --tx-file "$work/fund-script-owner.tx" --testnet-magic 42
echo "Pausing for 5 seconds..."
sleep 5
cardano-cli query utxo --address "$targetaddr" --testnet-magic 42 --out-file "$work/updatedutxo.json"
scriptownertxin=$(jq -r 'keys[0]' "$work/updatedutxo.json")
scriptownerCollateral=$(jq -r 'keys[1]' "$work/updatedutxo.json")
# Step 2: Mint a single 4D696C6C6172436F696E
# We need the script policy ID
policyid=$(cardano-cli transaction policyid --script-file $plutusscriptinuse)
redeemer=scripts/plutus/data/42.redeemer
lovelaceatplutusscriptaddr=$(jq -r ".[\"$scriptownertxin\"].value.lovelace" "$work/updatedutxo.json")
dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4
echo "Lovelace at address: $lovelaceatplutusscriptaddr"
cardano-cli transaction build \
--alonzo-era \
--cardano-mode \
--testnet-magic 42 \
--change-address "$utxoaddr" \
--tx-in "$scriptownertxin" \
--tx-in-collateral "$scriptownerCollateral" \
--mint-script-file "$plutusscriptinuse" \
--mint-redeemer-file "$redeemer" \
--tx-out "$dummyaddress+1379280 + 5 $policyid.4D696C6C6172436F696E" \
--mint "5 $policyid.4D696C6C6172436F696E" \
--protocol-params-file example/pparams.json \
--out-file "$work/plutusmint.body"
cardano-cli transaction sign \
--tx-body-file "$work/plutusmint.body" \
--testnet-magic 42 \
--signing-key-file "$targetskey" \
--out-file "$work/plutusmint.tx"
# SUBMIT
cardano-cli transaction submit --tx-file "$work/plutusmint.tx" --testnet-magic 42
echo "Pausing for 5 seconds..."
sleep 5
cardano-cli query utxo --whole-utxo --testnet-magic 42