Inspiration

Money Matches

Coming from a background of competitive gaming, I didn't like the current state of GameFi. The current play to earn model makes sense for a lot of people, to me it is incredibly boring. On top of that, the gameplay in most of these games is far from good, if they did not have the P2E aspect then they would get very little recognition.

I wanted there to be a system setup to leverage the good parts of web3/Gamefi and use them for a matchmaking dapp, whilst also making use of already existing good games that these wager matches can be played out in.

The idea would be that two players can put up $5 each, they play a game of chess, the winner gets sent the $10 after the game has finished.

This can be achieved through a mix of on-chain and off-chain work.

What it does

At present,

  • Users can create games by specifying a wager in eth. This is done by signing a txn on the frontend which creates a match and stores it in the smart contract storage.
  • Users can accept games which another player has created by specifying the gameID, users can only accept games which have not been played/paidout/cancelled.
  • Users can cancel a game they have created before it has been accepted to get their wager back.
  • Users can play the game off chain in the python gamepy game, this verifies that a game has been created and has not been played yet. Upon winning this game the winner is pushed to a json bin.
  • Winner can then settle the game on the frontend and receive their winnings.

Built and deployed on Goerli.

How I built it

For the backend I used Solidity to create and store the match details on Ethereum. This meant I could easily create/accept games and process payments at the same time. Once a player has created a match, I made this data public so that the game client could verify a valid match was created, this was done using python web3 libraries, and checking the off-chain winner data to ensure it hasn't been played yet.

If the match was valid for this gameid, with the two addresses of the players matching up to this gameid, the game of connect four could start. Big security flaw here as I'm simply just typing in the addresses to the console here without verification, will mention my ideas for this in the bottom section

For the off-chain data I used a json bin which I could read and write to. When the game of connect four finished, an HTTP put request would send the address of the winner to this bin.

Now that we have a game played and the data in our json, the winner can settle the game by calling this function on the frontend, this uses the chainlink api to read data from a json array. Our gameID matches up exactly with the winner array in our json bin, so when this api is called and the chainlink request is fulfilled, the winner is automatically paid out their wager within the same function.

Challenges I ran into

Mostly time, I have opted for this dodgy python game approach to demonstrate how I want the off-chain game to look like, but in the future I want to wrap this platform around a proper in browser game like chess so it's actually usable.

I hadn't worked with chainlink APIs apart from in tutorials so it took me a little while to figure that bit out.

It was very fun trying to workout a clean way to get the winner match data pushed somewhere then read by the contract though, my current method isn't scalable but it taught me a lot about how to go about it moving forward.

Accomplishments that I'm proud of

Very happy to get a prototype working. The fact that a game can actually be played off chain, then settled and paid out with one more transaction in a clean way makes me proud. It makes me excited for what else I could apply this platform to.

What I learned

That I need to have a more serious think about scalability and security before revisiting this project. It's ok in it's current state for the hackathon, but I need to plan a lot more to bring this to life.

What's next for Money Matches - Competitive GameFi

I have a genuine passion for this project so I'm going to keep working on it, a clean competitive platform like this could have a lot of potential on chains like polygon or bnb where the txn fees are so low, games could be played for a couple cents and it could open up the market to anyone.

First thing would be to get rid of the python demo and move to an in browser game. I'm thinking chess!

Share this project:

Updates