Kickstarter-like smart contract

I was interesting in finding out what I could accomplish with Move so I set myself the task of implementing a kickstarter-like smart contract. The idea is simple:

  • Create a campaign to raise a certain amount of money with a deadline (e.g. 1000 libra over 10 days)
  • While the campaign is active (i.e. before the 10 days are up) other people can pledge money to the campaign
  • At the end of the 10 days, one of two things will happen:
    • If the total money pledged is equal to or exceeds the target then the campaign is successful and the creator gets all the money
    • Otherwise all the money is returned to those who initially pledged it.

This is somewhat similar to the EarmarkedLibraCoin example in the documentation.

So I figured I need to do the following:

  • Create a module call it Kickstarter
  • Define two resources
    • Pledge which contains a LibraCoin.T and a recipient address
    • Campaign which contains a target value (e.g. 1000 libra), expiry date (e.g. 10th July 2019), current value raised

Let’s suppose Alice wants to start a campaign and Bob and Charlie are going to pledge.

Alice will call a procedure defined in the Kickstarter module to create a campaign which will assign a Campaign resource to her account with a starting value raised of 0, target 1000 and expiry 10th July 2019.

Bob will call a procedure also defined in the Kickstarter module to pledge say 100 libra to Alice’s campaign which will assign a Pledge resource to his account with Alice’s account as the recipient address and 100 Libra coin. The procedure will also mutate the campaign’s current value raised, incrementing it by the amount pledged (100).

Charlie will do the same, raising the current campaign pledge amount to 200.

Now here comes the tricky part which I’m not sure how can be done with Move. I figured I need to implement a procedure which Alice can call to end the campaign and it would do something like this:

assert(now >= campaign.expiry_date);
if (campaign.current_value >= {
  // Assign all coins to Alice and burn the Pledges
} else {
  // Return all coins to senders and burn the Pledges

So my questions are:

  1. Does Move have any procedure to get the current time/date so I can verify the campaign has expired?
  2. How do I iterate over all pledges to process them when the campaign has ended?

I have a feeling for the 2nd point I would need to issue a separate transaction to process each pledge separately (e.g. allow Alice to claim all the pledges one by one if her campaign succeeds, or allow the people to each individually reclaim their pledge if the campaign fails). Is that right? It doesn’t seem ideal.


I am also very interested in everything smart contracts. Please keep up with your journey, documenting your thoughts and procedures. Keep up with it great job :star_struck:


@MartinSherburn also interested in this. fetch previous version LedgerInfo via RPC thread they talked about a Time resource plans. In the meantime, have you found anything wrt current time?

Digging a little deeper I think exploring get_height built in may proxy the behavior you’re looking for.

Please keep documenting, would love to follow on this.