Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Contracts

This page provides detailed documentation for each contract in the magical-nft template.

Main Contract

File: contracts/{{ProjectName}}.sol

The main contract is an ERC721 implementation that serves as the entry point for your NFT.

Key Functions

function mint(address to) external payable

Mints a new token to the specified address.

function tokenURI(uint256 tokenId) public view returns (string memory)

Returns the metadata URI for a token, delegating to the renderer.

function setRenderer(address newRenderer) external onlyOwner

Updates the renderer contract address.

Inheritance

  • ERC721 - OpenZeppelin's ERC721 implementation
  • Ownable - Access control for owner-only functions

Renderer Contract

File: contracts/{{ProjectName}}Renderer.sol

Handles all metadata and HTML generation.

Key Functions

function tokenURI() external view returns (string memory)

Generates the complete token metadata JSON (delegates to generateMetadata()).

function setStorageAddress(address _storageAddress) external onlyOwner

Updates the storage contract address.

Internal Functions

The renderer uses these private functions internally:

  • generateMetadata() - Builds the JSON metadata with animation_url and image
  • generateHTML() - Assembles HTML from stored files (start.html, CSS, JS, end.html)
  • encodeMetadataJSON() - Encodes metadata as base64 data URI

Storage Contract

File: contracts/{{ProjectName}}Storage.sol

Manages onchain storage of assets using SSTORE2.

Key Functions

function store(string calldata key, bytes calldata data) external onlyOwner

Stores data with a given key.

function read(string calldata key) external view returns (bytes memory)

Reads data associated with a key.

function getPointer(string calldata key) external view returns (address)

Returns the SSTORE2 pointer for a key.

SSTORE2

SSTORE2 stores data as contract bytecode, which is:

  • Cheaper to write - Uses CREATE instead of SSTORE
  • Cheaper to read - Uses EXTCODECOPY instead of SLOAD
  • Immutable - Once stored, data cannot be modified

EthDrive

File: contracts/EthDrive.sol

A utility contract for managing file uploads and organization.

SSTORE2

File: contracts/SSTORE2.sol

The SSTORE2 library implementation for efficient onchain storage.