Skip to content

IggyPostMetadata.sol

Tempe Techie edited this page Jun 17, 2023 · 1 revision

IggyPostMetadata.sol

The IggyPostMetadata contract is a smart contract that generates metadata for a Post NFT. It provides functions to retrieve metadata associated with a specific token ID and generate SVG image data for the NFT.

Contract Variables

  • tldAddress (public immutable address): The address of the TLD (Top-Level Domain) contract used to fetch the default names of authors (the .op domain smart contract address).
  • description (public string): The description of the Post NFT.
  • name (public string): The name of the Post NFT.
  • url (public string): Base URL for a post on Opti Social (https://opti.social/post/).

Events

The contract emits the following events:

  • DescriptionChanged(address indexed user, string description): Fired when the description of the NFT is changed.
  • NameChanged(address indexed user, string name): Fired when the name of the NFT is changed.

Public and External Functions

getMetadata()

function getMetadata(
    uint256 _tokenId,
    string calldata _postId,
    address _author,
    string calldata _textPreview,
    uint256 _timestamp
) public view returns (string memory)

Note that the getMetadata() function is called by the tokenURI() function in the IggyPostNft1155 smart contract. So no need to call the getMetadata() function directly from the frontend. Always do it through the tokenURI() function.

This function returns the metadata associated with a specific token ID in the form of a JSON string. It takes the following parameters:

  • _tokenId: The ID of the token.
  • _postId: The ID of the post associated with the token.
  • _author: The address of the author of the post.
  • _textPreview: The preview text of the post (only the first e.g. 140 chars).
  • _timestamp: The timestamp when the first post NFT of this ID was minted.

Other read functions are for internal contract purposes.

Owner-only Functions

The following functions can only be called by the contract owner.

changeName(string calldata _name)

function changeName(string calldata _name) external onlyOwner

This function allows the contract owner to change the name of the NFT. It takes a new name as a parameter.

changeDescription(string calldata _description)

function changeDescription(string calldata _description) external onlyOwner

This function allows the contract owner to change the description of the NFT. It takes a new description as a parameter.

changeUrl(string calldata _url)

function changeUrl(string calldata _url) external onlyOwner

This function allows the contract owner to change the base URL associated with the NFT. It takes a new URL as a parameter.