How to use --change-address with multiple input wallets?

I’m using the following command to build a transaction to send all tokens/NFTs and ADA from multiple wallets to a single wallet and it works just fine. With the use of --change-address parameter the single receiver wallet gets all the ADA and tokens which basically empties all the multiple input wallets.

cardano-cli transaction build --mainnet --alonzo-era $TX_INS --tx-out "$TX_OUTS" --change-address $RECEIVER_ADDR --witness-override $N --out-file matx.raw

Now what i want to do is just to send the tokens/nft and each input wallets should get the ADA change. I’m not really sure if using multiple --change-address parameters work that way.

Will this command works with multiple --change-address parameters?

cardano-cli transaction build --mainnet --alonzo-era $TX_INS --tx-out "$TX_OUTS" --change-address $RECEIVER_ADDR1 --change-address $RECEIVER_ADDR2 --change-address $RECEIVER_ADDR3 --witness-override $N --out-file matx.raw

No, there is only one --change-address allowed in a transaction.

1 Like

It would have to know, which change address should get the change of which input(s) and from which to subtract which part of the fee (divided by change addresses or proportional to the input or proportional to the transferred tokens?) and which part of the minimum output that has to go with the tokens.

Even more complicated, since cardano-cli does not know about wallets, just input UTxOs and output addresses. If three inputs belong to the same wallet, we would probably want to send the change to the same address.

So, it’s all not implemented and not trivial to implement.

You can do these calculations yourself (with the added knowledge that you know, what belongs to which wallet, and how you want to distribute fees and the minimal output that goes with the tokens) and use the old build-raw way. But then you also have to calculate fees yourself.