<p>This does not answers your question directly, but might you give you an idea how to solve it in a different and potencialy better way.</p>
<p>In <a href="https://twitter.com/_KtorZ_/status/1598471760332087297" rel="nofollow noreferrer">this twitter thread KtorZ</a> explains the recent changes on how to handle collateral.</p>
<blockquote>
<p>In case you wondered, here are some quick clarifications about the infamous 'collaterals' in #Cardano.</p>
<p>There was an interesting conversation I was brought into and thought it could be interesting to turn it into a proper thread.</p>
<p>All you ever wanted to know about collaterals 
With the Alonzo era and the introduction of Plutus scripts was also added a new feature to transactions: collaterals.</p>
<p>In essence, a collateral is an input which is consumed when a script fails to execute in a transaction.</p>
<p>But, aren't scripts supposed to be deterministic?
Precisely.</p>
<p>So in principle, any user in their right mind would not submit a transaction with a failing script, because they would know the outcome in advance.</p>
<p>Yet, an attacker of the system might find that interesting...
In fact, a failed transaction consumes resources but does not reward block producers for it. No fees are collected. For basic transactions only involving public key signatures, that's okay since the resources involved are negligible.</p>
<p>Yet for Plutus scripts, that's another story.
Hence why a 'collateral' was introduced to transactions.</p>
<p>It is an input (or, UTxO) that is consumed when a well-formed transaction with a failing script is submitted through the system. It acts as a mechanism to prevent bad actors to waste resources of the network at no cost.
Any transaction that executes a script is required to have a collateral, but it's only consumed if the result of the script execution turns out wrong.</p>
<p>The amount of collateral depends on the cost of the script and some protocol parameters. Plus, some extra rules.
In particular, the collateral cannot itself be an input locked by a script.</p>
<p>Moreso, it must NOT contain any native asset, but be a pure Ada UTxO.</p>
<p>Of course, it must also be an existing input that can be rightfully spent by the transaction.
In practice, it means that wallets must manage this collateral. Wallets must make sure to keep a large enough Ada-only UTxO available for collateral.
This can be a little tricky, and also, a bit odd from a user perspective.
Most Ada holders that have interacted with DApps have probably went through the steps of 'setting a collateral' in their wallet prior to making any transaction to a smart-contract.</p>
<p>This is a, relatively transparent, way for wallet providers to inform users about collaterals.
Overall, this is an unsatisfactory user and developer experience, for both &gt; Ada holders and wallet providers alike.
While the management of collaterals doesn't require users to explicitly set one, it's cumbersome and confusing to manage over time behind the scene.
So, with the Babbage era, a new feature was introduced called the 'collateral return'.
This allows wallets to not only define a collateral input to consume on failure, but also an output to send some change to in case it happens.</p>
<p>And this makes everyone's life a lot easier.
Remember the constraints about the collateral? In particular, that it needs to be Ada-only?</p>
<p>Well now, what matters is that the remainder between the collateral input &gt; and return is an Ada value, of a minimum quantity depending on the script cost and protocol parameters.
Said differently, it makes management of collaterals easier for wallets that decide to make use of it. They no longer need to keep a particular Ada-only UTxO around but can simply use any sufficiently large input as collateral and dump whatever is left in a change output.
It's interesting to note that collaterals were never meant to be a user-facing feature in the first place.
This was supposed to happen behind the scene only, because in principle, users (or by extension wallets) do not normally submit failing transactions.
Yet, this somehow made its way through UIs in such a way that as Cardano users, we've grown accustomed to it.
Up to the point where, new wallets would even have to adopt the same strategy to not confuse people.</p>
<p>UX is a funny thing 
Moving forward, and with collateral return available in the protocol, we can hope that wallet providers will gradually update to adopt this new approach and, put collaterals back in the shadow and not bother us users about them anymore </p>
</blockquote>

