Skip to main content

ERC721 Base

import "@thirdweb-dev/contracts/base/ERC721Base.sol";

The ERC721Base smart contract implements the ERC721 NFT standard, along with the ERC721A optimization to the standard. It allows you to mint NFTs to yourself (or to someone else) and selling those NFTs on a marketplace.

Detected Extensions

Once deployed, you can use the features made available by these extensions on the SDK and dashboard:

Click on each feature to learn more about what functions are available.

Usage

Import the contract and inherit from it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/base/ERC721Base.sol";

contract MyNFT is ERC721Base {

constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
)
ERC721Base(
_defaultAdmin,
_name,
_symbol,
_royaltyRecipient,
_royaltyBps
)
{}

}

Functions to Override

The following functions have been implemented on this contract & are available to be overridden to add custom logic:

tokenURI
    /**
* @notice Returns the metadata URI for an NFT.
* @dev See `BatchMintMetadata` for handling of metadata in this contract.
*
* @param _tokenId The tokenId of an NFT.
*/
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
string memory fullUriForToken = fullURI[_tokenId];
if (bytes(fullUriForToken).length > 0) {
return fullUriForToken;
}

string memory batchUri = _getBaseURI(_tokenId);
return string(abi.encodePacked(batchUri, _tokenId.toString()));
}
mintTo
    /**
* @notice Lets an authorized address mint an NFT to a recipient.
* @dev The logic in the `_canMint` function determines whether the caller is authorized to mint NFTs.
*
* @param _to The recipient of the NFT to mint.
* @param _tokenURI The full metadata URI for the NFT minted.
*/
function mintTo(address _to, string memory _tokenURI) public virtual {
require(_canMint(), "Not authorized to mint.");
_setTokenURI(nextTokenIdToMint(), _tokenURI);
_safeMint(_to, 1, "");
}
batchMintTo
    /**
* @notice Lets an authorized address mint multiple NFTs at once to a recipient.
* @dev The logic in the `_canMint` function determines whether the caller is authorized to mint NFTs.
*
* @param _to The recipient of the NFT to mint.
* @param _quantity The number of NFTs to mint.
* @param _baseURI The baseURI for the `n` number of NFTs minted. The metadata for each NFT is `baseURI/tokenId`
* @param _data Additional data to pass along during the minting of the NFT.
*/
function batchMintTo(
address _to,
uint256 _quantity,
string memory _baseURI,
bytes memory _data
) public virtual {
require(_canMint(), "Not authorized to mint.");
_batchMintMetadata(nextTokenIdToMint(), _quantity, _baseURI);
_safeMint(_to, _quantity, _data);
}
burn
    /**
* @notice Lets an owner or approved operator burn the NFT of the given tokenId.
* @dev ERC721A's `_burn(uint256,bool)` internally checks for token approvals.
*
* @param _tokenId The tokenId of the NFT to burn.
*/
function burn(uint256 _tokenId) external virtual {
_burn(_tokenId, true);
}

/*//////////////////////////////////////////////////////////////
Public getters
//////////////////////////////////////////////////////////////*/

/// @notice The tokenId assigned to the next new NFT to be minted.
function nextTokenIdToMint() public view virtual returns (uint256) {
return _currentIndex;
}
transferFrom
    /// @dev See {ERC721-_transferFrom}.
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override(ERC721A) onlyAllowedOperator(from) {
super.transferFrom(from, to, tokenId);
}
safeTransferFrom
    /// @dev See {ERC721-_safeTransferFrom}.
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override(ERC721A) onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId);
}