[Project: Blockchain] Algorand Crypto CornHole

Desc:

9th Blockchain IoT project…😋
Algorand 2021 Hackathon
CornHole + Arduino + Algorand = FUN


This is also my first Hackathon! First real smart contract project on Algorand too!

Link here: https://www.encode.club/encode-algorand-hackathon

This project is a culmination of every thing I like:

  • Embedded Systems (Arduino is cool!)
  • IoT (Sensor in everything and everywhere…)
  • Blockchain (Algorand is cool!)
  • Smart Contracts (It’s like sliced bread!)
  • Beavis and Butthead (1980’s Adult Cartoon, I’m OLD!)
  • Python (So many frameworks and support!)
  • CornHole (Duh!!!)
  • Drinking beer (CornHole needs beer!)
  • Crypto (Because its cool!)
  • Betting (Because its cool!)

So long story short I wanted to challenge myself (SOLO) and learn something fun and new with drinking and games. It’s also where I showcase my many talents in a lot of different areas. This is it… Nuff said…

I want to give many thanks to Algorand Developer Vilijan Monev and his TicTacToe project that help bootstrap my Decentralized App (DAPP) rather quickly! Please see his great project below. In fact, his implementation via smart contracts is what I use and is about 90% similar.

There’s a few modifications that I had do since Tic-Tac-Toe is somewhat different to CornHole. The game logic for Crypto CornHole is also much simpler as its the first player to reach a threshold and win the game (21 in real CornHole and 3 in my implementation). This is for demonstration purposes and can later be increased to match the real CornHole game. Also eliminated is throwing 4 bags per inning per player. I had really simplified Crypto CornHole to be 1 bag per inning per player to deal with corner cases that I’m not ready to handle at the moment.

Link to Official CornHole rules: https://www.playcornhole.org/pages/rules

I must emphasize that Vilijan solution to smart contracts is very well done and I will not discuss any further here. See the link below to get a better understand of his Awesome smart contract implementation!

Link here: https://developer.algorand.org/solutions/tic-tac-toe-dapp/

*Note I’m not using real Crypto! I’m on Testnet which is a mock of the real thing. Go here if you want fake monies…

Link here: https://testnet.algoexplorer.io/dispenser


Gotchas:

Please take notice. This is not a simple run and go. There is quite a bit of overhead to get it running, but here are some hints along the way to help before running the code. It’s not for the faint of heart! You have been warned!

  • Use Anaconda to install the conda environment. It’s very useful for sandboxing Python virtual environments. Link: https://www.anaconda.com/products/individual
  • Install the python required libraries via ‘pip install -r requirements.txt’ to support the DAPP.
  • This is a rather tricky one wrt. to accounts. The original code I forked from generated 3 new accounts (player x, player o, creator) automatically that needed to be replenished with the Testnet Dispenser. I had different ideas thou because I wanted to control player acounts via the Algorand iOS Wallet for a later feature of this project that I did not have time to get to (QR code scanner for player registration). Nonetheless, I was able to extract two accounts from Algorand iOS Wallet and copy over the info (public key) into the ‘app.py’ DAPP code and ‘config.yml’. Not including the private key for the players accounts which needed to be transformed using some clever Python and Algorand SDK to go from passphrase to private key. The creator account was a little creative and used Python and Algorand SDK to generate account and correspond public and private key. Always make sure to top off the three accounts else TROUBLE!
  • Also one biggie is the creator account is limited to 10 DAPP instances. That means after 10 DAPP runs, a new creator account needs to be created to continue.
  • Its also important to have a PureStake account to access the Algorand Testnet Blockchain via API calls instead of a personal Algorand node. It makes development much easier! Grab the API token from Pure Stake and copy to ‘config.yml’ to run the DAPP.
  • I run on Windows 10 ( I know right?) but I use VirtualBox to run a VM with Ubuntu 18 installed. I like doing this because I can sandbox my OS and custom make it as I progress and keep project specific. Keeps things very organized. VM is also great at taking snapshots of your OS at different times so going back in time is great time saver if too much bloat happens and need to fork to another custom build.
  • To run the DAPP not only requires python and pip install, it also requires Streamlit a Python prototyping framework to make things work. In fact, running the DAPP via command line is special. Heres a hint its not ‘python3 app.py’. It’s more like ‘streamlit run app.py‘. Fun right? Now try integrating that with PyCharm and debug! I did it. Can you?

