Christmas Card v2

Last year I sent out our family Christmas Card to about 50 people, but I included a little bit of a challenge to add a little bit something to it. It was all in fun, and I hoped that some would find it interesting.

v1 – 2021 Retrospective…

What was it you ask? Well it was Bitcoin. One the back of everyone’s Christmas Card I attached a sticker that looked something like the following:

It was a Bitcoin Private Key, that was customized partially with their name, of which I had just deposited a token amount of bitcoin, that they could own and play around with. In the end, about a handful of people were able to figure it out it was Bitcoin and collect their reward.

So, on to year 2…

v2 – 2022

Being pretty happy with the 2021 idea, but wanting to see more people involved, I decided to evolve it a little more for year two. After some thought, I still liked the idea of Bitcoin, but I wanted to make it more approachable, so I decided to do more of a game, in which you could play and then win Bitcoin.

So, what does it look like? Well it ended up looking like this:

As you can see, everyone of the recipients got a customized link, that would take them into the game, in which they could answer some (mostly family related) simple questions. It was an opportunity for me to say “Hi” with a little bit of a custom message beyond the postcard.

When you would visit, this is what the site looked like:

Not being much of a designer, the site above is what I came up with. When you first log in to it, it presents you with a simple welcome message, including a custom short You Tube video wishing everyone Happy Holidays. Following that, it takes you right into this experience, where you start answering a series of questions moving from one level to another.

At each level you get an option to answer the question, or to skip on to the next level. If you answer correctly, then you earn Bitcoin, and it is deposited into your account. At the end of the game, you can then check the balance of your account, and then just transfer out the money that you have earned.

And, that is it as they say. If you are interested in knowing a little more about how it all worked, then please read below, and if not, then I hope you enjoyed, and we will see what is to come in year three.

Behind the Curtain

There were three main components to make this work, and they are the following:

  • API/Data – Backend API and data which kept track of which players were on what levels, and to be able to react and response to their answers.
  • Website – Static website which presented the Game to the user with the data from the API included.
  • Bitcoin Scripts – Scripts that were capable of taking bitcoin from one account (“the bank”) and then depositing it in other accounts for the different players.

This will all eventually be hosted on GitHub or some equivalent, but I have not done that yet.

API/Data

Being more of a backend person, it all starts with the data. Here is the key data and concepts that I really needed to keep track of:

  • Invites – Who was invited (eg. their name), what was their current progress in the game, and some other associated metadata such as the account that I would deposit their earnings in (eg. Bitcoin address and private key).
  • Levels – The questions associated with each one of the levels, what the acceptable answers were, and what the prize was for getting it right.
  • Stats – Some global stats such as how many people have won each round.

For simplicity sake, this was all stored in json files. Here is an example of one of those files.

<.../invites/test.json>
{
  "name": "Smith Family",
  "bitcoin_address": "1G2zt786BsvKJXAvTamW3Bds64e6pcQBMx",
  "bitcoin_private": "L22zGSFr75Cix3h8BUKxfyRUTpxEnNC442pvjnwP2F2GNEppUKuc",
  "level_current": 1
}

That was the data part, but in addition there needed to be an API. Following up on some previous work I had done, I made a simple JSON Python-based app that responded to requests for data, along with submitting of answers to progress though the game. Here is an example of what that looked like:

https://api.achille.com/xmas/profile
{
  "name": "Chris"
  "bitcoin_address": "1G2zt786BsvKJXAvTamW3Bds64e6pcQBMx",
  "bitcoin_private": "L22zGSFr75Cix3h8BUKxfyRUTpxEnNC442pvjnwP2F2GNEppUKuc",
  "level_current": {
    "error": "",
    "id": 1,
    "message": "",
    "question": "<Question...>"
  },
  "levels": [
    {
      "level": 1,
      "name": "One",
      "prizes_left": 32,
      "winners": 3
    },
    ....
  ],
}

Done, now we have data, and a way to access and manipulate it.

Website

The website is not really my specialty, so it could be a little bit more polished, but I put together a simple HTML/Javascript/CSS website that allows you to walk though the questions, answer them, and also see the status of other things like your bitcoin balance.

[Shout out to Nora, my daughter, who helped me make some improvements, so it could atleast get to where it is!]

This is mostly done though some simple Javascript/Ajax which is calling the backend JSON/Python API to get all the data that it needs. It also have a couple other niceties like url rewriting which allows the urls to be nice and pretty (see original invitation for example) and to obscure that from the visitor. Not too much more than that, mostly just an answer and skip option which forward the data, and show the results to the user.

Done with second piece, so now we have a functioning website, but no prizes yet.

Bitcoin Scripts

You know a project is destined to not last long when part of it is held together with bash scripts…

One of the core pieces of game, was that when people did get things right, that they would earn some Bitcoin, so how was all this going to end up working? For efficiently, and really because it didn’t demand anymore like, as I said this was all done with Bash scripts.

Basically we start with a “bank” bitcoin account which has all the funds to be used for giving out during the game (side-note: See the starting idea for every crypto exchange that horribly failed, but doing it anyways…). I then created a Bash script which can call the correct command-line tools to then deposit X Bitcoin in Y Account. This is accomplished by doing the following steps every time we need to do another transaction:

  1. Check the “Bank” account and see if there have been any updates since the last time we have run. If there are then move all pending transactions to completed, if not, then just remember details about this source account.
  2. Create an internal pending transaction for placing X Bitcoin in Y Account. (This is as sample as a placeholder file in a particular format).
  3. Create a new Bitcoin transaction for all the pending transfers we are trying to accomplish. This creates a large command-line with exactly the right parameters and calls tx (from pycoin project). Then sign this transactions. This now represents all outstanding transactions we want to perform.
  4. Upload this latest transaction to the blockchain via https://blockchain.info/pushtx.

This script is then just called via the API when someone gets something correct.

Now really done (well, after tons of testing and bug fixes…)

Conclusion

This ended up taking me much longer than I expected, or really wanted to spend on it, but I am very happy with the results. While not pretty, it accomplishes exactly what I wanted, and is ripe for updates next year, which much less work.

People sometimes ask why I am so fascinated with Bitcoin… I am not sure if it will ever reach its full potential, but the answer is partially this post. How else could this have been done without something like Bitcoin? The ease at which I can just create some bits on my machine, anonymously post them to some random website, and just have it transfer money is amazing to me. In any other world I would need to write some ridiculously complicated API to interface with any financial institution, and it just would have never complete.

Wondering how people are doing in the game? Well, check it out right on the blockchain. Everyone one of these withdrawals is someone playing my game and winning…

https://www.blockchain.com/explorer/addresses/btc/13MU55NuURYjwQhPDS8REsVHu6GBzWwrvT