---
# System prepended metadata

title: On-chain ml-generated NFTs

---

# On-chain ml-generated NFTs

## Generative NFTs

Generative NFTs are a class of NFTs that can be completely generated on-chain without pointing to an IPFS hash or other url for the media. Instead, a script is provided that takes some input seed and generates an image

One of the most famous examples is **[chromie squiggles](https://chromie-squiggles.com/)**

> It's an [actual script](https://chromie-squiggles.com/source-code) built into the smart contract that executes the moment the mint transaction goes through. The script takes a seed input, in the form of a hash string...which is a long hexadecimal string or "hash string" generated on the blockchain in a pseudo-random manner when the token is minted. This seed is used to control a variety of different variables in each Squiggle. Each character in this string (0-9, a-f) represents a value from 0-15 and each pair of characters ("ab", or "f2") represents a value from 0-255. For example, the y-coordinate of each point in a Squiggle is dictated by the value of a hex pair in the seed. These pairs also control the starting color, rate of change of the gradient, amount of points in each Squiggle, plus some surprise features that make some Squiggles more rare than others. With so many different variables built-in to each Squiggle and such a large number of possible seeds, you could generate new Squiggles all day and never come up with the same Squiggle. However, once a seed has been set for a token, the resulting output will always be identical and repeatable. A verifiably deterministic output.

This concept started **[Artblocks.io](https://www.artblocks.io/info/how-it-works)** which is a site for many generative nft collections created in a similar manner.

## Integrate ML

### High level
To integrate ML into this concept we would need to generate this seed that would be passed into the script. If we used some form of reinforcement algorithm, we could create some interesting tokenomics. For example:

- Users could burn generations that they don't like so that future seeds are dissimilar
- Users could pay the contract and provide an ID to a seed that they favor, such that future generations would resemble that seed.

### Technical

The model would need to fit the following requirements:
- Output a `bytes32` seed that can be used for the image generation. This would allow for a maximum of `1.157920892373162e+77` unique images.
- Input a `bytes32` seed to be added as negative or positive weight (or other piece of data from the generation of the seed?)

There are two routes we could go here:

#### **1. We create an ML model lives off-chain and provable ([ZKML](https://twitter.com/DCbuild3r/status/1628732442172612609))**
This would be the easiest way to create a "fully-fledged" model that would fit our needs. My concern here though, is that this would only really work for a fully static model and not one that could be trained based on on-chain actions? We could prove that generations are created by the AI `off-chain -> on-chain` but trustless-ly training the model `on-chain -> off-chain` may not be simple.

ZKML would allow us to verifiably prove that an output was generated from a model. Resources and code examples can be found [here](https://github.com/zkml-community/awesome-zkml).

> Note: also might get "bonus points" for using new/hyped tech

#### **2. We create a simplified model that lives on chain**

This would be quite cool to do but the main concern is the technical limitations of the EVM or FuelVM.

After some quick searching, my best guess would be that we could adapt something similar to this [code example](https://www.geeksforgeeks.org/what-is-reinforcement-learning/) on reinforcement learning, but I'm still a bit unclear on these types of algorithms and how they work exactly. 

## Randomness

We would also need some sort of randomness seed, for this we could use [Chainlink VRF](https://docs.chain.link/vrf/v2/introduction) or we could use the [Axiom]() tooling I mentioned in the call to [access Consensus Layer randomness](https://twitter.com/axiom_xyz/status/1620104730470150145?s=20).