Github:

Branch: Main

Tag: CornHole.1.0.0

Repo: https://github.com/csalinasonline/projectAlgorandCornHole

Forked: https://github.com/Vilijan/TicTacToe_Algorand


Video:


The Hardware:

  • Qty, Desc, Vendor
    • 1 set of 2 Professional CornHole Boards, Ultra
    • x1, PC Windows (with VirtualBox Ubuntu 18 VM), Amazon
    • x2, Arduino Unos , Amazon
    • x4, Bluetooth Serial Modules, Amazon
    • x2, USB to Serial Modules , Amazon
    • x2, Power Management circuit, Amazon
    • x2, Step-down PSU, Amazon
    • x2, Addressable RGB LED light strip , Amazon
    • x2, Ultrasonic transducers, Amazon
    • x2, Accelerometers, Amazon
    • x2, MP3 Player circuit, Amazon
    • x2, Lipo Batteries 2s 5Ah, Amazon
    • x2, Lipo Chargers, Amazon
    • xX, Misc wires, resistors, electronic stuff? , My Self
    • BOM Link: https://github.com/csalinasonline/projectAlgorandCornHole/tree/main/BOM

What Do They Do:

  • CornHole Boards – Well need CornHole Boards to play CoreHole of course 😋
  • PC Windows (with VirtualBox Ubuntu ) – The DAPP runs on the VM that is connected to external hardware via the two ‘USB to Serial Modules.’
  • Arduino Uno – The computer brains for each CornHole that takes sensor data from sensors and outputs lights and sounds. Communicates via Wireless Bluetooth Serial to PC.
  • Bluetooth Serial Modules – Connected to the ‘USB to Serial Modules’ to enable wireless capabilities.
  • USB to Serial Modules – See PC above.
  • Power Management circuit – Off-the-shelf circuit that watches battery level and cuts off power when too low to prevent battery damage.
  • Step-down PSU – Take high battery voltage of approx 11.1v to 5v to run electronics properly.
  • Addressable RGB LED light strip – Lights are a great way to communicate status. Solid blue means IDLE, alternating on-off colors means a Woody (1pt bag on board), alternating chase colors means a CornHole (3 pts bag in hole).
  • Ultrasonic transducers – Detect bag in hole for a CornHole.
  • Accelerometers – Detect bag on board (or hit board) for a Woody.
  • MP3 Player circuit – Play sounds to communicate status in a funny way with ‘Beavis and Butthead’ sounds bytes. A Woody plays annoying sounds and CornHole plays the theme song.
  • Lipo Batteries 2s 5Ah – Need to power all the electronics for CornHole.
  • Lipo Chargers – Off-the-shelf charger that plug into wall and charge batteries.
  • Misc wires, resistors, electronic stuff? – we’ll need to connect stuff and overhead. This ain’t a simple lego project 😋

The Block Diagrams:

I like diagrams. I’ll let them do the talking…


The Schematic:


The DAPP:

The bridge between the users and the blockchain. Use Streamlit python framework! It make life so much easier prototyping and releasing an Minimum Viable Product (MVP).


The Algo Explorer:

It’s all on the blockchain! You can’t call B!@$*&()!!! It’s all on the ledger for everyone to see!

Link here: https://testnet.algoexplorer.io/application/28852393

See the smart contract! Anybody can audit it!

See the variables for player scores! It’s saved on the chain forever! Can’t get any easier than that!

See the transactions! It’s even timestamped!


The Prototype:

I like pictures!


About

Medium: @csalinasonline
LinkedIn: https://www.linkedin.com/in/conrad-salinas-17a29327
Site: https://www.DeepHomebrew.com

Medium Link: TODO
YouTube link: TODO
Site: TODO

Discover more from deepHomeBrew

Subscribe now to keep reading and get access to the full archive.

Continue reading