Plutus Smart Contract Series - Jellybean Guessing Game

Since a number of people were quite excited about the idea of having more Plutus smart contract examples I decided to create a SC “series”. This series goes step by step in setting up a Jellybean Guessing Game from an empty SC all the way to automating closing the game and user input error checking. There are 8 contracts in total and each file has a short explanation commented in. Eventually this may end up becoming a full-fledged tutorial with detailed instructions on all of the specifics, but for now due to time-constraints this ‘series’ is geared for the more dedicated individual.

In this ‘series’ the topics that are covered include:

  • How to lock funds in a smart contract (with a DataScript attached)
  • How to attempt to redeem funds from a smart contract (with a RedeemerScript attached)
  • How on-chain code works/how it validates whether a collectFromScript call is valid.
  • How to hash the winning number and validate the hashed guess.
  • How to set up wallet triggers/handlers to automate closing the game after block #10 if the player failed to guess the answer in time.
  • How to check data inputed via the UI to make sure it is valid, else throw an error.

I look forward to seeing more devs jump in and start using Plutus, so if you have any questions feel free to ask them here and I’m sure it’ll end up helping out a lot of other people too.

25 Likes

A sincere thank you for this!

3 Likes

Tested it out on https://prod.playground.plutus.iohkdev.io/ and … IT works! :clap:

thank you very much to provide such examples and share your knowledge with the community.

3 Likes

How did you test it @werkof and @bobert ? Can I copy and paste the code in each file into the Plutus Playground and press compile? I would like to play around with it.

Nice work making a smart contract Robert.

~Rick

1 Like

Indeed Rick, simply copy and paste the code into Plutus Playground and press compile. I’d recommend starting with the final smart contract so you can get a feel for how it’s suppose to work ( the first 4 or so set up the boilerplate and won’t really do much if you intend to simply play around). From there make sure you call watchSCAddress in Plutus Playground (calling it for both wallets gives you the most freedom), and then you can lock a number and guess a number to play the game.

5 Likes

Excellent job, thank you very much

2 Likes

Kudos to you, sir.

Thank you for sharing the wealth that is knowledge.
I will be moving to a new place this weekend, and will probably not be able to sign on as we unpack things and get internet and utilities turned on.

Happy New Years and blessings to you and your loved ones. (Along with everybody in the Cardano community. Let’s do great things in 2019 and beyond.)

4 Likes

@bobert Thank you so much for posting this. Just ran it in Plutus Playground. Super helpful to me as a beginner!

2 Likes

Thank you so much! I am hoping to get into the Hackathon at the Summit next month (and continue to develop with Plutus), but as a new Haskell programmer I was feeling pretty lost. This will help so much! I’ll let you know if I have any questions :slight_smile:

4 Likes

Great to hear that this has come in handy. I’ll be a the Summit myself so we may end up running into each other at some point. Nonetheless, I wish you luck in the Hackathon :+1:

4 Likes