On-Chain Blockchain Storage Explained Simply

Alex Gieson
Coinmonks
4 min readNov 16, 2022

--

On a previous article I wrote about on-chain blockchain storage, I was asked to explain it in simpler terms. After looking back over it, I do agree that it was a technical article, so in this article I intend to break it down and explain some of the different storage techniques using less technical language to help conceptualize what’s going on!

What data are we storing?

There are many different types of data to store on the blockchain, but in this article we will be focusing on the tokenURI of NFTs. The tokenURI holds data that is specific to each NFT, such as the image, the collection it belongs to, a description, and any other attributes that might describe the NFT. The tokenURI is formatted as a json, which is a widely used method of organizing data.

{
"name": "Alex",
"occupation": "student",
"age": 22,
"hobbies": ["music", "writing", "running", "photography"]
}

This example shows how the data is organized in a JSON structure. If you’ve programmed in Python before, it’s essentially the same structure as a dictionary. We can see there are different fields, and each one can be filled with a string (text), integer (number), or list (multiple strings). For example, if we were to ask the JSON what the "occupation" field is storing, it would tell us "student".

TokenURI

Now that we understand the basics of JSON structures, we can take a look at an example tokenURI from a text-based NFT project called In Writing.

{
"name": "In Writing #0",
"string": "SGVsbG8sIFdvcmxkIQ==",
"external_url": "https://inwriting.io/text/?tokenID=0",
"description": "In Writing is the first text NFT collection that allows for 100% on-chain storage of any unique string of characters! Mint your own strings at inwriting.io",
"tokenId": "0",
"image_data": "https://inwritingapi.com/inwriting_polygon/get_svg.php?tokenID=0"
}

From the JSON, we can quickly gather its name (In Writing #0), tokenId (0), and a description of the NFT. The "external_url" takes you to the website of the project and show’s you the NFT, and the "image_data" is a link to the image of the NFT. What is the "string" field?

In Writing is a text-based NFT project, so they are storing the text of the NFT (where all of the value of these NFTs comes from) in the string field. "SGVsbG8sIFdvcmxkIQ==" doesn’t really mean much though, why would anyone turn this string into an NFT? Actually, it’s the text "Hello, World!" , enrypted using base64 encryption. Check it out here! There are many reasons to base64 encode the text, but the biggest one would be so that a " in the string would not mess up the JSON structure!

On-Chain Storage

Circling back to the topic of this article, let’s examine each field and decide which fields of the tokenURI are on chain, and which ones are off chain.

On Chain

  • "name": "In Writing #0"
  • "string": "SGVsbG8sIFdvcmxkIQ=="
  • "description": "In Writing is the first text NFT collection that allows for 100% on-chain storage of any unique string of characters! Mint your own strings at inwriting.io"
  • "tokenId": "0"

All of these fields are on chain, because they are given to you directly from the blockchain in the tokenURI. You don’t have to go to any other website to get the information you want, they are all right there for you.

Off Chain

  • "external_url": "https://inwriting.io/text/?tokenID=0"
  • "image_data”: "https://inwritingapi.com/inwriting_polygon/get_svg.php?tokenID=0"

These fields are off chain, because you have to navigate to a website (not hosted by the blockchain) in order to get the data you want.

Pros and Cons of On-Chain and Off-Chain Storage

As an investor in an NFT project, you want the value of your NFT to be stored on chain. When something is stored on chain, it means it will be there forever, without having to count on someone’s website being maintained! This means your NFT can’t lose all of its value due to a website going down or completely offline.

If on-chain storage is better, then why not store everything on chain? In an ideal world everything would be stored on chain, but unfortunately on-chain storage is very expensive. Images, for example, are very large and would cost hundreds, if not thousands, of dollars to store on chain. Text, on the other hand, is not very large and can be stored on chain inexpensively.

Looking back at the example of In Writing’s tokenURI, why did they store the image of the NFT off chain? Isn’t the image the valuable part?? In most cases, the image is the valuable part of an NFT; however, In Writing is a text-based NFT marketplace, which means the valuable part of their NFTs is the text itself, not the image of the text. So, the valuable part of In Writing’s NFTs are stored on chain in the "string" field.

Conclusion

Now that you understand the meaning of on-chain storage, you are now more knowledgable in the cryptocurrency world! Understanding the value of on-chain storage can help you when making investments, creating your own project, and even at the dinner table if you’re having an in depth conversation about blockchain technology. I hope this article was a good introduction into the topic of on-chain storage, and if you have any questions feel free to comment!

On-Chain Blockchain Storage Explained Simply

--

--