@howo recently shared with me the image below (neither of us made this image, but I have a reasonable belief that it's copyright free), and it made me realize there are some common misconceptions about 2nd layer apps that are worth dispelling.
Originally, I was going to make one post about this, but it started to run long when I tried to avoid skipping any steps in my explanations, so I’ve decided to break it up into a few short, easy-to-digest posts. This also means I won't be explaining all the problems with this image today, either, but hey, what's life without a little anticipation?
Misconception 1: it’s difficult (or impossible) to make decentralized 2nd layer apps
Creating a 2nd layer app on Hive is almost trivially easy for an experienced programmer. How easy? Let’s take a look at how to go about creating a 2nd layer app for playing decentralized tic-tac-toe matches.
Design the transactions and protocol rules for your tic-tac-toe app
To start a game, we just need two operations:
offer_match, “player”: “mynextvictim”
accept_offer, “transaction_id”: transaction_id_of_offer
Whenever a player wants to challenge a player he broadcasts an offer_match. For this simple example, our app will just auto-expire an offer if it isn’t accepted in 24 hours.
To accept an offer, the challenged player broadcasts a transaction with the “accept_offer” operation that includes the transaction id of the original offer. If the acceptance is broadcast within the 24 hour period, the app will start a game and accept moves from each player.
So we just need one more operation, the “move” operation:
move, "transaction_id":transaction_id_of_offer, “coordinates”: [row_number, column_number]
Again, for simplicity, we’ll design our app so that the challenged player gets the first move, but we could easily make this a parameter of either the offer or the acceptance operation.
We just need to add a few more protocol rules: 1) players need to take turns moving, 2) players can’t move to a previously occupied square, 3) player wins if he gets 3 in a row, and 4) game ends in a tie if 9 valid moves occur without a winner (i.e. all the squares get filled).
Defining the protocol rules are so simple, there’s probably marginally more work in writing the user interface that displays the tic-tac-toe board, allows the user to click on squares, and updates the board as moves are received from the blockchain. But all of this is pretty easy to do, code-wise.
For Hive, two great choices for a programming language to do this would be Python or Javascript, as Hive has easy-to-use libraries that allow your application to publish and read transactions from the blockchain.
Decentralize your tic-tac-toe game
Now, as easy as it was to design, there’s still the “hard step” of decentralizing your tic-tac-toe app, right? Nope, that’s the really easy part.
Simply publish the official rules publicly. Ideally, you would also publish your source code with a license that lets anyone run your code. Congratulations, you can play decentralized tic-tac-toe with other people around the world, secure in the knowledge they can’t cheat. Anyone can run your code on their computer, connect it up to a Hive API node, verify all the game transactions, and determine who really won each game (although, fair warning, most of those games are probably going to be ties).
The blockchain maintains an immutable record of what moves were actually made, and by whom, so all you need is the publicly available “tic-tac-toe” rules to determine the winner. Someone can run a server that provides false answers, but you can always run your own server to find out the truth.
The example reminds me very much of things @edicted likes to play with
Many dapps utilize tokens (NFT or FT) - I hope there's some discussion around those later in the series!
Too bad I don't actually have a working product to point to, eh?
Soon™
Better to be working on it then to have never. My game idea might never get off the ground because I can't figure out how to program lol
Eh you'll figure it out. Things are going to get easier around here. The entire network has financial incentive to teach everyone the basics.
I am actually going to force myself to learn how to program!
Maybe we can learn together lol I’m decent with a fair amount of things but programming has been one of the ones I haven’t dipped my feet into yet. I’ve downloaded an app that’s pretty good at teaching but I used it for about 2 weeks before I stopped. It’s called Learn Python. Seems to be decent but I need to figure it out to write some stuff.
Tokens will definitely come up :-)
I think this is a hint of a pump coming..
Only a little pump maybe but BUY HIVE should be headlining in Leo community at least. Maybe I'm wrong but some HYPE is needed for that coming HF to get Hive back closer to Steem. On CMC at least.
I could definitely use a pump-up!!! Oh, Tokens!!!
Lol watch them exchanges wiggles!
If you see a rise in BUYS you know the whales are about to take a big meal. They might vomit shortly after though so don't hold too long.
Btw did you know whale waste is highly valuable? Not trying to be funny here it's actually a real thing.
https://www.scientificamerican.com/article/strange-but-true-whale-waste-is-valuable/
Hive Whale waste though.... I'm not sure if that has much value outside of the circle of Dutch Rudders.
Haha! Good advice!
Well if it brings more utility and dapps to the ecosystem or allowing us to connect to other ecosystems with your HIVE wallet, why not? Open it up, crypto is still in the BUIDL phase, people need to forget about holding on to what we've got, this space is about taking risks
I have started learning python to try some programming on hive chain, can we have some complete tutorials on 2 layered use ? Like have some simple extended JSON and publish it on hive. The dapp can design their own JSON data.
There are some tutorials here: https://developers.hive.io/tutorials/#tutorials-python
Will a tic tac toe genius bot be considered cheating? 🤔
Posted using Dapplr
You could just try it.
Pretty much the only way to win tic-tac-toe is to go first, take the center square, and then hope your opponent doesn't move into a corner. Then you can force a win by moving into a corner.
#spoilers
Lol yeah basically the case but I was just asking in general if bots count as cheating
i wouldn't call bots "cheating"... a bot also has to play by the rules enforced on the 2nd layer protocol...
but bots can be an unfair advantage and spoil the fun for normal players.
definitely something to consider when designing an app.
yeah bots are cheating which is exactly why it would be so hard to design a game on blockchain with a financial incentive. The motivation to Sybil attack the network is quite high.
I've always wondered why people are so comfortable with paying to play games like fortnight and the rest but whenever blockchain is attached to a game, it always requires earnings. 🤔
I wouldn't say a blockchain game requires earnings as much as it does ownership. Ownership and power over the product must be decentralized to the community. The problem here is that you can't really separate ownership from earnings because anyone could sell what they own. Without this dynamic there is no reason to use crypto or blockchain tech to begin with, doing so would just make the product less efficient, more complicated, and harder to scale.
Yeah this pretty much sums it up really. Everything is so damn ceremonious and drawn out.
That meme looks like someone is butt hurt that they didn’t think of a second layer app first now they are kicking themselves and trying to throw shade lol
saludos amigos
Excellent article !!! very informative
Also, if you feel cheated, you can always replay everything and get to the truth. For example, if someone steals your NFT somehow, using a different type of transaction, it will always show on chain and can always be canceled.
When I see these publications I realize that due to my technological ignorance I am missing an important part of this community.
In any case, I enjoy sharing (publishing and reading) and I thank you for your efforts that make it possible.
Gracias/Thank you.
How would you go about verifying all the game transactions through a Hive API node? Is there a way to pull a subset of all the blockchain custom_json transactions, i.e. only those custom_json that are flagged as belonging to your game? And only for a certain set of users?
I didn't think that this kind of detail was currently possible through the API? I'd be very happy to be wrong.
well, if code is only streaming and verifying it would possibly take A LOT of data reading but its technically possible to verify all the transactions of the game with Hive API.
I think it's currently technically possible by:
(a) Streaming all the blocks of the blockchain and separating out custom_json that match your game criteria.
(b) Pulling the operations of each user account involved in the game and separating out custom_json that match your game criteria.
These approaches are OK if you have a centralised server for your game that can do this work and update the current game state for all players.
However neither of them is really suitable under a decentralised approach, i.e. if each game participant has to carry out this work themselves to validate the current game position. You don't want to be streaming the last 10,000 blocks to find 9 noughts-and-crosses moves.
Is there currently a better way?
Yes, you are right, that is why i said its 'technically possible' because:
It pretty impractical to do this on some public Node (Hive API). so in conclusion the game is decentralized and if you have doubts you can always verify running your own node.. a better way? maybe this tic-tac-toe game can have a ledger & blocks storage & hash verification (like hive-engine) which would be faster since now your only looking the game transactions (but a mumbo jumbo of blockchain code witch is totally op for a tic-tac-toe game), don't know if it makes sense. the final goal is that it can't be cheated, you can always verify.
Right now you have to pull them all, but the API you're describing is also pretty trivial to implement.
That's good news. I think we would see a lot more game development if devs could just pull their own data rather than having to deal with the full blockchain.
We see this with the front-ends. The Hive API is pretty good for building a front-end, so a lot of them get built.
We would also potentially get some invention / progression into true decentralised gaming (as you outline in your article) which I think would be really interesting.
Visit my hive blog please
The main obstacle for building layer 2 apps is that there is no monetization model. Without Smart Media Tokens apps are not able to create new ecosystems, experiment with new tokenomics, and build communities. Hive blockchain has a lot of advantages (speed, free transactions, usernames, etc.), but we are two years behind all other projects in launching tokens.
At the time of publishing of the initial white paper, SMTs were a great concept, pioneering Automatic Market Maker and customization of token rules. Sure, we can blame Steemit for not doing their job for all these years, but when I am looking at the DHF, there is noting to suggest we might see SMTs any time soon.
Congratulations @blocktrades! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @hivebuzz: