Marlowe Pioneer
 
w0708c_notify
20220806

Running a simple Marlowe contract (without the backend)

This page describes the execution on marlowe testnet of the same contract as in Brian W Bush’s lecture 5 (see: github.com .. lectures/05-marlowe-cli-pab.ipynb) but then without using the backend, just using marlowe-cli and cardano-cli.

Cli commands used (in alphabetical order):

cardano-cli address build 
cardano-cli key convert-cardano-address-key 
cardano-cli key verification-key 
cardano-cli query utxo 

marlowe-cli run execute 
marlowe-cli run initialize 
marlowe-cli run prepare --deposit-..
marlowe-cli run prepare --notify 
marlowe-cli run withdraw 
marlowe-cli util mint 

Setting up the env

A cardano node needs to be running in the background: start-cardano-node in a nix shell, for detailed info see w0708a, with these environment variables:

export CARDANO_NODE_SOCKET_PATH=/tmp/node.socket
export CARDANO_TESTNET_MAGIC=1567

Overview

A summary of the steps taken:

  • prepare (create key, mint tokens, create contract)
  • tx: initialize the contract
  • tx: fund the contract
  • tx: notify
  • tx: withdraw

There is only one role, and that is the ‘actor’, with role AC (hex: 41 43).

Scripts

The scripts: scripts_708c.zip, my ref: daedtest:/u01/marlowe/20220802_redo_notify.

Filenames starting with an even number are the scripts, odd filenames are the inputs/outputs of the scripts.

00_setenv.sh

02_create_keys.sh
04_fund_actor.sh
06_mint_tokens.sh
        07_out.txt
08_create_contract.sh
        09_contract.json
        09_state.json
10_prepare_initialization.sh
        11_marlowe.json
12_execute_initialization.sh
        13_raw.json
14_prepare_fund.sh
        15_marlowe.json
16_execute_fund.sh
        17_raw.json
18_prepare_notify.sh
        19_marlowe.json
20_execute_notify.sh
        21_raw.json
22_withdraw.sh
        23_raw.json

Script 00_setenv.sh must be adapted by the executor along the way (eg enter POLICY_ID, CONTRACT_ADDRESS, PAYOUT_ADDRESS), and will be executed by every script (not shown in the text here).

00 Environment variables

Script: 00_setenv.sh

02 Create actor keys/address and fund it

Actor address (and keys) are created using script 02_create_keys.sh. Put some ADA (eg 100) into it.


    addr_test1vpe789twz302sgyat5jvmhgtxmtzj27ejdjpgtt6rkwz2usyyrwyc
    

    battle absorb easy cousin ability pave fence cousin orbit sense impact scale helmet .. rest omitted ..
    

    {
        "type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
        "description": "",
        "cborHex": "5880287226c6069313a3dab7d8983236⋯⋯₂₆₀⋯⋯2c86b4c665969213e5519072b1434dbb"
    }
        

    {
        "type": "PaymentExtendedVerificationKeyShelley_ed25519_bip32",
        "description": "",
        "cborHex": "58401e8fbc5c48e356152f6a42034495⋯⋯₁₃₂⋯⋯2c86b4c665969213e5519072b1434dbb"
    }
        

Balance:

Sat Aug  6 07:30:50 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                       
--------------------------------------------------------------------------------------
f261⋯d997  1     100.00 ADA + TxOutDatumNone  

:   LEGEND
:   f261⋯d997  → f2617fb1e0555ca5dc5905d18521fdd19ff3d3d52459a882408e1e970488d997

06 Mint the tokens

Script: 06_mint_tokens.sh

Output. Put this ID in 00_setenv.sh

PolicyID "82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88"

Out-file: 07_out.txt

Balance:

Sat Aug  6 07:35:36 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  0     89.83 ADA + TxOutDatumNone                     
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

08 Create the contract

Script: 08_create_contract.sh

Two files created:

  • 09_contract.json
  • 09_state.json

10 Prepare the initialization

Script 10_prepare_initialization.sh

marlowe-cli run initialize --roles-currency "$POLICY_ID"    \
                           --contract-file 09_contract.json \
                           --state-file    09_state.json    \
                           --out-file      11_marlowe.json  \
                           --print-stats

Output:

Validator size: 12415
Base-validator cost: ExBudget {exBudgetCPU = ExCPU 24652144, exBudgetMemory = ExMemory 82900}

