```solidity

// SPDXLicenseIdentifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

import "@openzeppelin/contracts/utils/Counters.sol";

contract BlindBox is ERC721, Ownable {

using Counters for Counters.Counter;

Counters.Counter private _tokenIds;

mapping(uint256 => string) private _tokenURIs;

event TokenURIUpdated(uint256 indexed tokenId, string tokenURI);

constructor(string memory name, string memory symbol) ERC721(name, symbol) {}

function mint(address to, string memory tokenURI) external onlyOwner returns (uint256) {

_tokenIds.increment();

uint256 newTokenId = _tokenIds.current();

_mint(to, newTokenId);

_setTokenURI(newTokenId, tokenURI);

return newTokenId;

}

function _setTokenURI(uint256 tokenId, string memory tokenURI) internal {

require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");

_tokenURIs[tokenId] = tokenURI;

emit TokenURIUpdated(tokenId, tokenURI);

}

function tokenURI(uint256 tokenId) public view override returns (string memory) {

require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

string memory uri = _tokenURIs[tokenId];

return uri;

}

function updateTokenURI(uint256 tokenId, string memory newTokenURI) external onlyOwner {

_setTokenURI(tokenId, newTokenURI);

}

}

```

免责声明:本网站部分内容由用户自行上传,若侵犯了您的权益,请联系我们处理,谢谢!联系QQ:2760375052

分享:

扫一扫在手机阅读、分享本文

萍果

这家伙太懒。。。

  • 暂无未发布任何投稿。