<p>I am not sure what you mean by automatically send funds out of smart contracts&quot;. If you mean without someone actually executing the contract in a transaction, this is not possible. Just people sending ADA to the smart contract address will not trigger the smart contract execution, someone has to do a transaction including the smart contract execution to do what you want.</p>

CC BY-SA 4.0
2021-12-29T14:33:10.373Z
Thanks for your reply, let me be more specific. I want a script which locks all ADA sent to it until a threshold is reached, like 1,000 ADA. Once the threshold is reached, there's a part of the script which sends out 1,000 ADA to a pre-defined address, and the cycle continues again until at least 1,000 ADA is locked in the contract again. It would be ideal for anyone to be able to send ADA to this script address. Also, what is the difference between triggering and not triggering a smart contract execution?
Myles
CC BY-SA 4.0
2021-12-29T17:42:32.910Z
Just sending ADA to a smart contracts address will not execute the smart contract. Someone must execute the smart contract in a transaction.
George - APEX Stake Pool
CC BY-SA 4.0
2021-12-29T17:50:43.763Z
Ok I understand that. I'm looking for an actual haskell code example/tutorial to carry this all out.
Myles
CC BY-SA 4.0
2021-12-29T07:19:26.120Z
2021-12-29T07:19:26.120Z
George - APEX Stake Pool
<p>As @George pointed out, there is no such thing as &quot;automatic&quot; for smart contracts. Everything must be triggered manually by an off-chain actor.</p>
<p>That being said, you could definitely create a script that holds funds in escrow until a threshold is reached, at which point those funds become distributable/claimable.</p>
<p>This is similar to how the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week01/src/Week01/EnglishAuction.hs#L103" rel="nofollow noreferrer">auction code</a> works:</p>
<p>Each time someone bids, the auction datum is updated. In the case of the auction, once a deadline has been past, the bids are collectable by the seller and the bidder can claim their winnings.</p>
<p>You could follow a similar pattern where a datum tracks the ADA locked at the script address, and the datum is replaced with an updated datum each time more ADA is locked. At the point the locked ADA passes 1000, the funds become claimable.</p>
<p>There are many ways you could organize the distributions, but the simplest/closest to automatic might be as follows: any transaction that pushes the total equal to or over 1000ADA must distribute to the designated recipients, and all excess tokens will be rolled over to a new datum. That makes the last contribution more expensive, so it might discourage contributions, so you could consider paying the distribution fees with the pot or something else.</p>

CC BY-SA 4.0
2021-12-29T20:35:08.063Z
thanks so much!! this really helps me get on the right path
Myles
CC BY-SA 4.0
2021-12-29T20:31:41.170Z
2021-12-29T20:31:41.170Z
Mitchell Turner
<p>I'm looking for an example or tutorial for how to write a smart contract which locks all ADA sent to it until a threshold of at least 1,000 ADA is reached. Once 1,000 ADA is reached, as much ADA as possible is sent to a pre-defined address and the counter resets. Is this possible with the current Plutus platform?</p>
<p>Thanks, Myles</p>

<plutus><smart-contract>
Automatically send funds out using a smart contract
# Automatically send funds out using a smart contract

(Asked by: username_0 on 2021-12-29)

I'm looking for an example or tutorial for how to write a smart contract which locks all ADA sent to it until a threshold of at least 1,000 ADA is reached. Once 1,000 ADA is reached, as much ADA as possible is sent to a pre-defined address and the counter resets. Is this possible with the current Plutus platform?

Thanks, Myles

**Tags:** plutus, smart-contract

---

## 2 answers

### Answer by username_1 on 2021-12-29. Score: 2

I am not sure what you mean by automatically send funds out of smart contracts". If you mean without someone actually executing the contract in a transaction, this is not possible. Just people sending ADA to the smart contract address will not trigger the smart contract execution, someone has to do a transaction including the smart contract execution to do what you want.

> **Comments:**
> **username_0**: Thanks for your reply, let me be more specific. I want a script which locks all ADA sent to it until a threshold is reached, like 1,000 ADA. Once the threshold is reached, there's a part of the script which sends out 1,000 ADA to a pre-defined address, and the cycle continues again until at least 1,000 ADA is locked in the contract again. It would be ideal for anyone to be able to send ADA to this script address. Also, what is the difference between triggering and not triggering a smart contract execution?  
> **username_1**: Just sending ADA to a smart contracts address will not execute the smart contract. Someone must execute the smart contract in a transaction.  
> **username_0**: Ok I understand that. I'm looking for an actual haskell code example/tutorial to carry this all out.  

---

### Answer by username_2 on 2021-12-29. Score: 1

As @George pointed out, there is no such thing as "automatic" for smart contracts. Everything must be triggered manually by an off-chain actor.

That being said, you could definitely create a script that holds funds in escrow until a threshold is reached, at which point those funds become distributable/claimable.

This is similar to how the [auction code](https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week01/src/Week01/EnglishAuction.hs#L103) works:

Each time someone bids, the auction datum is updated. In the case of the auction, once a deadline has been past, the bids are collectable by the seller and the bidder can claim their winnings.

You could follow a similar pattern where a datum tracks the ADA locked at the script address, and the datum is replaced with an updated datum each time more ADA is locked. At the point the locked ADA passes 1000, the funds become claimable.

There are many ways you could organize the distributions, but the simplest/closest to automatic might be as follows: any transaction that pushes the total equal to or over 1000ADA must distribute to the designated recipients, and all excess tokens will be rolled over to a new datum. That makes the last contribution more expensive, so it might discourage contributions, so you could consider paying the distribution fees with the pot or something else.

> **Comments:**
> **username_0**: thanks so much!! this really helps me get on the right path  

---