This produces the contract in file 11_marlowe.json, from which we pick up the contract address (marloweValidator) and payout address (rolesValidator):

Edit the 00_setenv.sh script, and put the following values for variables CONTRACT_ADDRESS and PAYOUT_ADDRESS respectively:

jq -r '.marloweValidator.address' 11_marlowe.json
jq -r '.rolesValidator.address' 11_marlowe.json

12 Execute initialization

Balance:

Sat Aug  6 07:58:36 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  0     89.83 ADA + TxOutDatumNone                     
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  

:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

Script 12_execute_initialization.sh:

marlowe-cli run execute --tx-in "0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f#0" \
                        --change-address "$ACTOR_ADDRESS"                                            \
                        --required-signer actor.skey                                                 \
                        --marlowe-out-file 11_marlowe.json                                           \
                        --out-file 13_raw.json                                                       \
                        --print-stats                                                                \
                        --submit=600

Output:

Fee: Lovelace 181605
Size: 353 / 32768 = 1%
Execution units:
  Memory: 0 / 30000000 = 0%
  Steps: 0 / 10000000000 = 0%
TxId "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68"

Balance:

Sat Aug  6 07:59:45 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  
1ff7⋯bc68  0     87.65 ADA + TxOutDatumNone                     


--- CONTRACT ---
TxHash     TxIx  Amount                                                       
--------------------------------------------------------------------------------------
1ff7⋯bc68  1     2.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "b4d1⋯3458"  


--- PAYOUT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------



:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   1ff7⋯bc68  → 1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68
:   b4d1⋯3458  → b4d11d73a97a90b99c62dad772a1048dffb7fd9eacf67d10d5b10f6c530f3458

14 Prepare fund

Script 14_prepare_fund.sh

marlowe-cli run prepare --marlowe-file 11_marlowe.json \
                        --deposit-account "Role=AC" \
                        --deposit-party "Role=AC"    \
                        --deposit-amount "$AMT"             \
                        --invalid-before "$NOW"               \
                        --invalid-hereafter "$((NOW+2*HOUR))" \
                        --out-file 15_marlowe.json \
                        --print-stats

Output:

Datum size: 75

16 Execute fund

Balance before:

Sat Aug  6 08:16:30 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                         
--------------------------------------------------------------------------------------
0357⋯c48f  1     10.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  
1ff7⋯bc68  0     87.65 ADA + TxOutDatumNone                     


--- CONTRACT ---
TxHash     TxIx  Amount                                                       
--------------------------------------------------------------------------------------
1ff7⋯bc68  1     2.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "b4d1⋯3458"  


:   LEGEND
:   0357⋯c48f  → 0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   1ff7⋯bc68  → 1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68
:   b4d1⋯3458  → b4d11d73a97a90b99c62dad772a1048dffb7fd9eacf67d10d5b10f6c530f3458

Script 16_execute_fund.sh

marlowe-cli run execute --marlowe-in-file 11_marlowe.json                                                       \
                        --marlowe-out-file 15_marlowe.json                                                      \
                        --required-signer actor.skey                                                            \
                        --tx-in-marlowe "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#1"    \
                        --tx-in-collateral "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#0" \
                        --tx-in "1ff769543b58899fdf5aaa0896d7b3ce5e0b937a9b15ca634b1482cc307cbc68#0"            \
                        --tx-in "0357e269aafd87f4a002095a1a924b36428e391d7db8e974aebd8ed4e967c48f#1"            \
                        --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                        --change-address "$ACTOR_ADDRESS"                                                       \
                        --out-file 17_raw.json                                                                  \
                        --print-stats                                                                           \
                        --submit=600

Output:

Fee: Lovelace 1163485
Size: 13091 / 32768 = 39%
Execution units:
  Memory: 5025830 / 30000000 = 16%
  Steps: 1698217004 / 10000000000 = 16%
TxId "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417"

Balance after:

Sat Aug  6 08:33:15 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
b0d8⋯d417  0     79.48 ADA + TxOutDatumNone                    
b0d8⋯d417  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash     TxIx  Amount                                                        
--------------------------------------------------------------------------------------
b0d8⋯d417  1     17.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "8c41⋯ac92"  


:   LEGEND
:   b0d8⋯d417  → b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   8c41⋯ac92  → 8c41853425fc656af21606df26098e9439d6da12ed574773e2629313ac5cac92

18 Prepare notify

Script 18_prepare_notify.sh

marlowe-cli run prepare --marlowe-file 15_marlowe.json        \
                        --notify                              \
                        --invalid-before "$NOW"               \
                        --invalid-hereafter "$((NOW+3*HOUR))" \
                        --out-file 19_marlowe.json            \
                        --print-stats

Output:

Datum size: 23
Payment 1
  Acccount: "AC"
  Payee: Party "AC"
  Ada: 17.000000

20 Execute notify

bash 20_execute_notify.sh

marlowe-cli run execute --marlowe-in-file 15_marlowe.json                                                       \
                        --marlowe-out-file 19_marlowe.json                                                      \
                        --tx-in-marlowe "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#1"    \
                        --tx-in-collateral "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#0" \
                        --tx-in "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#0"            \
                        --tx-in "b0d8426083833ecbd30d086cf0fcbe463addb6074038c7ebc508cc8b7137d417#2"            \
                        --required-signer actor.skey                                                            \
                        --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                        --change-address "$ACTOR_ADDRESS"                                                       \
                        --out-file 21_raw.json                                                                  \
                        --print-stats                                                                           \
                        --submit=600

Output:

Fee: Lovelace 933056
Size: 12946 / 32768 = 39%
Execution units:
  Memory: 2242078 / 30000000 = 7%
  Steps: 818511856 / 10000000000 = 8%
TxId "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3"

Balance after execution:

Sat Aug  6 09:24:41 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
46ed⋯5bc3  0     78.55 ADA + TxOutDatumNone                    
46ed⋯5bc3  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------


--- PAYOUT ---
TxHash     TxIx  Amount                                                        
--------------------------------------------------------------------------------------
46ed⋯5bc3  1     17.00 ADA + TxOutDatumHash ScriptDataInAlonzoEra "8b60⋯68ee"  


:   LEGEND
:   46ed⋯5bc3  → 46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88
:   8b60⋯68ee  → 8b604460b567ff3433b5ad7c74cf317c7b6b4d1152f3c4b0f6a025b3f6d768ee

22 Withdraw

Script 22_withdraw.sh

marlowe-cli run withdraw --marlowe-file 19_marlowe.json                                                          \
                         --role-name "$ACTOR_ROLE"                                                               \
                         --tx-in-collateral "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#0" \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#2"            \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#1"            \
                         --tx-in "46edc06ada464aa9a9ec9cac8f09395009dd31f3bef80ebb3d8814a400795bc3#0"            \
                         --required-signer actor.skey                                                            \
                         --tx-out "$ACTOR_ADDRESS+$MINIMUM_ADA+1 $ACTOR_TOKEN"                                   \
                         --change-address "$ACTOR_ADDRESS"                                                       \
                         --out-file 23_raw.json                                                                  \
                         --print-stats                                                                           \
                         --submit=600

Output:

Fee: Lovelace 431007
Size: 2885 / 32768 = 8%
Execution units:
  Memory: 1461810 / 30000000 = 4%
  Steps: 557930172 / 10000000000 = 5%
TxId "8f87b5548db95a3ef3238199e20c5768d74b902645d8e242de7a839f33052a9c"

Balance:

Sat Aug  6 09:31:32 UTC 2022

--- ACTOR --- 
TxHash     TxIx  Amount                                        
--------------------------------------------------------------------------------------
8f87⋯2a9c  0     78.12 ADA + TxOutDatumNone                    
8f87⋯2a9c  1     17.00 ADA + TxOutDatumNone                    
8f87⋯2a9c  2     2.00 ADA + 1 82f3⋯df88.4143 + TxOutDatumNone  


--- CONTRACT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------


--- PAYOUT ---
TxHash  TxIx  Amount  
--------------------------------------------------------------------------------------

:   LEGEND
:   8f87⋯2a9c  → 8f87b5548db95a3ef3238199e20c5768d74b902645d8e242de7a839f33052a9c
:   82f3⋯df88  → 82f3e2b30f235528ea3c6a826bff2303154f591749170c9e9fb8df88

Bottom line

The contract and payout address are empty now, everything is back on the actor’s address.

Total money in the pocket = 78.12 + 17.00 + 2.0 = 97.12. Since we started out with 100 ADA, running this contract cost us 2.88 ADA.

Post scriptum

This is the way the contract looks in blockly:

.. and in marlowe:

 
Notes by wmoco. Generated on momo:/home/willem/sync/20220806_wmoco_pubcoms/20220806_marlowe_pioneer at 2023-06-14 18:32