Skip to content

Latest commit

 

History

History
512 lines (386 loc) · 16.7 KB

ERC721.md

File metadata and controls

512 lines (386 loc) · 16.7 KB

ERC721 Non-Fungible Token Standard basic implementation (ERC721.sol)

View Source: contracts/token/ERC721/ERC721.sol

↗ Extends: ERC165, IERC721 ↘ Derived Contracts: ERC721Burnable, ERC721Enumerable, ERC721Full, ERC721Metadata, ERC721MetadataMintable, ERC721Mintable, ERC721Mock, ERC721Pausable

ERC721

see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md

Contract Members

Constants & Variables

bytes4 private constant _ERC721_RECEIVED;
mapping(uint256 => address) private _tokenOwner;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => uint256) private _ownedTokensCount;
mapping(address => mapping(address => bool)) private _operatorApprovals;
bytes4 private constant _InterfaceId_ERC721;

Functions

balanceOf

⤾ overrides IERC721.balanceOf

Gets the balance of the specified address

function balanceOf(address owner) public
returns(uint256)

Returns

uint256 representing the amount owned by the passed address

Arguments

Name Type Description
owner address address to query the balance of

ownerOf

⤾ overrides IERC721.ownerOf

Gets the owner of the specified token ID

function ownerOf(uint256 tokenId) public
returns(address)

Returns

owner address currently marked as the owner of the given token ID

Arguments

Name Type Description
tokenId uint256 uint256 ID of the token to query the owner of

approve

⤾ overrides IERC721.approve

⤿ Overridden Implementation(s): ERC721Pausable.approve

Approves another address to transfer the given token ID The zero address indicates there is no approved address. There can only be one approved address per token at a given time. Can only be called by the token owner or an approved operator.

function approve(address to, uint256 tokenId) public undefined

Arguments

Name Type Description
to address address to be approved for the given token ID
tokenId uint256 uint256 ID of the token to be approved

getApproved

⤾ overrides IERC721.getApproved

Gets the approved address for a token ID, or zero if no address set Reverts if the token ID does not exist.

function getApproved(uint256 tokenId) public
returns(address)

Returns

address currently approved for the given token ID

Arguments

Name Type Description
tokenId uint256 uint256 ID of the token to query the approval of

setApprovalForAll

⤾ overrides IERC721.setApprovalForAll

⤿ Overridden Implementation(s): ERC721Pausable.setApprovalForAll

Sets or unsets the approval of a given operator An operator is allowed to transfer all tokens of the sender on their behalf

function setApprovalForAll(address to, bool approved) public undefined

Arguments

Name Type Description
to address operator address to set the approval
approved bool representing the status of the approval to be set

isApprovedForAll

⤾ overrides IERC721.isApprovedForAll

Tells whether an operator is approved by a given owner

function isApprovedForAll(address owner, address operator) public
returns(bool)

Returns

bool whether the given operator is approved by the given owner

Arguments

Name Type Description
owner address owner address which you want to query the approval of
operator address operator address which you want to query the approval of

transferFrom

⤾ overrides IERC721.transferFrom

⤿ Overridden Implementation(s): ERC721Pausable.transferFrom

Transfers the ownership of a given token ID to another address Usage of this method is discouraged, use safeTransferFrom whenever possible Requires the msg sender to be the owner, approved, or operator

function transferFrom(address from, address to, uint256 tokenId) public undefined

Arguments

Name Type Description
from address current owner of the token
to address address to receive the ownership of the given token ID
tokenId uint256 uint256 ID of the token to be transferred

safeTransferFrom

⤾ overrides IERC721.safeTransferFrom

Safely transfers the ownership of a given token ID to another address If the target address is a contract, it must implement onERC721Received, which is called upon a safe transfer, and return the magic value bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); otherwise, the transfer is reverted.

  • Requires the msg sender to be the owner, approved, or operator
function safeTransferFrom(address from, address to, uint256 tokenId) public undefined

Arguments

Name Type Description
from address current owner of the token
to address address to receive the ownership of the given token ID
tokenId uint256 uint256 ID of the token to be transferred

safeTransferFrom

⤾ overrides IERC721.safeTransferFrom

Safely transfers the ownership of a given token ID to another address If the target address is a contract, it must implement onERC721Received, which is called upon a safe transfer, and return the magic value bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); otherwise, the transfer is reverted. Requires the msg sender to be the owner, approved, or operator

function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public undefined

Arguments

Name Type Description
from address current owner of the token
to address address to receive the ownership of the given token ID
tokenId uint256 uint256 ID of the token to be transferred
_data bytes bytes data to send along with a safe transfer check

_exists

Returns whether the specified token exists

function _exists(uint256 tokenId) internal
returns(bool)

Returns

whether the token exists

Arguments

Name Type Description
tokenId uint256 uint256 ID of the token to query the existence of

_isApprovedOrOwner

Returns whether the given spender can transfer a given token ID

function _isApprovedOrOwner(address spender, uint256 tokenId) internal
returns(bool)

Returns

bool whether the msg.sender is approved for the given token ID, is an operator of the owner, or is the owner of the token

Arguments

Name Type Description
spender address address of the spender to query
tokenId uint256 uint256 ID of the token to be transferred

_mint

⤿ Overridden Implementation(s): ERC721Enumerable._mint

Internal function to mint a new token Reverts if the given token ID already exists

function _mint(address to, uint256 tokenId) internal undefined

Arguments

Name Type Description
to address The address that will own the minted token
tokenId uint256 uint256 ID of the token to be minted by the msg.sender

_burn

⤿ Overridden Implementation(s): ERC721Enumerable._burn,ERC721Metadata._burn

Internal function to burn a specific token Reverts if the token does not exist

function _burn(address owner, uint256 tokenId) internal undefined

Arguments

Name Type Description
owner address
tokenId uint256 uint256 ID of the token being burned by the msg.sender

_addTokenTo

⤿ Overridden Implementation(s): ERC721Enumerable._addTokenTo

Internal function to add a token ID to the list of a given address Note that this function is left internal to make ERC721Enumerable possible, but is not intended to be called by custom derived contracts: in particular, it emits no Transfer event.

function _addTokenTo(address to, uint256 tokenId) internal undefined

Arguments

Name Type Description
to address address representing the new owner of the given token ID
tokenId uint256 uint256 ID of the token to be added to the tokens list of the given address

_removeTokenFrom

⤿ Overridden Implementation(s): ERC721Enumerable._removeTokenFrom

Internal function to remove a token ID from the list of a given address Note that this function is left internal to make ERC721Enumerable possible, but is not intended to be called by custom derived contracts: in particular, it emits no Transfer event, and doesn't clear approvals.

function _removeTokenFrom(address from, uint256 tokenId) internal undefined

Arguments

Name Type Description
from address address representing the previous owner of the given token ID
tokenId uint256 uint256 ID of the token to be removed from the tokens list of the given address

_checkOnERC721Received

Internal function to invoke onERC721Received on a target address The call is not executed if the target address is not a contract

function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes _data) internal undefined
returns(bool)

Returns

whether the call correctly returned the expected magic value

Arguments

Name Type Description
from address address representing the previous owner of the given token ID
to address target address that will receive the tokens
tokenId uint256 uint256 ID of the token to be transferred
_data bytes bytes optional data to send along with the call

_clearApproval

Private function to clear current approval of a given token ID Reverts if the given address is not indeed the owner of the token

function _clearApproval(address owner, uint256 tokenId) private undefined

Arguments

Name Type Description
owner address owner of the token
tokenId uint256 uint256 ID of the token to be transferred

Contracts