Core Contract
Last updated
Last updated
This documentation is for a prototype contract and the specifications may be updated.
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:
You can also interact with the contract using our Frontend Application (DApp) which is available at SuperPiccellCore DApp.
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 or manually adding it from the settings menu.
PC: MetaMask, Trust Wallet, Coinbase Wallet
Smartphone: MetaMask
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.
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.
This contract can receive and send out Ether and ERC20 tokens. Token transfers can only be performed by the owner of the contract.
withdrawToken
Allows the owner to withdraw ERC20 tokens accidentally sent to the contract.
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.
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:
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.
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.