ERC-721 NFTs¶
Unique tokens follow ERC-721. Tested in Create NFTs.
PQCollection.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/// Example ERC-721 collection: the owner mints sequential IDs; metadata lives at baseURI + tokenId.
/// Unaudited tutorial code.
contract PQCollection is ERC721, Ownable {
uint256 public nextId = 1;
string private base;
constructor(string memory baseURI_, address owner_) ERC721("Tutorial Collection", "TCOL") Ownable(owner_) {
base = baseURI_;
}
function mint(address to) external onlyOwner returns (uint256 id) {
id = nextId++;
_safeMint(to, id);
}
function _baseURI() internal view override returns (string memory) {
return base;
}
}
tokenURI(id)returnsbaseURI + id; host JSON metadata on IPFS or HTTPS. The chain stores only the URI._safeMint/safeTransferFromrevert withERC721InvalidReceiverif a receiving contract lacksonERC721Received.Transfer(from, to, tokenId)hastokenIdindexed; the explorer uses this to index NFT transfers.- The Windows Wallet lists ERC-721 tokens it discovers and transfers them; its Studio NFT collection template deploys an equivalent OpenZeppelin collection without code.
Sources at 72057fe3ec: developers/examples/nft/src/PQCollection.sol
Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec