> For the complete documentation index, see [llms.txt](https://moonsters-nfts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moonsters-nfts.gitbook.io/docs/smart-contracts/onchain-workflow.md).

# Onchain Workflow

The [<mark style="color:green;">**Moonsters**</mark>](https://moonsters-nfts.gitbook.io/docs/moonsters/introduction.md) ecosystem operates through a set of interconnected contracts that ensure all actions are verifiable on the blockchain.

## **📌 Key Steps in the Moonsters Ecosystem**

{% stepper %}
{% step %}

### **Egg Purchase**

* The user purchases an egg by interacting with <mark style="color:purple;">**EggUtilities.sol**</mark>.
* This contract **validates** the transaction and **assigns** a rarity to the egg.
* Then, it **sends** the data to <mark style="color:purple;">**EggCollection.sol**</mark>, which **mints** the egg NFT on the blockchain.
* A portion of the payment is redirected to **MoonVault.sol** for reward distribution.
  {% endstep %}

{% step %}

### **Egg Hatching**

* The user interacts with <mark style="color:purple;">**EggUtilities.sol**</mark> to **hatch** an egg.
* The contract **calculates** the Moonster's rarity and attributes.
* Then, it **sends** this data to <mark style="color:purple;">**MoonsterCollection.sol**</mark>, which **mints** the new Moonster NFT on the blockchain.
* Metadata is also generated in real-time through <mark style="color:purple;">**MoonsterMetadata.sol**</mark>.
  {% endstep %}

{% step %}

### **Leveling Up**

* The user **feeds** their Moonster using <mark style="color:blue;">**$SDUST**</mark> through <mark style="color:purple;">**MoonsterUtilities.sol**</mark>.
* The contract **increases** the Moonster’s **level progress** bar.
* When the bar is full, <mark style="color:purple;">**MoonsterCollection.sol**</mark> **updates** the NFT with the new level.
* This directly **impacts** <mark style="color:blue;">**MoonVault**</mark>, **increasing** its weight in rewards.
  {% endstep %}

{% step %}

### **Moonster Evolution**

* The user **fuses** two identical Moonsters through <mark style="color:purple;">**MoonsterUtilities.sol**</mark>.
* The contract **validates** the evolution and **sends** the update to <mark style="color:purple;">**MoonsterCollection.sol**</mark>.
* The Moonster’s attributes, metadata, and **impact** on **MoonVault** are recalculated.
  {% endstep %}

{% step %}

### **MoonVault & Rewards**

* Each Moonster automatically **generates** points within the <mark style="color:purple;">**MoonVault.sol**</mark> reward system.
* The user can **claim** their rewards when the distribution cycle ends.
  {% endstep %}
  {% endstepper %}

<figure><img src="https://3941680481-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiIN1ANgu4kjZAjk0auKi%2Fuploads%2Fl91ZPuWg2E1V5QX6swzO%2FMoonsters.drawio%20(5).png?alt=media&amp;token=8d3fa94a-67dd-47d6-83e9-6407405b568e" alt=""><figcaption><p>Flowchart</p></figcaption></figure>
