How many witnesses shall I add to tx if I have 2 txins from different addresses?

I am trying to understand the required number of witnesses in a transaction.
Case 1:
Two TxIns from the same address. Shall I add one witness signed by the private key of the address or two?

Case 2:
Two TxIns from different addresses. Shall I add two witnesses signed by two private keys?

I am sorry for the naive question but I could not find a clear explanation…

One witness per required signing key. If your Q is related to cardano-cli transaction build-raw, there is now also cardano-cli transaction build, which is much simpler to use and does not require you to calculate the fees upfront.

2 Likes

@tomdx , thank you for the prompt reply.
I am building a transaction in my code and using cardano-cli for testing:)
So just to confirm: when you say “One witness per required signing key” you mean that if I have two input transactions from the same address, I need only one witness (signing key associated with the address), if I have two inputs from two different addresses, I need two witnesses(signed by keys of each address), is it correct?

Yes, the scope of the signing key is actually the BIP44 account, which in case of Cardano is also the scope of the staking key i.e. each account has its own private key. Multiple distinct addresses may belong to the same account. If they do, you only need to witness once for those.

2 Likes

Alright @tomdx I appreciate this reference but I give up on figuring out how to use it and/or finding documentation on that CLI syntax. :crazy_face: I can see the acceptable options in the CLI itself but not which combination of them will produce a well-defined transaction.

Do you know of a reference that illustrates a transaction with cardano-cli transaction build as completely as in the legacy page here (Create a simple transaction) for build-raw? :pray:

Sure, what would you like to see? We have mint, burn, plutus or simple p2pkh like this …

[17-12-2021 14:53:50] INFO astor --pay2pkh --from Owner --to Shelley --value {2 Ada 2 Ada 10 Astor175 10 Astor175 10 Astor175 10 Astor175} ====================================================================
[17-12-2021 14:53:50] INFO Query UTxO for Owner
  15e169ab92398b693d9995c3cc593906dff933582a3b4e9adee223f8000e69d5#4 value {lovelace 1700000 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175 30} datum TxOutDatumNone
  848701d2a14fa0788de2403950153aa58de6ba50ccb5bfa23e5bdf0fcb6369f8#1 value {lovelace 1700000 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175 10} datum TxOutDatumNone
  dae253082c5a1d880d6cab04cf329497b7c5b680653676e6441c6748470a5cc2#4 value {lovelace 1700000 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175 30} datum TxOutDatumNone
  e5e50b9adf7f09f87c98ba6e8a9eeb2961fc97d9e956b8fd8cf15371f65b417c#1 value {lovelace 1700000 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175 10} datum TxOutDatumNone
  faeba45176bdafb08fef61299f0906942cd97249015a9db5fd484869ecc8e5bc#7 value {lovelace 1700000 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175 920} datum TxOutDatumNone
  848701d2a14fa0788de2403950153aa58de6ba50ccb5bfa23e5bdf0fcb6369f8#0 value {lovelace 103855030} datum TxOutDatumNone
  729761ffe32f6be972bda0e70438a8d1d51ee5df8e6304d97102065f4f9f7292#0 value {lovelace 908095217} datum TxOutDatumNone
  56e7a7d3dd2f41622cbb2552d6b69ac24316fd98234cb2070d5f8cd698658563#0 value {lovelace 1000000000} datum TxOutDatumNone
  78271f692bcb6c2c7657714dd72c12802fd23cad8be2611bb2a43ec11cb9acc5#0 value {lovelace 1000000000} datum TxOutDatumNone
  a02c2f2ba3b32ecd0a10df50c11b1b7c92220cbf1264eac4672340de2c285772#0 value {lovelace 1000000000} datum TxOutDatumNone
  d1cbf51be38167ff90d3f1e3ae4040a0cfa31408c957b94bef130558d033378e#1 value {lovelace 35000000000} datum TxOutDatumNone
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 2000000 lovelace
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 2000000 lovelace
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175
[17-12-2021 14:53:51] INFO Pay Owner => Shelley 10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175
[17-12-2021 14:53:51] INFO In total 4000000 lovelace
[17-12-2021 14:53:51] INFO In total 40 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.Astor175
[17-12-2021 14:53:51] INFO Lovelace: 107255030 - 4000000 => 103255030
[17-12-2021 14:53:51] INFO Build payment transaction
[17-12-2021 14:53:51] INFO cardano-cli transaction build
 --testnet-magic 1097911063
 --alonzo-era
 --tx-in 848701d2a14fa0788de2403950153aa58de6ba50ccb5bfa23e5bdf0fcb6369f8#0
 --tx-in 15e169ab92398b693d9995c3cc593906dff933582a3b4e9adee223f8000e69d5#4
 --tx-in 848701d2a14fa0788de2403950153aa58de6ba50ccb5bfa23e5bdf0fcb6369f8#1
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+2000000
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+2000000
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+1700000+10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.4173746f72313735
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+1700000+10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.4173746f72313735
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+1700000+10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.4173746f72313735
 --tx-out addr_test1vqz72ux5hmryxypv3kdus2qacxt5prf6ujj765w3dnz7zzsps3uac+1700000+10 891b79189cc2ad6175160655a0e6286036695af10d2511f77f966e5c.4173746f72313735
 --change-address addr_test1qzckvdxzgyz47j5vm90ql6grkq27a4jp6pvs4md00q8tdj2zfyms9sdxunjcwz9p8ltlqvdcy7469ut6u89xavfwqkqsy9nss6
 --out-file /var/cardano/local/scratch/tx.raw
[17-12-2021 14:53:52] INFO Sign transaction
[17-12-2021 14:53:53] INFO Submit transaction 
1 Like

thanks; that looks straightforward enough if the nonnegative balance simply goes into --change-address :sunglasses: