Skip to content

Instantly share code, notes, and snippets.

@johnshearing
Last active August 5, 2022 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnshearing/bb820f32f148dc10ab64a18362bf6aa9 to your computer and use it in GitHub Desktop.
Save johnshearing/bb820f32f148dc10ab64a18362bf6aa9 to your computer and use it in GitHub Desktop.

Marlowe Pioneers:

Setting Up A Cardano Development Environment On a Windows 10 Computer

I made this tutorial so that I can remember how to set up my Cardano development environment if I ever have to do it again. Much thanks to all the community members that helped me through the process.
I hope others may find this useful.

Tutorial showing how to:

  • Setup a Linux environment on Windows 10 using Windows Subsystem for Linux (WSL)
  • Setup VS Code for use with WSL
  • Setup the Marlowe development environment
  • Setup Jupyter Notebooks for use with Marlowe Pioneer Lessons
  • Directs the user to Marlowe Pioneer Lessons
  • Directs the user to continue with @Marco M's tutorial

Basic Setup Starting With A Machine Running Windows 10.

If you have a Linux Ubuntu 20.04.4 or greater installed then skip ahead.

Install Windows Subsystem for Linux.
We are basically following the directions at the webpage linked below:
https://pureinfotech.com/install-windows-subsystem-linux-2-windows-10/

In the search field on your Windows Task Bar in the lower left of your computer screen, enter the following to open a new terminal window:
cmd
Then in the pop up menu, right click over the Command Prompt item and select Run as Administrator

Enter the following command into the terminal window to find the latest version of Ubuntu:
wsl --list --online

For me I see the following is the latest version of Ubuntu:
Ubuntu-20.04
You may see something different.

So enter the following to install the latest version:
Be sure to change the last bit to match the latest version you have for Ubuntu.
wsl --install --distribution Ubuntu-20.04

Wait for the install to complete.

Now restart your computer so that the changes you made can take effect.
When the computer starts again, an Ubuntu terminal window will open automatically without you doing anything.
Just wait until the Ubuntu terminal window opens.
You will see a message which says "Installing, this may take a few minutes"
Be patient, this will take some time for the software to install.

Finally, you will see a prompt in the terminal window asking for your UNIX user-name.
Enter something short like the initials of your name.
Use lower case letters. You will be glad you did.

Then you will be prompted for a password.
Make it a good one and be sure to write it down and keep it in a secure place.

You will be prompted to enter your password again.
Then you're in the Windows Subsystem for Linux.
You can start using Linux commands.

Enter the following commands to upgrade the list of Linux applications that are available from the Internet for install.
You will be prompted for the password you created when you installed WSL.
sudo apt update
sudo apt upgrade -y

For those like me that are not familiar with Linux commands, we have the following links.

When you have finished experimenting with Linux enter exit into the Ubuntu terminal window to end your session.

Now is a good time to install the VS Code development environment and code editor.
Go to the following webpage to download and install the VS Code development environment and text editor.
https://code.visualstudio.com/download
Now double click on the file you just downloaded and follow the prompts to install VS Code.

Next install the Remote Development Extension pack by going to the following website.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
Press the Install button seen at the website and follow the prompts.

Now in VS Code, click on the View menu and select the Command Pallet option.
Type the following into the Command Pallet:
Remote-WSL: New WSL Window using Distro...
Now select your default distribution from the menu and a new instance of VS Code will appear.
This new instance is connected to your Ubuntu Linux distribution that you just installed.
You can close the original instance of VS Code.

Let's use VS Code as a file manager.
Click on the Files icon in the upper left corner of VS Code.
Select the Open Folder button.
The Open Folder dialog window will open and your home folder will be shown by default.
Press the OK button.
Answer Yes, that you trust the security of the folder and then you will see that you have access to a nice GUI file manager.

Let's use VS Code's terminal window.
At the top menu click the Terminal option and then select New Terminal
Now we have a nice terminal window at the bottom, a code editor above that, and finally a file manager at the left side.
You can close VS Code for Now.

