# Core Contract

## SuperPiccellCore Contract

{% hint style="danger" %}
This documentation is for a prototype contract and the specifications may be updated.
{% endhint %}

### Overview

The `SuperPiccellCore` contract is a smart contract on the Ethereum blockchain that is designed to store various types of content in a decentralized manner. The content is categorized into six types: Character, Episode, Event, Item, Location, and Organization. Each piece of content has a unique ID and includes metadata such as encoding, content type, and revision. Please note that this is a prototype contract and is currently deployed on the Sepolia testnet, a development environment for Ethereum, and is subject to change in the future.

You can view the contract on the Sepolia testnet at the following links:

* [SuperPiccellCore Contract GitHub repository](https://github.com/dev-muhus/superpiccell-core-contract)
* [SuperPiccellCore Contract on Sepolia Etherscan](https://sepolia.etherscan.io/address/0x8160583444A49e869DB9E627eFCA281c8dC71B4e#code)

You can also interact with the contract using our Frontend Application (DApp) which is available at [SuperPiccellCore DApp](https://superpiccell-core-contract.vercel.app/).

#### Frontend Application (DApp)

<figure><img src="https://3709285822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF65NVadFITGjqcUB9079%2Fuploads%2Fj07e9SOi9wLPzyRThOm4%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202024-09-13%2014.12.16.png?alt=media&#x26;token=38efe272-51d6-489e-9fb6-66d9081a2f35" alt=""><figcaption></figcaption></figure>

The frontend application (DApp) provides a user-friendly interface for interacting with the `SuperPiccellCore` contract. The DApp allows you to view all the contents stored in the contract in a more intuitive way compared to direct interaction with the blockchain. The DApp is built using the React JavaScript library and connects to the Ethereum blockchain using the ethers.js library.

To interact with the DApp, you will need a browser extension like MetaMask that allows your browser to connect to the Ethereum blockchain. Furthermore, you will need to switch your MetaMask network to the Sepolia network. You can add the Sepolia network to MetaMask by using [chainlist](https://chainlist.org/chain/11155111) or manually adding it from the settings menu.

<div align="left"><figure><img src="https://3709285822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF65NVadFITGjqcUB9079%2Fuploads%2FHq1sNeDufKtLOKO0HJJG%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202023-08-04%2014.14.56.png?alt=media&#x26;token=627bcde1-ce13-4eb1-b3ef-bc1782308ca0" alt=""><figcaption></figcaption></figure></div>

#### Environment Requirements for the DApp

* PC: MetaMask, Trust Wallet, Coinbase Wallet
* Smartphone: MetaMask

### Features

| Function Name            | Description                                                                                                                           |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| createContent            | Creates new content. This function can only be called by the owner of the contract. Protected content or contract cannot be modified. |
| updateContent            | pdates existing content. This function can only be called by the owner of the contract. It cannot update protected content.           |
| deleteContent            | Deletes content. This function can only be called by the owner of the contract. It cannot delete protected content.                   |
| getContent               | Gets the content with the specified ID.                                                                                               |
| getAllContents           | Gets all contents.                                                                                                                    |
| getContentsByContentType | Gets all contents that match the specified content type.                                                                              |
| isContentProtected       | Returns whether the content with the specified ID is protected or not.                                                                |

### Security Features

| Function Name       | Description                                                                                                                                                                            |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| protectContract     | Calling this function puts the contract into protection mode, preventing the creation, update, and deletion of content. This function can only be called by the owner of the contract. |
| protectContent      | Marks specific content as protected, which prevents further updates or deletions of the content.                                                                                       |
| isContractProtected | Returns whether the contract is in protection mode.                                                                                                                                    |

### Token Transfers

This contract can receive and send out Ether and ERC20 tokens. Token transfers can only be performed by the owner of the contract.

| Function Name	 | Description                                                                  |
| -------------- | ---------------------------------------------------------------------------- |
| withdrawToken  | Allows the owner to withdraw ERC20 tokens accidentally sent to the contract. |

### Data Structure of Contents

Each piece of content stored in the contract is represented as an instance of the `Content` struct. The `Content` struct has the following fields:

* `id (uint256)`: The unique identifier for the content. This ID is unique across all types of content.
* `exists (bool)`: A flag indicating whether the content exists. This is used internally by the contract.
* `encoding (string)`: The encoding of the content. Typically, this will be "UTF-8".
* `contentType (string)`: The type of the content. This could be one of "Character", "Episode", "Event", "Item", "Location", or "Organization".
* `content (string)`: This field contains the content data. The content is stored as a string. This string is a JSON string that encodes the content object.
* `revision (string)`: The revision of the content. This is typically set to "Genesis" when the content is first created.
* `createdAt (uint256)`: The timestamp (in seconds since the Unix epoch) when the content was created.
* `createdBy (address)`: The address of the user who created the content.
* `updatedAt (uint256)`: The timestamp (in seconds since the Unix epoch) when the content was last updated.
* `updatedBy (address)`: The address of the user who last updated the content.

You can retrieve the content with a specific ID by calling the `getContent` function and passing the ID as the argument.

### Content Formats

In the `SuperPiccellCore` contract, the `content` field is a string that stores a JSON-encoded content object. The structure of the content object depends on the `contentType`. Here are the formats for each content type:

#### Character

```json
{
    "name": "Kent",
    "full_name": "Kent Sawamura",
    "alias": "The Beard Daddy",
    "headline": "Kent is the father of the main character Maya and husband of Lisa.",
    "gender": "Male",
    "age": 35,
    "nationality": "Japan",
    "breed": null,
    "occupation": "System engineer",
    "favorite_food": "Eel, Soba, Tempura",
    "favorite_game": "Retro games from the 1990s, Bare Knuckle (Streets of Rage) - Mega Drive (GENESIS)",
    "personality": "Serious and clumsy",
    "admire": "Ian MacKaye",
    "description": "Kent is Maya's father and Lisa's husband. He is an old geek who loves 1980s and 1990s pop culture and punk rock. He loved early HardCorePunk and was an avid fan of Straight Edge when he was younger. He is usually an average systems engineer. He works for Halliday Technologies, a subsidiary of OIO, where he primarily maintains \"Dapp\", which has become an obsolete technology. His mother died of an incurable illness during his childhood and his father disappeared."
}
```

#### Episode

```json
{
    "episode_number": 1,
    "title": "The Beginning of Adventure",
    "subtitle": "Prologue",
    "content": [
        "There exists a star, blossoming with advanced civilization, located at the far reaches of the universe. The inhabitants of this star have been passionately engaged in the development of science and technology, relishing its fruits, since they passed a turning point called the Singularity over half a century ago.",
        "The virtual reality space \"Metaverse\" now comprises not just a part of people's lives, but the majority of it. Aside from time spent sleeping and eating, people spend most of their time in the Metaverse. Here, they work and enjoy traveling, hold music concerts, and experience love. The Metaverse mimics all aspects of the real world and sometimes even offers experiences that transcend it."
    ]
}
```

#### Event

```json
{
    "year": 2006,
    "event": [
        "Birth of Haraboji."
    ],
    "note": null
}
```

#### Item

```json
{
    "name": "Super Piccell Protocol",
    "alias": "SPP",
    "headline": "Super Piccell Protocol",
    "developer": "OIO (Kai Sawamura)",
    "release_year": 2067,
    "owner": "MMC (Multi-Metaverse Council)",
    "description": "Super Piccell Protocol is a large-volume encrypted data ultra-high-speed transfer protocol developed by OIO co-founder \"Kai Sawamura\". After Kai's disappearance, Dr. Dyson took over this development project and released it. By introducing this protocol into MVCE (Multi-Verse Connect Engine), seamless transfer of large-volume cryptographic data in multi-metaverse becomes possible. In addition, when used in conjunction with MD (Material Digitizer), it will be possible to digitize materials and transfer them to the metaverse for use."
}
```

#### Location

```json
{
    "name": "Sawamura House",
    "alias": "Maya's House",
    "headline": null,
    "address": "Hyakunincho, Shinjuku-ku, Tokyo",
    "description": "This is the house where Maya, Kent and Lisa live. It is a rented house and the landlord is Haraboji.",
    "note": null
}
```

#### Organization

```json
{
    "name": "Object Inovative Online",
    "alias": "OIO",
    "headline": "Object Inovative Online",
    "founder": "Kai Sawamura, Miles Dyson",
    "year_founded": 2057,
    "number_of_members": 52534,
    "representative": "Owen Bryant",
    "description": "OIO is a tech company founded by Kai and Dr. Dyson in their youth. The organization is currently headed by Bryant, who is also the MMC Supreme Chairman. It is one of the world's leading tech companies with the development of \"Multi-Verse Connect Engine\" and \"Material Digitizer\".",
    "note": null
}
```

{% hint style="warning" %}
In the actual contract, the **content** field is a string that contains a JSON string representing the content object. These examples are presented as objects for clarity, but when you interact with the contract, you will need to encode these objects as JSON strings before saving them to the contract, and decode them back into objects after retrieving them.

This means that when you get the **content** data from the contract, it will be a JSON string. You will need to parse this string into a JavaScript object (or the equivalent in your programming language) in order to interact with the content data. For example, in JavaScript, you would use **JSON.parse(contentString)** to convert the JSON string into an object.

Similarly, before saving content to the contract, you will need to convert your content object into a JSON string. In JavaScript, you would use **JSON.stringify(contentObject)** to do this.

Remember to always handle the **content** data as a JSON string when interacting with the **SuperPiccellCore** contract directly.
{% endhint %}

{% hint style="warning" %}
Although in theory it's possible to store any form of data in the **content** field, including images that have been converted to a base64 string, due to the high gas costs associated with storing large amounts of data on the blockchain, it is recommended to only store text-based content. Attempting to store large images or other forms of large data can lead to extremely high transaction costs. Therefore, the **SuperPiccellCore** contract is primarily designed to store text-based contents.
{% endhint %}
