Collateral question

I’m just looking for a bit of clarity on including collateral in a script tx. Is it best practice to create a UTxO within your wallet matching your collateral amount? In my scenario I have a python script wherein I set a collateral amount and then allow the script to run if there is a collateral utxo matching the amount, e.g. 5ada and looks for a utxo in the sending wallet matching 5 ada. Alternatively I could have the script check for >= 5 ada, but again, looking for best practice…if for some reason the tx failed would the collateral be consumed in full? So if I did >= 5 and the utxo the script chose had 50ada, would a tx failure (after sending was successful lets say) consume all 50?

The collateral UTxO is consumed in full. (Also note that it cannot contain native tokens.)

In principle, it should be nearly impossible for an honestly constructed transaction to fail the phase 2 validation and forfeit the collateral. A phase 1 failure (checking UTxOs, signatures, and simple scripts) does not result in loss of collateral. I believe that phase 2 failures would be rejected by cardano-cli transaction build or the local node before the transaction is sent to the memory pool. The only way that I’ve been able to get a script to consume collateral is to construct it with cardano-cli transaction build --script-invalid.

That said, I still create a dedicated UTxO with only 2 ADA to use as collateral because I don’t want to risk more, just in case my understanding in the paragraph above is incorrect.

P.S. The oracle that I’m running automatically creates a 2 ADA output for use as collateral the next time it runs. That ensures that appropriate collateral is always ready at hand.

Awesome, thank you for the clarification. And this is what I thought also esp from some testnet tests I’ve been doing.

Also splitting off collateral is something I’m looking at automating as well, after a check that a UTxO with collateral doesn’t already exist of course.

1 Like

The answers are no more true after the introduction of collateral return mechanism: https://cips.cardano.org/cips/cip40/