OEP: 3
Title: Non-fungible Token Standard
Author: tanyuan <tanyuan666@gmail.com>, zhoupw <zhoupw@gmail.com>, tonyclarking<tonyclarking@gmail.com>
Type: Standard
Status: Accepted
Created: 2018-07-26
The OEP-5 Proposal is a standard interface for NFTs. This standard allows for the implementation of a standard API for NFTs within smart contracts.
A standard NFT interface which allows NFTs on the DNA blockchain to be conveniently used by other applications.
def name()
Returns a string
, the name of the NFTs - e.g. "My Non-Fungibles".
def symbol()
Returns a string
, the short symbol of the NFTs - e.g. "MNFT"
.
This symbol should be short (3-8 characters is recommended), with no whitespace characters or new-lines and should be limited to the uppercase latin alphabet (i.e. the 26 letters used in English).
def totalSupply()
Returns the total number of NFTs.
def balanceOf(address)
Returns the number of NFTs assigned to address
.
The parameter address
must be a 20-byte address.
If not, this method must throw
an exception.
def ownerOf(tokenId)
Returns the address currently marked as the owner of the NFT with id of tokenId
.
tokenId
should be string or a bytearray.
If the owner address of tokenId
can't be determined, this method must throw
an exception.
def transfer(to, tokenId)
Transfers the NFT from the owner address of tokenId
to the to
address.
tokenId
should be string or bytearray.
This method can be called by either the token owner, the approved account for the NFT with the id tokenId
or an address that has been approved to transfer all tokens for the token owner (see approvalForAll
method).
If the owner address of tokenId
can't be determined, this method must throw
an exception.
to
must be 20-byte address.
If not, this method must throw
an exception.
After a transfer, if an address had been approved by the approve
method, it should be cleared automatically.
def TransferMulti(args) state = { to: <TO ADDRESS>, tokenId: <TOKEN ID> }
The transferMulti method allows the transferring of multiple NFTs to multiple to
addresses.
The parameter is an array of objects, the object is a state
struct, which contains two items: the receiver address to
(which must be 20-byte address) and the tokenId
of the NFT.
If any of the transfers fail, all of the transfers must be failed, and the method must throw
an exception.
def approve(to, tokenId)
The approve method allows the to
address to transfer the tokenId
NFT.
If this function is called again it overwrites the to
address that can transfer the NFT.
tokenId
should be string or bytearray.
The to
address must be 20-byte address.
If not, this method must throw
an exception.
def getApproved(tokenId)
Returns the address that is allowed to send the NFT with id tokenId
.
def clearApproved(tokenId)
The clearApproved method removes the address that was set by the approve method for the NFT with the id tokenId
.
tokenId
should be string or bytearray.
This method can only be called by the token owner.
If not, this method must throw
an exception.
def approvalForAll(owner, to, approval)
The approvalForAll method grants permission to the to
address to transfer NFTs on behalf of the owner
address.
approval
should be true
to grant permission and false
to revoke permission.
The owner
and to
addresses must be 20-byte address.
If not, this method must throw
an exception.
def tokensOf(address)
Returns a serialized DynamicList
of the tokenIds of the NFTs assigned to address
.
The parameter address
must be a 20-byte address.
If not, this method must throw
an exception.
This method should return the DynamicList
of tokens in the serialized hex format.
def takeOwnership(to, tokenId)
Either the token owner or the approved account can assign the ownership of the NFT with the id tokenId
to the to
address.
tokenId
should be string or bytearray.
The parameter to
must be a 20-byte address.
If not, this method must throw
an exception.
def properties(tokenId)
Returns a serialized NVM object containing the properties for the given NFT. The NVM object must conform to the Metadata JSON Schema.
The parameter tokenId
must correspond to a valid NFT.
If not, this method must throw
an exception.
{ "title": "Asset Metadata", "type": "object", "properties": { "name": { "type": "string", "description": "Identifies the asset to which this NFT represents" }, "description": { "type": "string", "description": "Describes the asset to which this NFT represents" }, "image": { "type": "string", "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." } } }
TransferEvent = RegisterAction("transfer", "from", "to", "tokenId")
The event must be triggered when NFTs are transferred, including zero value transfers.
A token contract which creates new NFTs must trigger a transfer
event with the from
address set to null
.
A token contract which burns tokens must trigger a transfer
event with the to
address set to null
when tokens are burned.
ApprovalEvent = RegisterAction("approval", "from", "to", "tokenId")
The event must be triggered on any successful calls to approve.
OEP-5 Template: Python Template