CC BY-SA 4.0
2022-12-02T20:35:24.550Z
Thanks Marek, I posted a similar question on their Twitter thread before coming here :) I don't think the points answer the specific question, though, KtorZ recognizes that UX  "is a funny thing", and my question is to address the UX.
D S
CC BY-SA 4.0
2022-12-02T12:21:37.123Z
2022-12-02T12:21:37.123Z
Marek Mahut - StakeNuts
<p>Yes this is possible but requires <em>suitable</em> UTxO(s) being already present in wallet. Due to virtues of <a href="https://cips.cardano.org/cips/cip40/" rel="nofollow noreferrer">CIP-40</a> any UTxO can be taken as collateral because we can set for return output and only this balance between input collateral(s) and return collateral output is required to satisfy the earlier collateral needs (such as being percentage of transaction fee and ada-only<sup>†</sup>). Note that as of now, we can take up to three UTxO(s) as collateral inputs (this is a protocol parameter).
<a href="https://atlas-app.io/" rel="nofollow noreferrer">Atlas</a> by Genius Yield handles for collateral and the example project in their documentation utilises this approach where if wallet has already set collateral then that is used otherwise framework chooses suitable UTxO as collateral for building the transaction.</p>
<hr />
<p><sup>†</sup> Find more details in ledger specifications <a href="https://github.com/input-output-hk/cardano-ledger/releases/latest/download/babbage-ledger.pdf" rel="nofollow noreferrer">here</a>.</p>

CC BY-SA 4.0
2023-05-02T06:22:34.203Z
2023-05-02T06:22:34.203Z
Sourabh
<p>New users of Cardano sometime want to get started quickly and often face the daunting task of understanding what collateral is. Then faced with the fact that they need to send some collateral to their wallet ... the quickness aspect of it gets lost very quickly</p>
<p>This is particularly true for Mobile Apps running on Cardano. Where users download the mobile app and get a wallet generated for them in the background. The wallet cannot interact with smart contracts until some ada is sent to it from the outside. This is cumbersome and degrades the user experience.</p>
<p>Question: Is it possible for the Dapp provider to add collateral for the user from a centralized wallet?</p>
<p>Potential workflow:</p>
<ul>
<li>User builds a transaction using the cardano-serialization-lib</li>
<li>User sends the transaction to a back-end service of the Dapp provider</li>
<li>The backend service adds the collateral field, partially signs the transaction and sends back to the user</li>
<li>The user signs the full transaction and submits it through their wallet</li>
</ul>
<p>This would enhance the user experience in mobile apps and increase the adoption of Cardano by letting users download an app and strat using straight away</p>
<p>Is something like this currently possible, and what are the risks?</p>
<p>All the best,
DSIO</p>

<wallet><cardano-serialization-lib><development><integration>
Collateral for new Wallets
# Collateral for new Wallets

(Asked by: username_0 on 2022-12-02)

New users of Cardano sometime want to get started quickly and often face the daunting task of understanding what collateral is. Then faced with the fact that they need to send some collateral to their wallet ... the quickness aspect of it gets lost very quickly

This is particularly true for Mobile Apps running on Cardano. Where users download the mobile app and get a wallet generated for them in the background. The wallet cannot interact with smart contracts until some ada is sent to it from the outside. This is cumbersome and degrades the user experience.

Question: Is it possible for the Dapp provider to add collateral for the user from a centralized wallet?

Potential workflow:

* User builds a transaction using the cardano-serialization-lib
* User sends the transaction to a back-end service of the Dapp provider
* The backend service adds the collateral field, partially signs the transaction and sends back to the user
* The user signs the full transaction and submits it through their wallet

This would enhance the user experience in mobile apps and increase the adoption of Cardano by letting users download an app and strat using straight away

Is something like this currently possible, and what are the risks?

All the best,
DSIO

**Tags:** wallet, cardano-serialization-lib, development, integration

---

## 2 answers

### Answer by username_1 on 2022-12-02. Score: 1

This does not answers your question directly, but might you give you an idea how to solve it in a different and potencialy better way.

In [this twitter thread KtorZ](https://twitter.com/_KtorZ_/status/1598471760332087297) explains the recent changes on how to handle collateral.

> In case you wondered, here are some quick clarifications about the infamous 'collaterals' in #Cardano.
>
> There was an interesting conversation I was brought into and thought it could be interesting to turn it into a proper thread.
>
> All you ever wanted to know about collaterals
> With the Alonzo era and the introduction of Plutus scripts was also added a new feature to transactions: collaterals.
>
> In essence, a collateral is an input which is consumed when a script fails to execute in a transaction.
>
> But, aren't scripts supposed to be deterministic?
> Precisely.
>
> So in principle, any user in their right mind would not submit a transaction with a failing script, because they would know the outcome in advance.
>
> Yet, an attacker of the system might find that interesting...
> In fact, a failed transaction consumes resources but does not reward block producers for it. No fees are collected. For basic transactions only involving public key signatures, that's okay since the resources involved are negligible.
>
> Yet for Plutus scripts, that's another story.
> Hence why a 'collateral' was introduced to transactions.
>
> It is an input (or, UTxO) that is consumed when a well-formed transaction with a failing script is submitted through the system. It acts as a mechanism to prevent bad actors to waste resources of the network at no cost.
> Any transaction that executes a script is required to have a collateral, but it's only consumed if the result of the script execution turns out wrong.
>
> The amount of collateral depends on the cost of the script and some protocol parameters. Plus, some extra rules.
> In particular, the collateral cannot itself be an input locked by a script.
>
> Moreso, it must NOT contain any native asset, but be a pure Ada UTxO.
>
> Of course, it must also be an existing input that can be rightfully spent by the transaction.
> In practice, it means that wallets must manage this collateral. Wallets must make sure to keep a large enough Ada-only UTxO available for collateral.
> This can be a little tricky, and also, a bit odd from a user perspective.
> Most Ada holders that have interacted with DApps have probably went through the steps of 'setting a collateral' in their wallet prior to making any transaction to a smart-contract.
>
> This is a, relatively transparent, way for wallet providers to inform users about collaterals.
> Overall, this is an unsatisfactory user and developer experience, for both > Ada holders and wallet providers alike.
> While the management of collaterals doesn't require users to explicitly set one, it's cumbersome and confusing to manage over time behind the scene.
> So, with the Babbage era, a new feature was introduced called the 'collateral return'.
> This allows wallets to not only define a collateral input to consume on failure, but also an output to send some change to in case it happens.
>
> And this makes everyone's life a lot easier.
> Remember the constraints about the collateral? In particular, that it needs to be Ada-only?
>
> Well now, what matters is that the remainder between the collateral input > and return is an Ada value, of a minimum quantity depending on the script cost and protocol parameters.
> Said differently, it makes management of collaterals easier for wallets that decide to make use of it. They no longer need to keep a particular Ada-only UTxO around but can simply use any sufficiently large input as collateral and dump whatever is left in a change output.
> It's interesting to note that collaterals were never meant to be a user-facing feature in the first place.
> This was supposed to happen behind the scene only, because in principle, users (or by extension wallets) do not normally submit failing transactions.
> Yet, this somehow made its way through UIs in such a way that as Cardano users, we've grown accustomed to it.
> Up to the point where, new wallets would even have to adopt the same strategy to not confuse people.
>
> UX is a funny thing
> Moving forward, and with collateral return available in the protocol, we can hope that wallet providers will gradually update to adopt this new approach and, put collaterals back in the shadow and not bother us users about them anymore

> **Comments:**
> **username_0**: Thanks Marek, I posted a similar question on their Twitter thread before coming here :) I don't think the points answer the specific question, though, KtorZ recognizes that UX  "is a funny thing", and my question is to address the UX.  

---

### Answer by username_2 on 2023-05-02. Score: 0

Yes this is possible but requires *suitable* UTxO(s) being already present in wallet. Due to virtues of [CIP-40](https://cips.cardano.org/cips/cip40/) any UTxO can be taken as collateral because we can set for return output and only this balance between input collateral(s) and return collateral output is required to satisfy the earlier collateral needs (such as being percentage of transaction fee and ada-only†). Note that as of now, we can take up to three UTxO(s) as collateral inputs (this is a protocol parameter).
[Atlas](https://atlas-app.io/) by Genius Yield handles for collateral and the example project in their documentation utilises this approach where if wallet has already set collateral then that is used otherwise framework chooses suitable UTxO as collateral for building the transaction.

---

† Find more details in ledger specifications [here](https://github.com/input-output-hk/cardano-ledger/releases/latest/download/babbage-ledger.pdf).


---

