 Welcome everybody. My name is Lars Brunius. I'm the director of education at IOHK. And in this video, I will demonstrate how you can use the Cardano CLI command line tool written in Rust to construct quite complicated transactions by hand. We will demonstrate this with the example of a transaction involving four different wallets and use two of those for inputs and the other two for outputs. If you want to find out more about the Cardano CLI tool, you should check out the home page on GitHub at input minus output minus HK slash Cardano minus CLI. And there you will, if you scroll down, find the link to the command line documentation where all the commands that we will be using in this video are explained in detail. First of all, let's find out what wallets we have available. So in Cardano CLI, I enter the command wallet with sub command list. And I see there are actually five wallets. The first one is my private wallet on the main net. So we obviously won't be using that, but the other four are on the staging net and are there for demonstration. So we can use those. So first let's see how many funds are in each of those. So I issue the command Cardano CLI wallet status and then the name of the wallet. So the first one has almost 3000 ADA in them. The second 1000, the third also 1000 and the fourth also 1000. So let's write this down and let's assume that staging and staging two want to pay 1000 ADA in total to staging three and staging four 500 ADA each and all of that in a single transaction. So let's write this down as well. So after subtracting 500 ADA from the first two wallets, they should be left with about 2500 and 500 ADA. And after adding 500 ADA to the wallets, staging three and staging four, they should both contain 1500 ADA. So to get started, we create a new empty transaction. So we issue the command transaction new and we have to give the name of the blockchain in this case, I want to use the staging blockchain. And we have created this transaction. And this is the internal transaction ID 6F1VWW and I can check the status of a transaction with the command transaction status. And then I have to supply this ID. So right now there's nothing, there are no inputs, no outputs, no fee. And we will add all the missing parts step by step. First of all, we need addresses for the money to go to. So staging three and staging four wallets have to create new addresses for that purpose. And this is done with the command cardano wallet address. Then the name of the wallet, let's start with staging three. And then two indices for account index and address index, we can use zero, zero. I have to provide the wallet password and I get my address. Let's do the same for staging four. I can password for that wallet and I have my second address. Now that I have these addresses, I can add one output to the transaction for each. This is done with the command cardano CLI transaction at minus output. And the first parameter is the transaction ID, which was this six F one VWW. Then the address, so let's just copy paste the first one we created and then the amount. We set a 500 ADA, but the amount must be specified in Loveless. So I have to add six zeros. Okay. And let's do the other address as well. So let me copy paste this. Now that we have added the desired outputs, let's care about the inputs. So we must find appropriate UTXOs for both of the input wallets, staging and staging two that we can use. In order to do that, we can issue the command cardano CLI wallet UTXOs and name of the wallet. Let's start with staging and let's do the same for staging two. Okay. Now in order to use UTXOs, we must add them as input to our transaction. So that's the command cardano CLI transaction at input. First parameter again is the transaction ID and then second and third specify the UTXO. So that's this transaction ID and the two here, the index. And we do the same for the second UTXO we want to use down here. So transaction ID and the index here is three. Now let's check the status of the transaction. And we see that indeed our two outputs over 500 are here and our two inputs are there as well, but we see that we are not done yet because remember in this UTXO based accounting, you always have to use up a complete UTXO and there was far too much money in those UTXOs. So right now the total input is almost 3000 ADA, but the total output is only 1000 ADA. So we must create change addresses for the rest of the funds to go to. We know how to create new addresses. So cardano CLI, wallet address, name of the wallet. So we need one change address for staging and one for staging two. And we can again use indices zero, zero must provide the password. Do the same for staging two, password. The UTXO we use from the staging wallet contained 1999.7 ADA. We only want to pay 500, so we should give the difference back to the change address, which would be 1499.70. However, there is also an actual fee to pay that is displayed in the status of the transaction, 0.17 ADA. So let's subtract that and only give 1499.58 ADA back. So let's do that 1499 and 500,000 loveless. Now for the second change, let's check the UTXO again. So command wallet UTXOs staging two. So we use the first one with this address. And so let's create an output for that. So cardano CLI transaction, add yet another output. Two, six, F, one, VWV, the change address we created before. And now how much do we have to pay back? So there were 999.8, we want to spend 500. So the difference is 499.8, so 499 ADA and 800,000. Loveless. Let's check again the status and this looks good. So now we have four outputs, two desired ones that transfer the money we actually want to transfer, then the two change outputs for the first wallet and for the second wallet. And we can also check here the total input and the total output are now almost the same. So the calculation seemed to be correct. And we pay an actual fee now of 0.2 ADA and the minimal fee we would have to pay was 0.18 ADA. So that looks okay. So everything is looking good. That means we can now finalize the transaction by issuing the finalize command, six, F, one, VWV, okay. And now we're almost done. Now we have to sign it. So we issue that transaction sign command and now we are prompted for one signature from the staging wallet which provided the first input. So I have to provide that wallet password. Now we are prompted for the signature from the second wallet, the staging two wallet for the other input. So now both signatures have been added. And now finally I can send the transaction with the command send. And as another argument, I have to provide the name of the blockchain I want to send it to. Okay. And it is sent. And now of course we want to check whether the transaction actually happened, but for that we have to wait approximately two minutes until the block has been created and broadcasted to the blockchain. So after waiting for two minutes, let's update the local blockchain. So we issue the command blockchain pull name of the blockchain staging in our case. And now we go online and pull the newest blocks. And if everything went well, then our transaction should have been processed by now. So first of all, we have to synchronize all the wallets. So do the command wallet sync name of the wallet. Let's provide the password. Okay, let's do it with the other three wallets as well, the fourth one. And now we can check the status of these wallets. So we end up with 2,499.5, 500.8, 1,500 and 1,500 ADA. And if we compare that with our prediction, we see that it's exactly right. So to summarize, we saw how to manually create a complicated transaction with several outputs, several inputs to how to do everything by hand, explicitly sign and then send this transaction.