Let's continue setting up our computer.
In the search field on your Windows Task Bar in the lower left of your computer screen, enter the following to open a new Ubuntu terminal window:
ubuntu
Click on the Ubuntu menu item to start a new terminal window session.

In the alternative you can open the Command prompt by typing cmd into the search field on your Windows TaskBar and then type wsl into the terminal window in order to start your Ubuntu session.

Either way, when the command window opens enter the following command to change to your home directory.
cd ~

In the very upper left corner of the terminal window click the icon to open the context sensitive window.
Click on the Properties menu item.
Then click the checkbox marked Use Ctrl+Shift+C/V as Copy/Paste
If you don't do this then the you will not be able to use keyboard shortcuts for copy and paste.

Now it's time to install the NIX package manager.
Paste the following into the terminal window and press Enter to install the NIX Package Manager.
sh <(curl -L https://nixos.org/nix/install) --no-daemon

During the installation you will be prompted for your Linux password.
This is the password you just created when you setup Windows Subsystem for Linux.

Close the Ubuntu terminal window by entering the exit command or just close the terminal window using your mouse.
Now open a new Ubuntu terminal window.
The changes you made will now be effective.

Next we need to make the Nix.conf file.
Enter the following commands:
sudo mkdir /etc/nix - you will be prompted for your Linux password.
sudo nano /etc/nix/nix.conf

After supplying your password, the Nano word processor will open.
Paste the following text into the terminal window.

substituters        = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
experimental-features = nix-command flakes  
allow-import-from-derivation = true

Press Ctrl+X to start the save process.
Press y for Yes to save the modified buffer.
Press enter to accept the name nix.conf as the file name.

Download Marlowe Cardano

Now change back to your home directory with the following command:
cd ~

Install git with the following command:
sudo apt-get install git

Enter the following command into the Terminal Window to clone the Marlowe repository into the directory of your choice.
git clone https://github.com/input-output-hk/marlowe-cardano.git -b mpp-cli-lectures

Enter the following command into the Terminal Window to change to the directory you just cloned:
cd marlowe-cardano

Use the Nano text editor to edit one line in the marlowe-cardano\default.nix file.
Enter the following command into the terminal window to bring up the Nano text editor.
nano default.nix
Search for testnet-dev and change it to testnet-pioneers
Then press CTRL + X to initiate the close and save process.
Press y to accept the defaults and exit.

Enter the following command and wait a moment for the files to compile and for services to start.
nix-shell

Enter the following command into the terminal window and wait a couple of minutes for the node fully sync.
start-marlowe-run

You will see the node running in a TMUX session which allows you to manage several processes in a single terminal window.
Right clicking in any of the panes brings up a context sensitive menu.
These menus allow you to kill individual processes and do other things as well.
Right clicking over the number found in brackets in the green bar at the bottom of the screen all the way over to the very left brings up another context sensitive menu.
Finally, if you move your mouse over just a bit to the right of the number in brackets and right click again you will see a different context sensitive menu that allows you to kill all the processes at once. Use this menu to shut down the node when you are finished with it.
Check out this tutorial playlist to learn more about the TMUX environment.

From a NEW Ubuntu terminal window execute the following command:
cd ~/marlowe-cardano

Use the Nano text editor to edit one line in the ~/marlowe-cardano/marlow-cli/flake.nix file.
Enter the following command into the terminal window to bring up the Nano text editor.
nano ~/marlowe-cardano/marlowe-cli/flake.nix
Search for the word defaultApp and change it to apps.default
Now press CTRL + X to initiate the close and save process.
Press y to accept the defaults and exit.

You could have used VS Code to accomplish the same thing.

Start the nix shell with the following command:
nix-shell
Wait a moment for services to start and then enter the following command into the terminal window.
export CARDANO_NODE_SOCKET_PATH=/tmp/node.socket
export CARDANO_TESTNET_MAGIC=1567

Enter the following command into the terminal window to verify that you can connect to the Marlowe Pioneers node.
cardano-cli query tip --testnet-magic 1567

Note CARDANO_TESTNET_MAGIC=1097911063 for the public testnet. Replace --testnet-magic to --mainnet for the mainnet.

Enter the following commands one at a time to verify that you now have access to these CLIs from within the nix shell:
marlowe-cli --version
cardano-cli --version
cardano-wallet version

Enter the following command into the terminal window to change into the marlowe-cli directory.
cd marlowe-cli

Execute the command nix run from that folder in order to start JupyterLabs.

Ignore any error messages.

If everything went well you will see an offer to go to the following page.
Paste the following URL into your browser to view and interact with the rest of the official Marlowe Pioneer lessons.
http://localhost:8888/lab?token=99087d6fdd5df7c96dd0ffa3fda970bb4fd1a4f3a85e6686

If Jupyter Notebooks did not start don't worry. This feature is still being worked out and will be available soon.
The JupyterLabs notebooks are a convenient alternative to using the command line to complete the lessons.
They are just a convenience.
All commands can be directly entered into the terminal window while in the marlowe-cardano directory for the same results.

So go now to the following webpage (linked below) to continue with the Official Marlowe Lessons.
https://github.com/input-output-hk/marlowe-cardano/tree/main/marlowe-cli/lectures

When you are finished with the Official Marlowe Pioneers lessons then return here and check out the index of Cardano software and learning materials for Cardano developers which is linked below.
https://johnshearing.github.io/cardano_syllabus/

After having a look at the index linked above then continue on with the lesson below made by Marco M.

Marco M's Marlowe CLI Tutorial

The contract consists of two parties (Party1 and Party2) where each one deposit a specific amount of ADA and then the contract swaps the amounts.

Create wallets

The wallet1 will belong to the Party1 and the wallet2 will belong to the Party2. Generate the seed phrase mnemonic and convert it to an extended private key file wallet.prv, note that we are also saving the file wallet.seed.

mkdir -p wallets/wallet1
cd wallets/wallet1
# Generate the seed phrase and convert it into a root private key `wallet.prv`
cardano-wallet recovery-phrase generate --size 15 \
| tee wallet.seed \
| cardano-wallet key from-recovery-phrase Shelley \
| cardano-wallet key child 1852H/1815H/0H/0/0 > wallet.prv

# Generate the wallet files from the wallet.priv file previews generated
cardano-cli key convert-cardano-address-key --shelley-payment-key --signing-key-file wallet.prv --out-file payment.skey
cardano-cli key verification-key --signing-key-file payment.skey --verification-key-file payment.vkey
cardano-cli address build --testnet-magic 1567 --payment-verification-key-file payment.vkey > payment.addr

Note Repeat the previous steps to create the wallet2, the wallet folder should be named wallet2.

Funding the wallet
marlowe-cli util faucet \
--testnet-magic $CARDANO_TESTNET_MAGIC \
--lovelace 2000000000 \
--out-file /dev/null \
--submit 600 $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)

