Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NFTs to include custom data #440

Closed
ethanfrey opened this issue Sep 20, 2021 · 4 comments
Closed

Allow NFTs to include custom data #440

ethanfrey opened this issue Sep 20, 2021 · 4 comments
Assignees
Milestone

Comments

@ethanfrey
Copy link
Member

A first step on #391

A few people have tried to build on cw721-base but want to add extra metadata to the contract and cannot extend it. Basically, we would need:

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct TokenInfo<T> {
    /// The owner of the newly minted NFT
    pub owner: Addr,
    /// Approvals are stored here, as we clear them all upon transfer and cannot accumulate much
    pub approvals: Vec<Approval>,

    /// Identifies the asset to which this NFT represents
    pub name: String,
    /// Describes the asset to which this NFT represents
    pub description: String,
    /// A URI pointing to an image representing the asset
    pub image: Option<String>,

    pub extension: Option<T>,
}

(source)

The default implementation can simply leave extension: None. (Or use extension: Empty, removing the Option).

This can be done and then we make all query and execute methods accept this T. However, when thinking about it, it would be a great first example of using a struct to represent a contract, as described in #391

@ethanfrey ethanfrey added this to the v0.10.0 milestone Sep 20, 2021
@ethanfrey ethanfrey changed the title All NFTs to include custom data Allow NFTs to include custom data Sep 20, 2021
@hashedone
Copy link
Contributor

I am not sure if it is worth it for now waiting for #391 - I am doing some things around this after hours, but for now I don't put time on this unless we are agreed on this idea. Adding generic extension is relatively small change and it can be done in current environment (I am not sure how important is it).

One thing I would change here - make extension just T and leave it to the user to decide if it is optional (T may always be an option itself), making it Empty by default.

@ethanfrey
Copy link
Member Author

One thing I would change here - make extension just T and leave it to the user to decide if it is optional (T may always be an option itself), making it Empty by default.

Sounds good to use T.
Making it Option<Empty> by default is nice, so it is compatible with current serialised data that don't have that field.

@ethanfrey
Copy link
Member Author

I wouldn't wait until #391 but do some refactoring here to start sketching out what #391 (after code-gen) could look like on a concrete use-case.

@ethanfrey ethanfrey self-assigned this Sep 21, 2021
This was referenced Sep 21, 2021
@ethanfrey
Copy link
Member Author

Closed by #445

Example in #450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants