dillon-lomnitzer/dev

skip to content

I put a game inside an NFT

Last edited on November 14, 2024

You heard that right 🙃. In this brief article I'll describe the thought process and steps I took to put a working game inside an NFT that can be minted on the blockchain!

Introduction

NFT's have been around for a while now, and since their inception they've come a long way in terms of functionality and popularity. I remember the early days of the ERC20 token standard, Defi yield-farming, and the first NFTs. This evolution has blown my mind every step of the way.

I knew pretty soon after hearing about the blockchain that I was already magnetized to the idea of creating some tpye of ethereal currency that can immutably live on a blockchain for.. eternity?

I've been pretty lucky, and thankful, to have been part of some amazing teams and to have helped turn their blockchain ideas into full blown projects. This has lead me down a path I will not regret. Ok, enough about me.

ZORK

Zork is a text-based adventure game that was developed in the year 1982. It was made for and played on some of the earliest computers.

For some reason I was drawn to this game, it was simple, yet so verbose. I knew immediately my goal was to recreate it in some modern language and host it for anyone to play.

So that's what I did. I spent a few days using Vanilla JS mapping all the rooms and items from the original game and got it quickly hosted online. Obviously as a developer you're never content with what you've built previously so it's gone through a couple iterations. But all in all I mostly finished Zork and it's available to player here!

It's NFT Time

It was only a matter of time before I took one passion and combined it with another. At this point I've played with NFT's and their metadata enough to understand what the possibilities were, and although I've seen some amazing stuff done by people I had yet to see an actual game on token.

The first part of this was relatively simple. I knew that being a static game I could place the files on a CDN so the game could be distributed efficiently. I uploaded the content to a CDN storage spaces on Digital Ocean and messed around with some policies until I was able to visit the CDN link and run the game. The code for the game is relatively straightforward. You can check it out the codebase here to see what I'm talking about.

The next step was creating a generic ERC721A contract to generate tokens. That was pretty straightforward as well considering I have plenty of templates left over from other projects. This made bootstrapping easy with a super simple mint function

function mint(uint256 quantity) 
external payable callerIsUser nonReentrant requireCorrectEth(quantity) 
{
    if (!publicSaleActive) revert SaleNotActive();

    if (userMinted[msg.sender] + quantity > MINT_LIMIT_PER_ADDRESS)
        revert MintLimitReached();

    userMinted[msg.sender] += quantity;
    _mint(msg.sender, quantity);
}

Once I deployed the ERC721 ( NFT ) token the final thing to do was set the metadata pointing to my CDN. That way when the token shows up on a marketplace it will scrape the metadata_uri for the CDN url.

This is what the metadata looked like:

{
	"description": "This is a test token for the ZORK project",
	"image": "https://zork.nyc3.cdn.digitaloceanspaces.com/zork.png",
	"animation_url": "https://zork.nyc3.cdn.digitaloceanspaces.com/index.html",
	"name": "Zork Token"
}

I generated 2 tokens to test it out, and when I opened OpenSea what do you know! There's ZORK, playable, inside of an NFT on OpenSea!!

Zork on Opensea

Note

As of the latest update of this article Ethereum has swapped tesnets from Goerli to Sepolia and I have yet to re-release the token on Sep so any link is unplayable atm.

Conclusion

This was a much less technical article and more about the though processes of the project. My next steps are finding a away to preserve unique game data, and possibly even verify ownership so that no one else can play your game except the owner.

Until then remember, with grea power comes great responsibility 🧙

PROJECTS

© 2013–2024. Dillon Lomnitzer.