w0800_fan_out fund asnap
20220821
Fund Fan out and in
This page describes using the asnap utility to generate cardano-cli/marlowe-cli scripts. More about asnap can be found on it’s gitlab repo: gitlab.com/wmoco/asnap
The scripts described here are the following:
- Fund fan out using cardano-cli
- Fund fan out using marlowe-cli
- Fund fan in using cardano-cli
Note: fan-out = from 1 to many, fan-in = from many to 1
1. Fund fan out using cardano-cli
Suppose you need to fund 5 address with 50 ADA each, all sent from one ‘fund’ address.
Execute
You’ve created the addresses, and put the following files together in a directory:
fund.address fund.seed fund.skey fund.vkey
x01.address x02.address x03.address x04.address x05.address
This is the balance at the start:
Run the fund-fan-out script:
After the script has been run the balance will be this:
That’s it.
Digging a bit deeper.
The core of the template actions are these two snippets:
Snippet #1 :
«range .Alias2AddressMap.fund.TxixList»«if .FlagGreatestPureAda» --tx-in-collateral «.Txix» \
--tx-in «.Txix» \
«end»«end»
Snippet #2:
--change-address «.Alias2AddressMap.fund.Address» \
When you run the first snippet like this:
$ echo "«range .Alias2AddressMap.fund.TxixList»«if .FlagGreatestPureAda» --tx-in-collateral «.Txix» \
--tx-in «.Txix» \
«end»«end»" | asnap - fund.address
You get this output:
--tx-in-collateral 31a8a0eb1885768364eff4dd580078219b7500e301ad04f98e3163cdd7275577#0
--tx-in 31a8a0eb1885768364eff4dd580078219b7500e301ad04f98e3163cdd7275577#0
And for the second one:
$ echo "--change-address «.Alias2AddressMap.fund.Address» " | asnap - fund
.. you get:
--change-address addr_test1vr0sqeu2knafkesjhvjmzvqwz07gwqsvtprxvt2s3as3kzgtdzsmj
And then put together and run with the rest of the script, the output will be :
cardano-cli transaction build --testnet-magic 1567
--tx-in-collateral f61f38bca59200aace1a20fd2447935a2906baafad470186e48e838c73926bfe#0
--tx-in f61f38bca59200aace1a20fd2447935a2906baafad470186e48e838c73926bfe#0
--tx-out "addr_test1vq6szstpj6fywjqgq66mqe405283ldyptdkxqqc2yg0t9dccq80ze + 50000000 lovelace"
--change-address addr_test1vr0sqeu2knafkesjhvjmzvqwz07gwqsvtprxvt2s3as3kzgtdzsmj
--protocol-params-file protocol-parameters.json
--out-file unsigned.json
cardano-cli transaction sign --testnet-magic 1567
--tx-body-file unsigned.json
--signing-key-file fund.skey
--out-file signed.json
cardano-cli transaction submit --testnet-magic 1567 --tx-file signed.json
(the above script has been redacted for legibility: line-breaks and spacing was added)
2. Fund fan out using marlowe-cli
The downside of the first method is that you have 3 separate transactions. It can also be done in one, when using marlowe-cli transaction simple .
Here’s the script (side-note: to easily differentiate theses tx’s we just transfer 49 ADA instead of 50)
The instantiated command looked like this:
Resulting in this output ..
TxId "a47c70ad38c2f9b58213a8f798ff11bfbac3c369d69391ad1b1dd4856cf219db"
.. and this balance:
3. Fund fan in using cardano-cli
What happened? I accidentally executed a fan-out twice, from fund to mediator, buyer, seller. And now I want to put half (ie. 100 ADA each) back into the fund.
Before situation
The script
After situation
|