Skip to content

A system of smart contracts deployed to Ethereum which render the pixel-art and metadata for Radioactive Punks NFTs onchain without any off-chain dependencies.

Notifications You must be signed in to change notification settings

johnnyshankman/radioactive-punks-onchain

Repository files navigation

Radioactive Punks On-Chain

The punks that survived the cryptopocalypse, now on-chain.

RPUNKS

Where To Find Them

The contracts are live on Mainnet and can be played with on Etherscan.

You may use the Radioactive Punks Operating System Website to view any punk's image and attributes stored on-chain with our PUNK LOOKUP dApp.

Screen Shot 2023-06-20 at 5 19 10 PM

Radioactive Punks can be bought on our site and on OpenSea etc.

Setting Up

# Install hardhat and dev dependencies
yarn

# Compile the contracts
yarn compile

# Run tests comparing metadata of every punk
yarn test

# Run tests and keep coverage tabs
yarn coverage

Check the package.json to see all available commands.

How do you know it's a perfect copy of the real Radioactive Punks metadata?

Every metadata JSON file's attributes are checked individually.

Every image was checked manually by eye. I will write an image checker eventually but I'd have to spin up Selenium to properly do that and I'm too lazy to do that right now.

Design

This is not an ERC-721 token, it is a ITokenURISupplier and therefore contains a tokenURI method similar to an ERC-721. It returns the on-chain metadata and image renderer for a given Radioactive Punks Token ID. We use this on the original contract for its METADATA_PROVENANCE_HASH.

Deployment is modular and split across five main components:

RadioactivePunksRenderer: responsible producing an on-chain tokenURI

RadioactivePunksBytesHyperstructure: the encoded trait data of every punk as bytes in groups of 15

RadioactivePunksSVGChunk1: gzipped SVG layer data for all punks

RadioactivePunksSVGChunk2: gzipped SVG layer data for all punks

DataCompiler: helpful functions for concatenating data into valid Data URI formats

Why no use of "SSTORE2" you may ask? Well once you fill up the entire contract with bytes or string data there is no efficiency to be gained by using SSTORE2, it actually reuquires more overhead.

How does the punk render?

The JS inflates the SVG layers and then appends them into the DOM, hidden. The JS has the encoded punk data injected into it as a string. The JS then uses that encoded data to selectively unhide the correct layers to render that punk. You now have a responsive SVG representation of your punk.

If you'd like to download your punk, right clicking anywhere on the page will trigger a 4k PNG download. It converts the SVG into a 4K PNG without any loss in quality.

What was the deployment cost?

Approximately 0.44560054 Ether for all contracts combined.

Contracts Deployed

RadioactivePunksRenderer.sol

RadioactivePunksSVGChunk1.sol

RadioactivePunksSVGChunk2.sol

RadioactivePunksSVGHyperstructure.sol

DataCompiler.sol

External Contracts

FFLate Mainnet

  1. 0xa942F946A35545F50792DA1Ea1ADf0c3b619b921
  2. 0xF10EeDb5ACE715d78e0f89eCd1Dfc3E5874f6e3c

Goerli

  1. 0x86A477028841854D9d02a5BD4fd6936216510A0f
  2. 0xB948057bdd71835b19Ff90aEa03FAd3Ebb66E870

The Results

Screen Shot 2023-06-19 at 5 42 20 PM

Getting this Data from an RPC

Here's an example of getting the data of Punk #0 from the Cloudflare Public Ethereum RPC:

curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"eth_call", "params":[{"to":"0x5694010444cC8fbbed96c23a65FbC3714F624A26", "data":"0xc87b56dd0000000000000000000000000000000000000000000000000000000000000000"},"latest"]}' https://cloudflare-eth.com/

Want to create an API that serves a chained punk or your own similar on chain ITokenURISupplier contract? Deploy a TokenURI Proxy Server using a free Heroku node and Public RPC Node!

Improvements and Oversights

  1. Had I reordered the BytesHyperstructure to use the same indexing as the original NFT contract, I could've avoided the need for the entire TOKEN_ID_TO_BYTES_LOOKUP data structure, saving quite a lot of gas on deployment.
  2. I probably could've used SSTORE2 for a few minor strings to save minor amounts of gas upon deployment of the RadioactivePunksRenderer.sol file.
  3. Maybe use EIP-681 or EIP-4804 on the original NFT contract's tokenURI though the contract haphazardly appends .json at the end of every returned URI so that may never be a feasible thing for us.

Shoutouts

This would not have been possible if I was not standing upon the shoulders of these giants:

Please support their projects, art, and personal social media accounts.

About

A system of smart contracts deployed to Ethereum which render the pixel-art and metadata for Radioactive Punks NFTs onchain without any off-chain dependencies.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published