Note this only work for the testnet 1567 (Marlowe Pioneers)

Query the balance of an address
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

Smart Contract

Setup variables

MILLISECOND=1000
NOW=$(($(date -u +%s)*MILLISECOND))  # The current time in POSIX milliseconds.
HOUR=$((60*60*MILLISECOND))          # One hour, in POSIX milliseconds.
DEADLINE=$((NOW+10*HOUR))            # Timeout deadline, ten hours from now.
MINIMUM_ADA=2000000

PARTY_1=Party1
PARTY_2=Party2
PARTY_1_AMOUNT=100000000
PARTY_2_AMOUNT=200000000
Mint Role Tokens
cd ~/marlowe-cardano/
mkdir my-contract && cd my-contract

ROLES_CURRENCY=$(marlowe-cli util mint \
  --required-signer ~/marlowe-cardano/wallets/wallet1/payment.skey \
  --change-address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
  --out-file asset \
  --submit 600 \
  "$PARTY_1" "$PARTY_2" \
| sed -e 's/^PolicyID "\(.*\)"$/\1/')

echo "Roles currency $ROLES_CURRENCY"
echo "The hexadecimal representation of $PARTY_1 is $ROLES_CURRENCY.$(echo -n $PARTY_1 | basenc --base16)."
echo "The hexadecimal representation of $PARTY_2 is $ROLES_CURRENCY.$(echo -n $PARTY_2 | basenc --base16)."
Query the address to see that the tokens have been minted
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Output
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2     0        1979823763 lovelace + TxOutDatumNone
b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2     1        10000000 lovelace + 1 e6ab256a5a428c4427299149fa3ea6e055a966f7ddba7f8033841c3f.506172747931 + TxOutDatumNone
b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2     2        10000000 lovelace + 1 e6ab256a5a428c4427299149fa3ea6e055a966f7ddba7f8033841c3f.506172747932 + TxOutDatumNone

# The TxIx 0 is where we have our remaining ADA
# The TxIn 1 is where we have the Party1 role token
# The TxIn 2 is where we have the Party2 role token

Note To make the next transactions we need the make reference to this TxHash and TxIx.

Send funds to the second wallet

Let's send to the Party 2 the role token and also 1000 ADA wallet2.

# --tx-in TxHash#TxId

marlowe-cli transaction simple \
--required-signer ~/marlowe-cardano/wallets/wallet1/payment.skey \
--tx-in b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2#0 \
--tx-in b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2#1 \
--tx-in b437bd3fb73ffe4c87ec0ecdd73d5adb3fcbb8df6933d63d5a661e695436fed2#2 \
--change-address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_1" \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_2" \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)+1000000000" \
--out-file /dev/null \
--print-stats \
--submit 600
Construct the contract from a template
# Do not run
marlowe-cli template simple \
--minimum-ada "$MINIMUM_ADA" \
--bystander "Role=$PARTY_2" \
--party "Role=$PARTY_1" \
--deposit-lovelace "$PARTY_2_AMOUNT" \
--withdrawal-lovelace "$PARTY_2_AMOUNT" \
--timeout "$DEADLINE" \
--out-contract-file contract.json \
--out-state-file tx1.state

Note Not applicable here because we gonna test with our own contract (not from the templates). In case you use a contract from the templates, the command above automatically generates the contract.json and the tx1.state files for you.

Generate contract.json file

You can create your own contract using marlowe-playground, export it as JSON and then adjust the variables according.

cat > contract.json << EOI
{
  "when": [
    {
      "then": {
        "when": [
          {
            "then": {
              "token": {
                "token_name": "",
                "currency_symbol": ""
              },
              "to": {
                "party": {
                  "role_token": $PARTY_2
                }
              },
              "then": {
                "token": {
                  "token_name": "",
                  "currency_symbol": ""
                },
                "to": {
                  "party": {
                    "role_token": $PARTY_1
                  }
                },
                "then": "close",
                "pay": $PARTY_2_AMOUNT,
                "from_account": {
                  "role_token": $PARTY_2
                }
              },
              "pay": $PARTY_1_AMOUNT,
              "from_account": {
                "role_token": $PARTY_1
              }
            },
            "case": {
              "party": {
                "role_token": $PARTY_2
              },
              "of_token": {
                "token_name": "",
                "currency_symbol": ""
              },
              "into_account": {
                "role_token": $PARTY_2
              },
              "deposits": $PARTY_2_AMOUNT
            }
          }
        ],
        "timeout_continuation": "close",
        "timeout": $(( NOW + 12 * HOUR ))
      },
      "case": {
        "party": {
          "role_token": $PARTY_1
        },
        "of_token": {
          "token_name": "",
          "currency_symbol": ""
        },
        "into_account": {
          "role_token": $PARTY_1
        },
        "deposits": $PARTY_1_AMOUNT
      }
    }
  ],
  "timeout_continuation": "close",
  "timeout": $(( NOW + 10 * HOUR ))
}
EOI
Generate tx1.state (inicial state of contract)
cat > tx1.state << EOI
{
  "accounts": [
    [[{ "role_token": "$PARTY_1"}, { "currency_symbol": "", "token_name": "" }], $MINIMUM_ADA]
  ],
  "choices": [],
  "boundValues": [],
  "minTime": 1
}
EOI
Initialize the contract

