Skip to main content

ERC721Base

The ERC721Base smart contract implements the ERC721 NFT standard, along with the ERC721A optimization to the standard. It includes the following additions to standard ERC721 logic: - Ability to mint NFTs via the provided mint function. - Contract metadata for royalty support on platforms such as OpenSea that use off-chain information to distribute roaylties. - Ownership of the contract, with the ability to restrict certain functions to only be called by the contract's owner. - Multicall capability to perform multiple actions atomically - EIP 2981 compliance for royalty support on NFT marketplaces.

Methods

approve

function approve(address to, uint256 tokenId) external nonpayable

See {IERC721-approve}.

Parameters

NameTypeDescription
toaddressundefined
tokenIduint256undefined

balanceOf

function balanceOf(address owner) external view returns (uint256)

See {IERC721-balanceOf}.

Parameters

NameTypeDescription
owneraddressundefined

Returns

NameTypeDescription
_0uint256undefined

batchMintTo

function batchMintTo(address _to, uint256 _quantity, string _baseURI, bytes _data) external nonpayable

Lets an authorized address mint multiple NFTs at once to a recipient.

The logic in the _canMint function determines whether the caller is authorized to mint NFTs.

Parameters

NameTypeDescription
_toaddressThe recipient of the NFT to mint.
_quantityuint256The number of NFTs to mint.
_baseURIstringThe baseURI for the n number of NFTs minted. The metadata for each NFT is baseURI/tokenId
_databytesAdditional data to pass along during the minting of the NFT.

burn

function burn(uint256 _tokenId) external nonpayable

Lets an owner or approved operator burn the NFT of the given tokenId.

ERC721A's _burn(uint256,bool) internally checks for token approvals.

Parameters

NameTypeDescription
_tokenIduint256The tokenId of the NFT to burn.

contractURI

function contractURI() external view returns (string)

Returns the contract metadata URI.

Returns

NameTypeDescription
_0stringundefined

getApproved

function getApproved(uint256 tokenId) external view returns (address)

See {IERC721-getApproved}.

Parameters

NameTypeDescription
tokenIduint256undefined

Returns

NameTypeDescription
_0addressundefined

getBaseURICount

function getBaseURICount() external view returns (uint256)

Returns the count of batches of NFTs.

Each batch of tokens has an in ID and an associated baseURI. See {batchIds}.

Returns

NameTypeDescription
_0uint256undefined

getBatchIdAtIndex

function getBatchIdAtIndex(uint256 _index) external view returns (uint256)

Returns the ID for the batch of tokens the given tokenId belongs to.

See {getBaseURICount}.

Parameters

NameTypeDescription
_indexuint256ID of a token.

Returns

NameTypeDescription
_0uint256undefined

getDefaultRoyaltyInfo

function getDefaultRoyaltyInfo() external view returns (address, uint16)

Returns the defualt royalty recipient and BPS for this contract's NFTs.

Returns

NameTypeDescription
_0addressundefined
_1uint16undefined

getRoyaltyInfoForToken

function getRoyaltyInfoForToken(uint256 _tokenId) external view returns (address, uint16)

View royalty info for a given token.

Returns royalty recipient and bps for _tokenId.

Parameters

NameTypeDescription
_tokenIduint256The tokenID of the NFT for which to query royalty info.

Returns

NameTypeDescription
_0addressundefined
_1uint16undefined

isApprovedForAll

function isApprovedForAll(address owner, address operator) external view returns (bool)

See {IERC721-isApprovedForAll}.

Parameters

NameTypeDescription
owneraddressundefined
operatoraddressundefined

Returns

NameTypeDescription
_0boolundefined

isApprovedOrOwner

function isApprovedOrOwner(address _operator, uint256 _tokenId) external view returns (bool isApprovedOrOwnerOf)

Returns whether a given address is the owner, or approved to transfer an NFT.

Parameters

NameTypeDescription
_operatoraddressundefined
_tokenIduint256undefined

Returns

NameTypeDescription
isApprovedOrOwnerOfboolundefined

