ERC-1155 Metadata URI

The OpenZeppelin ERC-1155 Metadata URI extension is needed to manage and store URIs for individual tokens. This extension allows each token to have its own unique URI, which points to a JSON file that conforms to the ERC-1155 Metadata URI JSON Schema. This is particularly useful for non-fungible tokens (NFTs) where each token is unique and may have different metadata.

Usage

In order to make an ERC-1155 token with Metadata URI flavour, you need to add the following code to your contract:

use openzeppelin_stylus::{
    token::erc1155::{extensions::Erc1155MetadataUri, Erc1155},
    utils::introspection::erc165::IErc165,
};

#[entrypoint]
#[storage]
struct Erc1155Example {
    #[borrow]
    erc1155: Erc1155,
    #[borrow]
    metadata_uri: Erc1155MetadataUri,
}

#[public]
#[inherit(Erc1155, Erc1155MetadataUri)]
impl Erc1155Example {
    fn supports_interface(interface_id: FixedBytes<4>) -> bool {
        Erc1155::supports_interface(interface_id)
            || Erc1155MetadataUri::supports_interface(interface_id)
    }

    // ...
}

Additionally, you need to ensure proper initialization during contract deployment. Make sure to include the following code in your Solidity Constructor:

contract Erc1155Example {
    // ...

    string private _uri;

    constructor(string memory uri_) {
        // ...
        _uri = uri_;
        // ...
    }
}