If you wanna just test the contract, you can run only the simulationcommands. If you wanna run the contract on-chain you need to run the simulation and the execution commands.

marlowe-cli run initialize \
--roles-currency "$ROLES_CURRENCY" \
--contract-file contract.json \
--state-file tx1.state \
--out-file tx1.marlowe \
--print-stats
Execution of the inicial deposit
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC
# tx-in TX_PARTY_1_ADA

marlowe-cli run execute \
--testnet-magic $CARDANO_TESTNET_MAGIC \
--tx-in "cc4dd70bc593b3584fa2e60bcd5d5025d9d7888734568864822a6d918d39c513#0" \
--change-address "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)" \
--required-signer ~/marlowe-cardano/wallets/wallet1/payment.skey \
--marlowe-out-file tx1.marlowe \
--out-file /dev/null \
--print-stats \
--submit 600
jq '.contract' tx1.marlowe | yq -y
CONTRACT_ADDRESS=$(jq -r '.marloweValidator.address' tx1.marlowe)
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
Simulation transaction 1
marlowe-cli run prepare \
--marlowe-file tx1.marlowe \
--deposit-account "Role=$PARTY_1" \
--deposit-party "Role=$PARTY_1" \
--deposit-amount "$PARTY_1_AMOUNT" \
--invalid-before "$NOW" \
--invalid-hereafter "$((NOW+9*HOUR))" \
--out-file tx2.marlowe \
--print-stats

jq '.contract' tx2.marlowe | yq -y

Note the perpare command move your contract from one stage to another stage.

Execution transaction 1
# Party 1 address
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Contract adresss
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
# --tx-in-marlowe TX_CONTRACT
# --tx-in-collateral TX_PARTY_1_ADA
# --tx-in TX_PARTY_1_ADA
# --tx-in TX_PARTY_1_TOKEN

marlowe-cli run execute \
--marlowe-in-file tx1.marlowe \
--tx-in-marlowe 59fd8c323155f0e6c2c7a0b679722b659c1d0d493c1d590f09f03c3561443dcf#1 \
--tx-in-collateral 59fd8c323155f0e6c2c7a0b679722b659c1d0d493c1d590f09f03c3561443dcf#0 \
--tx-in 59fd8c323155f0e6c2c7a0b679722b659c1d0d493c1d590f09f03c3561443dcf#0 \
--tx-in cc4dd70bc593b3584fa2e60bcd5d5025d9d7888734568864822a6d918d39c513#1 \
--required-signer ~/marlowe-cardano/wallets/wallet1/payment.skey \
--marlowe-out-file tx2.marlowe \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_1" \
--change-address "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)" \
--out-file /dev/null \
--print-stats \
--submit 600
jq '.contract' tx2.marlowe | yq -y
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
Simulation transaction 2
marlowe-cli run prepare \
--marlowe-file tx2.marlowe \
--deposit-account "Role=$PARTY_2" \
--deposit-party "Role=$PARTY_2" \
--deposit-amount "$PARTY_2_AMOUNT" \
--invalid-before "$NOW" \
--invalid-hereafter "$((NOW+9*HOUR))" \
--out-file tx3.marlowe \
--print-stats

# Datum size: 23
# Payment 1
#   Acccount: "Party1"
#   Payee: Party "Party2"
#   Ada: 100.000000
# Payment 2
#   Acccount: "Party2"
#   Payee: Party "Party1"
#   Ada: 200.000000
# Payment 3
#   Acccount: "Party1"
#   Payee: Party "Party1"
#   Ada: 2.000000

jq '.contract' tx3.marlowe | yq -y
Execution transaction 2
# Party 1 address
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet2/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Contract address
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
# --tx-in-marlowe TX_CONTRACT
# --tx-in-collateral TX_PARTY_2_ADA
# --tx-in TX_PARTY_2_ADA
# --tx-in TX_PARTY_2_TOKEN