mintTo

function mintTo(address _to, string _tokenURI) external nonpayable

Lets an authorized address mint an NFT to a recipient.

The logic in the _canMint function determines whether the caller is authorized to mint NFTs.

Parameters

NameTypeDescription
_toaddressThe recipient of the NFT to mint.
_tokenURIstringThe full metadata URI for the NFT minted.

multicall

function multicall(bytes[] data) external nonpayable returns (bytes[] results)

Receives and executes a batch of function calls on this contract.

Receives and executes a batch of function calls on this contract.

Parameters

NameTypeDescription
databytes[]The bytes data that makes up the batch of function calls to execute.

Returns

NameTypeDescription
resultsbytes[]The bytes data that makes up the result of the batch of function calls executed.

name

function name() external view returns (string)

See {IERC721Metadata-name}.

Returns

NameTypeDescription
_0stringundefined

nextTokenIdToMint

function nextTokenIdToMint() external view returns (uint256)

The tokenId assigned to the next new NFT to be minted.

Returns

NameTypeDescription
_0uint256undefined

owner

function owner() external view returns (address)

Returns the owner of the contract.

Returns

NameTypeDescription
_0addressundefined

ownerOf

function ownerOf(uint256 tokenId) external view returns (address)

See {IERC721-ownerOf}.

Parameters

NameTypeDescription
tokenIduint256undefined

Returns

NameTypeDescription
_0addressundefined

royaltyInfo

function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount)

View royalty info for a given token and sale price.

Returns royalty amount and recipient for tokenId and salePrice.

Parameters

NameTypeDescription
tokenIduint256The tokenID of the NFT for which to query royalty info.
salePriceuint256Sale price of the token.

Returns

NameTypeDescription
receiveraddressAddress of royalty recipient account.
royaltyAmountuint256Royalty amount calculated at current royaltyBps value.

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable

See {IERC721-safeTransferFrom}.

Parameters

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) external nonpayable

See {IERC721-safeTransferFrom}.

Parameters

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined
_databytesundefined

setApprovalForAll

function setApprovalForAll(address operator, bool approved) external nonpayable

See {IERC721-setApprovalForAll}.

Parameters

NameTypeDescription
operatoraddressundefined
approvedboolundefined

setContractURI

function setContractURI(string _uri) external nonpayable

Lets a contract admin set the URI for contract-level metadata.

Caller should be authorized to setup contractURI, e.g. contract admin. See {_canSetContractURI}. Emits {ContractURIUpdated Event}.

Parameters

NameTypeDescription
_uristringkeccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")

setDefaultRoyaltyInfo

function setDefaultRoyaltyInfo(address _royaltyRecipient, uint256 _royaltyBps) external nonpayable

Updates default royalty recipient and bps.

Caller should be authorized to set royalty info. See {_canSetRoyaltyInfo}. Emits {DefaultRoyalty Event}; See {_setupDefaultRoyaltyInfo}.

Parameters

NameTypeDescription
_royaltyRecipientaddressAddress to be set as default royalty recipient.
_royaltyBpsuint256Updated royalty bps.

setOwner

function setOwner(address _newOwner) external nonpayable

Lets an authorized wallet set a new owner for the contract.

Parameters

NameTypeDescription
_newOwneraddressThe address to set as the new owner of the contract.

setRoyaltyInfoForToken

function setRoyaltyInfoForToken(uint256 _tokenId, address _recipient, uint256 _bps) external nonpayable

Updates default royalty recipient and bps for a particular token.

Sets royalty info for _tokenId. Caller should be authorized to set royalty info. See {_canSetRoyaltyInfo}. Emits {RoyaltyForToken Event}; See {_setupRoyaltyInfoForToken}.

Parameters

NameTypeDescription
_tokenIduint256undefined
_recipientaddressAddress to be set as royalty recipient for given token Id.
_bpsuint256Updated royalty bps for the token Id.

supportsInterface

function supportsInterface(bytes4 interfaceId) external view returns (bool)

See ERC165: https://eips.ethereum.org/EIPS/eip-165

Parameters

NameTypeDescription
interfaceIdbytes4undefined

Returns

NameTypeDescription
_0boolundefined

symbol

function symbol() external view returns (string)

See {IERC721Metadata-symbol}.

Returns

NameTypeDescription
_0stringundefined

tokenURI

function tokenURI(uint256 _tokenId) external view returns (string)

Returns the metadata URI for an NFT.

See BatchMintMetadata for handling of metadata in this contract.

Parameters

NameTypeDescription
_tokenIduint256The tokenId of an NFT.

Returns

NameTypeDescription
_0stringundefined

totalSupply

function totalSupply() external view returns (uint256)

Burned tokens are calculated here, use _totalMinted() if you want to count just minted tokens.

Returns

NameTypeDescription
_0uint256undefined

transferFrom

function transferFrom(address from, address to, uint256 tokenId) external nonpayable

See {IERC721-transferFrom}.

Parameters

NameTypeDescription
fromaddressundefined
toaddressundefined
tokenIduint256undefined

Events

Approval

event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)

Parameters

NameTypeDescription
owner indexedaddressundefined
approved indexedaddressundefined
tokenId indexeduint256undefined

ApprovalForAll

event ApprovalForAll(address indexed owner, address indexed operator, bool approved)

Parameters

NameTypeDescription
owner indexedaddressundefined
operator indexedaddressundefined
approvedboolundefined

ContractURIUpdated

event ContractURIUpdated(string prevURI, string newURI)

Parameters

NameTypeDescription
prevURIstringundefined
newURIstringundefined

DefaultRoyalty

event DefaultRoyalty(address indexed newRoyaltyRecipient, uint256 newRoyaltyBps)

Parameters

NameTypeDescription
newRoyaltyRecipient indexedaddressundefined
newRoyaltyBpsuint256undefined

OwnerUpdated

event OwnerUpdated(address indexed prevOwner, address indexed newOwner)

Parameters

NameTypeDescription
prevOwner indexedaddressundefined
newOwner indexedaddressundefined

RoyaltyForToken

event RoyaltyForToken(uint256 indexed tokenId, address indexed royaltyRecipient, uint256 royaltyBps)

Parameters

NameTypeDescription
tokenId indexeduint256undefined
royaltyRecipient indexedaddressundefined
royaltyBpsuint256undefined

Transfer

event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)

Parameters

NameTypeDescription
from indexedaddressundefined
to indexedaddressundefined
tokenId indexeduint256undefined

Errors

ApprovalCallerNotOwnerNorApproved

error ApprovalCallerNotOwnerNorApproved()

The caller must own the token or be an approved operator.

ApprovalQueryForNonexistentToken

error ApprovalQueryForNonexistentToken()

The token does not exist.

ApprovalToCurrentOwner

error ApprovalToCurrentOwner()

The caller cannot approve to the current owner.

ApproveToCaller

error ApproveToCaller()

The caller cannot approve to their own address.

BalanceQueryForZeroAddress

error BalanceQueryForZeroAddress()

Cannot query the balance for the zero address.

MintToZeroAddress

error MintToZeroAddress()

Cannot mint to the zero address.

MintZeroQuantity

error MintZeroQuantity()

The quantity of tokens minted must be more than zero.

OwnerQueryForNonexistentToken

error OwnerQueryForNonexistentToken()

The token does not exist.

TransferCallerNotOwnerNorApproved

error TransferCallerNotOwnerNorApproved()

The caller must own the token or be an approved operator.

TransferFromIncorrectOwner

error TransferFromIncorrectOwner()

The token must be owned by from.

TransferToNonERC721ReceiverImplementer

error TransferToNonERC721ReceiverImplementer()

Cannot safely transfer to a contract that does not implement the ERC721Receiver interface.

TransferToZeroAddress

error TransferToZeroAddress()

Cannot transfer to the zero address.

URIQueryForNonexistentToken

error URIQueryForNonexistentToken()

The token does not exist.