cosmos-sdk/x/nft
Likhita Polavarapu ac6b19df21
refactor: x/nft audit changes (#14055)
## Description

ref: #13991 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-11-30 07:23:30 +00:00
..
client/cli refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
keeper refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
module refactor!: migrate to core appmodule.AppModule extension interfaces (#13794) 2022-11-14 21:23:55 +00:00
simulation refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
testutil docs: add docs about x/auth/tx (#14021) 2022-11-27 20:30:23 +00:00
codec.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
errors.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
event.pb.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
expected_keepers.go feat: implement nft module msg server (#10074) 2021-10-27 14:43:47 +00:00
genesis.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
genesis.pb.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
keys.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
msgs.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
nft.pb.go refactor: migrate to cosmos/gogoproto (#13070) 2022-09-08 17:27:48 +00:00
query.pb.go refactor: x/nft audit changes (#14055) 2022-11-30 07:23:30 +00:00
query.pb.gw.go fix: dockerfile for building proto (#11452) 2022-03-25 12:35:09 +00:00
README.md docs: add documentation for nft module (#13871) 2022-11-15 14:45:19 +00:00
tx.pb.go fix: fix buf commit link (#13345) 2022-09-20 21:21:45 +02:00

sidebar_position
1

x/nft

Contents

Abstract

x/nft is an implementation of a Cosmos SDK module, per ADR 43, that allows you to create nft classification, create nft, transfer nft, update nft, and support various queries by integrating the module. It is fully compatible with the ERC721 specification.

Concepts

Class

x/nft module defines a struct Class to describe the common characteristics of a class of nft, under this class, you can create a variety of nft, which is equivalent to an erc721 contract for Ethereum. The design is defined in the ADR 043.

NFT

The full name of NFT is Non-Fungible Tokens. Because of the irreplaceable nature of NFT, it means that it can be used to represent unique things. The nft implemented by this module is fully compatible with Ethereum ERC721 standard.

State

Class

Class is mainly composed of id, name, symbol, description, uri, uri_hash,data where id is the unique identifier of the class, similar to the Ethereum ERC721 contract address, the others are optional.

  • Class: 0x01 | classID | -> ProtocolBuffer(Class)

NFT

NFT is mainly composed of class_id, id, uri, uri_hash and data. Among them, class_id and id are two-tuples that identify the uniqueness of nft, uri and uri_hash is optional, which identifies the off-chain storage location of the nft, and data is an Any type. Use Any chain of x/nft modules can be customized by extending this field

  • NFT: 0x02 | classID | 0x00 | nftID |-> ProtocolBuffer(NFT)

NFTOfClassByOwner

NFTOfClassByOwner is mainly to realize the function of querying all nfts using classID and owner, without other redundant functions.

  • NFTOfClassByOwner: 0x03 | owner | 0x00 | classID | 0x00 | nftID |-> 0x01

Owner

Since there is no extra field in NFT to indicate the owner of nft, an additional key-value pair is used to save the ownership of nft. With the transfer of nft, the key-value pair is updated synchronously.

  • OwnerKey: 0x04 | classID | 0x00 | nftID |-> owner

TotalSupply

TotalSupply is responsible for tracking the number of all nfts under a certain class. Mint operation is performed under the changed class, supply increases by one, burn operation, and supply decreases by one.

  • OwnerKey: 0x05 | classID |-> totalSupply

Messages

In this section we describe the processing of messages for the NFT module.

:::warning The validation of ClassID and NftID is left to the app developer.
The SDK does not provide any validation for these fields. :::

MsgSend

You can use the MsgSend message to transfer the ownership of nft. This is a function provided by the x/nft module. Of course, you can use the Transfer method to implement your own transfer logic, but you need to pay extra attention to the transfer permissions.

The message handling should fail if:

  • provided ClassID does not exist.
  • provided Id does not exist.
  • provided Sender does not the owner of nft.

Events

The nft module emits proto events defined in the Protobuf reference.