marlowe-cli run execute \
--marlowe-in-file tx2.marlowe \
--tx-in-marlowe bca133ed3e4e39601481cfafde4d46a499eb47010a3c07cff779e7365f297990#1 \
--tx-in-collateral cc4dd70bc593b3584fa2e60bcd5d5025d9d7888734568864822a6d918d39c513#3 \
--tx-in cc4dd70bc593b3584fa2e60bcd5d5025d9d7888734568864822a6d918d39c513#3 \
--tx-in cc4dd70bc593b3584fa2e60bcd5d5025d9d7888734568864822a6d918d39c513#2 \
--required-signer ~/marlowe-cardano/wallets/wallet2/payment.skey \
--marlowe-out-file tx3.marlowe \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_2" \
--change-address "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)" \
--out-file /dev/null \
--print-stats \
--submit 600
jq '.contract' tx2.marlowe | yq -y
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC

Note the contract ends, but the parties need to withdraw their funds.

Party 1 withdraw their funds from the payout script address
# Party 1 address
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Contract payout address
ROLE_ADDRESS=$(jq -r '.rolesValidator.address' tx1.marlowe)
echo $ROLE_ADDRESS
cardano-cli query utxo --address "$ROLE_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
# --tx-in TX_PARTY_1_ADA
# --tx-in-collateral TX_PARTY_1_ADA
# --tx-in TX_PARTY_1_TOKEN

marlowe-cli run withdraw \
--marlowe-file tx3.marlowe \
--role-name $PARTY_1 \
--tx-in bca133ed3e4e39601481cfafde4d46a499eb47010a3c07cff779e7365f297990#0 \
--tx-in-collateral bca133ed3e4e39601481cfafde4d46a499eb47010a3c07cff779e7365f297990#0 \
--tx-in bca133ed3e4e39601481cfafde4d46a499eb47010a3c07cff779e7365f297990#2 \
--required-signer ~/marlowe-cardano/wallets/wallet1/payment.skey \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_1" \
--change-address "$(cat ~/marlowe-cardano/wallets/wallet1/payment.addr)" \
--out-file /dev/null \
--print-stats \
--submit 600
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

Note the PARTY_1 also received 2 ADA, it's the value of the initial deposit to initialize the contract.

Party 2 withdraw their funds from the payout script address
# Party 2 address
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet2/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Contract payout address
cardano-cli query utxo --address "$ROLE_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
# --tx-in TX_PARTY_2_ADA
# --tx-in-collateral TX_PARTY_2_ADA
# --tx-in TX_PARTY_2_TOKEN

marlowe-cli run withdraw \
--marlowe-file tx3.marlowe \
--role-name $PARTY_2 \
--tx-in cfee29d8b65d6b3ef9b4f4495cdc68756d36606ca77c46afc6d6e295152a965b#0 \
--tx-in-collateral cfee29d8b65d6b3ef9b4f4495cdc68756d36606ca77c46afc6d6e295152a965b#0 \
--tx-in cfee29d8b65d6b3ef9b4f4495cdc68756d36606ca77c46afc6d6e295152a965b#3 \
--required-signer ~/marlowe-cardano/wallets/wallet2/payment.skey \
--tx-out "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)+$MINIMUM_ADA+1 $ROLES_CURRENCY.$PARTY_2" \
--change-address "$(cat ~/marlowe-cardano/wallets/wallet2/payment.addr)" \
--out-file /dev/null \
--print-stats \
--submit 600
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet2/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC
cardano-cli query utxo --address "$ROLE_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC
Final balances
# Contract address
cardano-cli query utxo --address "$CONTRACT_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC

# Contract payout address
cardano-cli query utxo --address "$ROLE_ADDRESS" --testnet-magic $CARDANO_TESTNET_MAGIC

# Wallet 1
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet1/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

# Wallet 2
cardano-cli query utxo \
--address $(cat ~/marlowe-cardano/wallets/wallet2/payment.addr) \
--testnet-magic $CARDANO_TESTNET_MAGIC

Note the contract payout address is now empty.


@ Marco Martins [HYPE] Staking pool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment