Onchain vs Offchain NFTs: Why Permanency Matters
The NFT market is now a thing. Everybody is buying, selling and flipping JPEGs, and most people have no idea what they are actually buying. They see an image, they see a price, and they think they own a piece of art. In most cases they own a receipt.
Because most NFTs are just a pointer. The token lives on the blockchain, and inside it there is a link to where the art lives. And where the art lives can disappear, change or be taken down. You are not buying art, you are buying a receipt that points to art that might not exist tomorrow.
What are you actually buying?
When you buy an NFT you get a token. The token has metadata, and the metadata usually has a link to the image:
{
"name": "Cool Art #123",
"description": "This is amazing art",
"image": "https://example.com/artwork/123.png",
"attributes": []
}That image field is just a URL. And the whole question of permanency is where that URL points.
The storage spectrum
A company server. The worst option and, right now, the most common one. Server goes down, the art goes with it. Company changes the file, your art changes. Company dies, your art dies. The blockchain will keep saying that you own token #123 of something that is not there anymore. And who do you call then? Nobody.
{ "image": "https://mycompany.com/nft-art/123.png" }IPFS. Better. The file gets an address derived from its content, a hash, so nobody can swap it for another image without changing the address. But IPFS only keeps what someone is pinning. If nobody pins it, it gets garbage collected and it is gone. It is as permanent as the people who decide to keep it alive. Big projects like Bored Ape Yacht Club point to IPFS, which is fine as long as someone keeps paying for that.
{ "image": "ipfs://QmHash..." }Arweave. Designed for permanent storage: you pay once, up front, and the network is designed to keep the data. More expensive than IPFS, and probably the best option if the art has to live off chain.
const transaction = await arweave.createTransaction({ data: artworkData });
await arweave.transactions.sign(transaction);
await arweave.transactions.post(transaction);Art Blocks, the hybrid. This one is interesting. Art Blocks stores the artist's generative script on chain, which is great: the code that creates the art is permanent. But the script depends on libraries like p5.js or three.js, and those still live on CDNs. If the library disappears, you own a script you cannot run. Even the most serious project in the space has to compromise, and that tells you how hard real permanency is.
Fully on chain. The art is generated by the contract itself. No server, no pinning, no CDN. As permanent as the chain.
Building one
Ok, hands on. The trick is that the contract returns the whole thing, metadata and image, as data, so any browser can render it. SVG is perfect for this because it is just text, and text can be built programmatically, even from on chain data.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Base64.sol";
contract OnchainArt is ERC721 {
using Strings for uint256;
uint256 public totalSupply;
constructor() ERC721("Onchain Art", "ONCHAIN") {}
function mint() public {
_mint(msg.sender, totalSupply);
totalSupply++;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
require(_exists(tokenId), "Token does not exist");
string memory svg = generateSVG(tokenId);
string memory json = Base64.encode(
bytes(
string(
abi.encodePacked(
'{"name": "Onchain Art #',
tokenId.toString(),
'", "description": "Art generated onchain", "image": "data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
'"}'
)
)
)
);
return string(abi.encodePacked("data:application/json;base64,", json));
}
function generateSVG(uint256 tokenId) public pure returns (string memory) {
uint256 seed = uint256(keccak256(abi.encodePacked(tokenId)));
return string(
abi.encodePacked(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">',
'<rect width="100" height="100" fill="', getColor(seed), '"/>',
'<circle cx="50" cy="50" r="30" fill="', getColor(seed >> 8), '"/>',
'<rect x="20" y="20" width="60" height="60" fill="', getColor(seed >> 16), '" opacity="0.5"/>',
"</svg>"
)
);
}
function getColor(uint256 seed) private pure returns (string memory) {
return string(abi.encodePacked("hsl(", (seed % 360).toString(), ", 70%, 50%)"));
}
}Every token gets its own SVG, derived from its id, built by the contract every time someone asks for it. Nothing to pin, nothing to host, nothing to lose. It costs more gas and it limits what you can draw, and that limit is part of the fun.
Why I care
The permanency problem is not theoretical. People are paying thousands for tokens whose art lives on a server nobody is obliged to keep. Before buying, the questions are simple: where is the art stored, who controls that storage, and what happens if it fails? And if you build, be honest about the answer.
But the part that really stuck with me is not the risk. It is what appears when you go fully on chain: a new language for digital art. Suddenly you have a medium where a digital work can be as permanent as a sculpture or an oil painting, maybe more, because it does not decay physically. Artworks that can be interactive, generative, connected to live data, and that persist. That, for me, is the real thing here.
This post is part of a series on NFT fundamentals. Previous: Working with Tuples in Solidity. Next: Implementing EIP-2981 Royalties.