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

Add: cw721-non-transferable-with-metadata-onchain #154

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
28 changes: 28 additions & 0 deletions contracts/cw721-non-transferable-with-metadata-onchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "cw721-non-transferable-with-metadata-onchain"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]


[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
cw721 = { workspace = true }
cw721-base = { workspace = true, features = ["library"] }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
cw-utils = { workspace = true }
cw-ownable = { workspace = true }
54 changes: 54 additions & 0 deletions contracts/cw721-non-transferable-with-metadata-onchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CosmWasm Non-Transferable NFT with Onchain Metadata
A Non-Transferable NFT implementation by extending [`cw721-base`](https://github.com/CosmWasm/cw-nfts/tree/main/contracts/cw721-base) and using [`cw_ownable`](https://github.com/larry0x/cw-plus-plus/tree/main/packages/ownable) functions:

```rust
initialize_owner(deps.storage, deps.api, msg.admin.as_deref())?;
```

and

```rust
get_ownership(deps.storage)?.owner;
```
to check only contract owner can execute with the additional feature of onchain metadata:

```rust
#[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>;
```

This simplifies the json schema as it can be written now:

```rust
use cosmwasm_schema::write_api;

use nft::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
```
which was more complex in the [`cw721-non-transferable`](https://github.com/CosmWasm/cw-nfts/tree/main/contracts/cw721-non-transferable).
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;

use cw721_non_transferable_with_metadata_onchain::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}