<p>Yes. Something like this is <em>relatively</em> trivial for a Plutus script (Essentially, locking funds and some data at an address is the <em>only</em> thing  scripts do).</p>
<p>Here is one approach you could take. There are many other ways you could do this, but this is fairly reusable construction:</p>
<p>Your datum type could have the fields:</p>
<ol>
<li>Target Amount</li>
<li>Deadline</li>
<li>Recipient &quot;Arbitrary&quot; Address (if you want it to go to a specific party)</li>
</ol>
<p>The script will ensure that the Datum UTxO can only be redeemed if:</p>
<ol>
<li>The OUTPUT of the spending Tx includes a UTxO paid to the Recipient of value &gt;= Target Amount &amp;&amp; the Tx was executed before the Deadline, <strong>OR</strong></li>
<li>The Datum is replaced with a new identical Datum and a UTxO of &gt;= the value on the previous Datum.</li>
</ol>
<p>You can see an example of scripts requiring the datum is replaced with a new one in the
PPP <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Core.hs#L110" rel="nofollow noreferrer">Oracle example</a> or the <a href="https://github.com/input-output-hk/plutus-apps/blob/a6868cde87600051a4cc808777d665d0b859853c/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L106" rel="nofollow noreferrer">Uniswap example</a>, with their
corresponding off-chain code <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Core.hs#L161" rel="nofollow noreferrer">here</a> and <a href="https://github.com/input-output-hk/plutus-apps/blob/a6868cde87600051a4cc808777d665d0b859853c/plutus-use-cases/src/Plutus/Contracts/Uniswap/OffChain.hs#L201" rel="nofollow noreferrer">here</a>.</p>
<p>The case where the deadline is passed and the ADA is burned is implicit in a Datum that can no longer be redeemed--if no-one can reach the funds, they are as good as burned (there is no actual way to burn ADA anyway).</p>
<p>To initialize the script, you will create the Datum with an attached 25 ADA. There would be nothing ensuring that the initial value is 25 ADA, but that doesn't seem like an issue. A script that makes that requirement would need to be more complex.</p>

CC BY-SA 4.0
2021-11-23T00:32:44.513Z
Thank you, Mitchell! Your level of detail is much appreciated. If we could get even deeper, I'm wondering about the 2nd option of redemption you mention. Do you have any references/examples for how to replace a Datum from within the smart contract? I'm assuming it's in Haskell, or could it be done another way?
Myles
CC BY-SA 4.0
2021-11-23T01:05:56.953Z
Added some examples to my answer. This will require you to write Plutus (on-chain script) and Haskell (off-chain code). If you aren't familiar with writing Plutus smart contracts, I'd highly encourage you to go through the Plutus Pioneer Program lectures. Unfortunately, Plutus is a young language and not trivially easy to pick up.
Mitchell Turner
CC BY-SA 4.0
2021-11-21T06:09:29.973Z
2021-11-23T01:03:38.770Z
2021-11-23T01:03:38.770Z
Mitchell Turner
<p><strong>What I want to do</strong>: Send 25 ADA and lock it all at the script address until 1 of the 2 scenarios happen:</p>
<ol>
<li>100 ADA is sent by Nov 25th (today is Nov 20th) and all ADA at the script address is sent out to some arbitrary address (total 125 ADA sent out)</li>
<li>It is Nov 25th and 100 ADA has not been sent and locked at the script address by now, so all ADA at the script address is burned (25 ADA and whatever else that was sent below 100 ADA is burned)</li>
</ol>
<p>Is this possible with Plutus smart contracts? Is there anyway at all a smart contract like this can be implemented on the Cardano blockchain?</p>

<plutus><cardano-cli><cardano-node><plutus-pioneer-program>
How to lock funds in a smart contract?
# How to lock funds in a smart contract?

(Asked by: username_0 on 2021-11-21)

**What I want to do**: Send 25 ADA and lock it all at the script address until 1 of the 2 scenarios happen:

1. 100 ADA is sent by Nov 25th (today is Nov 20th) and all ADA at the script address is sent out to some arbitrary address (total 125 ADA sent out)
2. It is Nov 25th and 100 ADA has not been sent and locked at the script address by now, so all ADA at the script address is burned (25 ADA and whatever else that was sent below 100 ADA is burned)

Is this possible with Plutus smart contracts? Is there anyway at all a smart contract like this can be implemented on the Cardano blockchain?

**Tags:** plutus, cardano-cli, cardano-node, plutus-pioneer-program

---

## 1 answers

### Answer by username_1 on 2021-11-21. Score: 3

Yes. Something like this is *relatively* trivial for a Plutus script (Essentially, locking funds and some data at an address is the *only* thing scripts do).

Here is one approach you could take. There are many other ways you could do this, but this is fairly reusable construction:

Your datum type could have the fields:

1. Target Amount
2. Deadline
3. Recipient "Arbitrary" Address (if you want it to go to a specific party)

The script will ensure that the Datum UTxO can only be redeemed if:

1. The OUTPUT of the spending Tx includes a UTxO paid to the Recipient of value >= Target Amount && the Tx was executed before the Deadline, **OR**
2. The Datum is replaced with a new identical Datum and a UTxO of >= the value on the previous Datum.

You can see an example of scripts requiring the datum is replaced with a new one in the
PPP [Oracle example](https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Core.hs#L110) or the [Uniswap example](https://github.com/input-output-hk/plutus-apps/blob/a6868cde87600051a4cc808777d665d0b859853c/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L106), with their
corresponding off-chain code [here](https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Core.hs#L161) and [here](https://github.com/input-output-hk/plutus-apps/blob/a6868cde87600051a4cc808777d665d0b859853c/plutus-use-cases/src/Plutus/Contracts/Uniswap/OffChain.hs#L201).

The case where the deadline is passed and the ADA is burned is implicit in a Datum that can no longer be redeemed--if no-one can reach the funds, they are as good as burned (there is no actual way to burn ADA anyway).

To initialize the script, you will create the Datum with an attached 25 ADA. There would be nothing ensuring that the initial value is 25 ADA, but that doesn't seem like an issue. A script that makes that requirement would need to be more complex.

> **Comments:**
> **username_0**: Thank you, Mitchell! Your level of detail is much appreciated. If we could get even deeper, I'm wondering about the 2nd option of redemption you mention. Do you have any references/examples for how to replace a Datum from within the smart contract? I'm assuming it's in Haskell, or could it be done another way?  
> **username_1**: Added some examples to my answer. This will require you to write Plutus (on-chain script) and Haskell (off-chain code). If you aren't familiar with writing Plutus smart contracts, I'd highly encourage you to go through the Plutus Pioneer Program lectures. Unfortunately, Plutus is a young language and not trivially easy to pick up.  

---

