cw721-metadata-onchain

Crates.iocw721-metadata-onchain
lib.rscw721-metadata-onchain
version0.15.0
sourcesrc
created_at2021-10-14 10:15:06.527431
updated_at2022-09-16 07:58:47.25606
descriptionExample extending CW721 NFT to store metadata on chain
homepagehttps://cosmwasm.com
repositoryhttps://github.com/CosmWasm/cw-nfts
max_upload_size
id464862
size73,693
Core Rust Developers (github:cosmwasm:core-rust-developers)

documentation

https://docs.cosmwasm.com

README

CW721 Metadata Onchain

NFT creators may want to store their NFT metadata on-chain so other contracts are able to interact with it. With CW721-Base in CosmWasm, we allow you to store any data on chain you wish, using a generic extension: T.

In order to support on-chain metadata, and to demonstrate how to use the extension ability, we have created this simple contract. There is no business logic here, but looking at lib.rs will show you how do define custom data that is included when minting and available in all queries.

In particular, here we define:

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Trait {
    pub display_type: Option<String>,
    pub trait_type: String,
    pub value: String,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Metadata {
    pub image: Option<String>,
    pub image_data: Option<String>,
    pub external_url: Option<String>,
    pub description: Option<String>,
    pub name: Option<String>,
    pub attributes: Option<Vec<Trait>>,
    pub background_color: Option<String>,
    pub animation_url: Option<String>,
    pub youtube_url: Option<String>,
}

pub type Extension = Option<Metadata>;

In particular, the fields defined conform to the properties supported in the OpenSea Metadata Standard.

This means when you query NftInfo{name: "Enterprise"}, you will get something like:

{
  "name": "Enterprise",
  "token_uri": "https://starships.example.com/Starship/Enterprise.json",
  "extension": {
    "image": null,
    "image_data": null,
    "external_url": null,
    "description": "Spaceship with Warp Drive",
    "name": "Starship USS Enterprise",
    "attributes": null,
    "background_color": null,
    "animation_url": null,
    "youtube_url": null
  }
}

Please look at the test code for an example usage in Rust.

Notice

Feel free to use this contract out of the box, or as inspiration for further customization of cw721-base. We will not be adding new features or business logic here.

Commit count: 278

cargo fmt