public-awesome / cw-nfts

Examples and helpers to build NFT contracts on CosmWasm
Apache License 2.0
188 stars 180 forks source link

`cw721-expiration` contract with `invalid NFT` utility #140

Closed taitruong closed 10 months ago

taitruong commented 11 months ago

README.md:

CW721 Expiration

One typical use cases for an cw721-expiration contract is providing services for a limited period, like access cards, SLAs, cloud services, etc. Also check kudos below.

This contract enables the creation of NFTs that expire after a predetermined number of days. The expiration_days is set during instantiation of contract. Expiration timestamp is: mint timestamp + expiration days.

Custom cw721-base Contract

Query Messages

This contract extends cw721-base by adding a new invalid NFT utility. The following cw721-base query messages have been extended with an optional include_invalid property:

In case NFT is invalid (due to expiration) an error is thrown or filtered out. Above queries for including invalid NFTs must explicitly pass include_invalid: Some(true) (in all other cases (None, Some(false)) invalid NFTs are excluded).

Execute Messages

Execute messages are kept unchanged, but during execution an error is thrown for invalid NFTs for these operations:

Instantiation

To instantiate a new instance of this contract you must specify expiration_days - along with cw721-based properties: owner (aka minter), name, and symbol.

taitruong commented 11 months ago

Kudos to timpi for requesting this kind of NFTs, allowing NFT holders running nodes for a limited period.

taitruong commented 11 months ago

Some side notes to be addressed in other tasks. Mainly most of the code was simply copy-pasted from cw721-base. Imo this shows cw721-base is not modular/generic enough for custom c721-contracts. My suggestions:

Imo, by doing so, building custom, extended cw721 contracts get much faster done and better, with less/no copy paste code.

taitruong commented 10 months ago

@taitruong LGTM! Mind fixing the one linting error?

Done. Also fixes #141