What is an NFT?

It might not be what you think....

What is an NFT?
Photo by Andrey Metelev / Unsplash

It's not what you think

This article isn't what you think. It's not a discussion piece on how NFTs enable or transcend art, how they are gateways to communities and shared experiences. How they enable builders and creators to connect with users in ways never before possible. NFTs might be those things and more. But that's for another time. This article is crunchier than that: it's literally "what is an NFT", from a technical perspective. If you own an NFT, what does that actually mean?

It's in my wallet, right?

Well, no, it isn't. There is actually nothing in your wallet. And that's even if you haven't clicked that link for a cat pic NFT and inexplicably signed the transaction it popped up. Your wallet doesn't really exist (unless you are using a smart contract wallet, in which case you could argue that does exists - more on smart contract wallets another day). When you own an NFT (or any token), there is a blob of memory somewhere on the blockchain that says that NFT 69420 belongs to address 0xwhatever, and it's 0xwhatever that has exclusive(ish) rights to tell the contract that now 0xsomeoneelse owns that NFT.

Your wallet is what allows you to confirm that you own address 0xwhatever and therefore can update that particular bit of memory. But its that memory, administered by the smart contract, that says that an NFT even exists in the first place.

So what summons an NFT from the ether (pun intended)?

Photo by Eleanor Chen / Unsplash

Minting and Transfers

Three things happen when we mint an ERC721:

  • A counter for our address gets 1 added to it (this records our balance)
  • The owner of the token ID being minted gets recorded as our address
  • The contract sends out a message (emits an event) to say the first two things have happened

That's all that's needed for that NFT to now exist and be 'in' your wallet. If you ask that smart contract who owns token ID 69420 it tells everyone that you do. If you ask it your balance, it says you have one.

Other services off-chain will be watching both transactions and the emitted event to build up a picture of that NFT collection. They will aggregate these messages, which includes watching and noting future transfers. Applications like OpenSea use this information to display collections on their site.

There are four things that happen on transfer, and you might be able to guess what they are:

  • It reduces your balance by 1
  • In increases the balance of the address you are sending it to by 1
  • It sets the owner for the token to the address you are sending it to
  • It emits a message to say the transfer has happened
  • (It clears the token authority on that token in case you have set that - more on token authorities later, don't get me started...)

And whoosh! Conceptually that NFT is now in someone else's wallet!

Say what?

To recap: an NFT is some memory that says your address owns a token Id, with a +1 added to your balance.

But why oh why are you asking this omnus, you cry (if indeed you are still reading).

I've been thinking a lot lately about NFT gas usage, and then more specifically on SBTs (soul bound tokens). It strikes me that ERC721 is optimised for suboptimal memory usage. Every single NFT records it's owner, so if you own more than one you are storing 160 bits (the size of an address) over and over again. It also means that if you move those NFTs, for any reason, you have to update every single instance of those 160 bits.

This seems daft, and of course means moving NFTs cost a lot of gas. Some things help, for example services like niftymoves (still the most efficient free NFT transfer service that has never been used by anyone other than its creator). And if we build batch transfers in to the NFT itself we save hella huge amounts of gas (c'mon everyone, just do this). But we could save HUMONGOUS amounts of gas with a better storage structure. If rather than labelling token Ids with my address we could put them in a bag (bag 1 lets say), and note that I owned bag 1. I could transfer all my NFTs (let's be obscene and say I own 1,000,000) for the same cost as transferring a single NFT now.

You read that right. Of course there are complications, but this is why we innovate.

You mentioned SBTs?

Oh yes! I am also looking at that. SBTs are (in a very crude nutshell) NFTs that can't be transferred. I hope that the standard for these isn't just ERC721 with _transfer() removed.... I have been playing with what we can rip out if we know that the token can never move.

For example, I have a prototype contract which mints gasless SBTs. WTF I hear you say, but you heard right. The contract 'issues' these tokens with no gas required. If you check the contract for the new SBT it says you own it, and it has your balance setup correctly. The issue is letting other things know it exists. Which is what I am working on now.

Thanks for listening!!

p.s. If you want these to arrive in your inbox you can subsribe. There is no cost. If anything suggests a paid tier or whatever it does not exist. Everything here is freeeeeee!