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

feat: add NFT standard #3

Merged
merged 22 commits into from
May 20, 2021
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions sips/sips/sip-009-nft-standard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Preamble

SIP Number: 009

Title: Standard Trait Definition for Non-Fungibe Tokens
friedger marked this conversation as resolved.
Show resolved Hide resolved

Author: Friedger Müffke ([email protected])

Consideration: Technical

Type: Standard

Status: Draft

Created: 10 December 2020

License: CC0-1.0

Sign-off:

# Abstract

Non-fungible token are unique digital assets that are registered on the Stacks blockchain through a smart contract with certain properties.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Non-fungible token are unique digital assets that are registered on the Stacks blockchain through a smart contract with certain properties.
Non-fungible tokens are unique digital assets that are registered on the Stacks blockchain through a smart contract with certain properties.

Users should be able to identify a single non-fungible token. Users should be able to own it and transfer it. Non-fungible tokens can have more properties
that are not specified in this standard.

# License and Copyright

This SIP is made available under the terms of the Creative Commons CC0 1.0 Universal license, available at https://creativecommons.org/publicdomain/zero/1.0/
This SIP’s copyright is held by the Stacks Open Internet Foundation.

# Introduction

Tokens are digital assets that are registered on the Stacks blockchain through a smart contract. A non-fungible token (NFT) is a token that is globally unique and that users can identify through its identifier. The smart contract that registers the NFTs defines a name for the group of NFTs.

NFTs are enumerated, the id starts at 1 and the current last id is provided by the smart contract.

# Specification

NFT smart contract shall implement the trait defined at `ST314JC8J24YWNVAEJJHQXS5Q4S9DX1FW5Z9DK9NT.nft-trait` as well as satisfy the additional conditions.
The trait has three functions:
* `last-token-id` does not take any arguments and returns the highest number that is used as an identifier for any NFT. This is the upper limit when iterating through all NFTs.
* `get-owner` takes an NFT identifier and returns a response containing the principal owning the NFT for the given identifier. The principal is wrapped as an optional, that means if the corresponding NFT does not exists the response is `(ok none)`, otherwise, e.g. `(ok (some 'ST12...))`. The owner can be a contract principal.
* `transfer` takes an NFT identifier, a sender principal and a receiver principal. The function changes the ownership of the NFT for the given identifier. The change has to be reflected in the `get-owner` function, for details see implementation rules.

## Trait

```
(define-trait stacks-token-nft-standard-v1
(
;; Token ID, limited to uint range
(last-token-id () (response uint uint))
friedger marked this conversation as resolved.
Show resolved Hide resolved

;; Owner of given token identifier
(get-owner (uint) (response (optional principal) uint))
friedger marked this conversation as resolved.
Show resolved Hide resolved

;; Transfer from to
(transfer (uint principal principal) (response bool (tuple (kind (string-ascii 32)) (code uint))))
friedger marked this conversation as resolved.
Show resolved Hide resolved
)
)
```

## Implementation rules

1. Contracts must use a least one NFT asset. A post condition with deny mode and without any NFT condition about a changed owner must fail for `transfer` function calls.
friedger marked this conversation as resolved.
Show resolved Hide resolved
1. After a successful call to function `transfer` the function `get-owner` must return the recipient of the `transfer` call as the new owner.
1. If a call to function `get-owner` returns some principal `A` value then it must return the same value until `transfer` is called with principal `A` as a sender
1. For any call to `get-owner`, resp. `transfer` with an id greater than `last-token-id`, the call should return a response `none`, resp. failed transfer.
1. The following error codes are defined

| function | error | description |
|----------|-------|-------------|
|`transfer`|`{kind: "nft-transfer-failed", code: from-nft-transfer}`| Error if the call failed due to the underlying asset transfer. The code `from-nft-transfer` is the error code from the native asset transfer function|

# Related Work

https://eips.ethereum.org/EIPS/eip-721
friedger marked this conversation as resolved.
Show resolved Hide resolved
https://www.ledger.com/academy/what-are-nft

# Backwards Compatibility

Not applicable

# Activation

This SIP is activated if 5 contracts are deployed that are using the same trait that follows this specification. This has to happen before Stacks tip #5000.
friedger marked this conversation as resolved.
Show resolved Hide resolved

# Reference Implementations

Source code
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Source code
## Friedger's clarity-smart-contracts

https://github.com/friedger/clarity-smart-contracts/blob/master/contracts/sips/nft-trait.clar

Deployment on testnet: TODO