2

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

2 Answers 2

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.

3
  • 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
    Dec 29, 2021 at 14:33
  • Just sending ADA to a smart contracts address will not execute the smart contract. Someone must execute the smart contract in a transaction. Dec 29, 2021 at 17:42
  • Ok I understand that. I'm looking for an actual haskell code example/tutorial to carry this all out.
    – Myles
    Dec 29, 2021 at 17:50
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 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.

1
  • 1
    thanks so much!! this really helps me get on the right path
    – Myles
    Dec 29, 2021 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.