I’m very new to solidity programming, and I’m following an old tutorial based on 0.5.0.
I’ve tried to modify the tutorial for a recent version.
I’m trying to create a ECR721 token, and I have code that works. I am however extending from ERC721, ERC721URIStorage and ERC721Enumerable, and I believe there are some issues with methods from those contracts.
Did I correctly resolve these issues, or am I missing some key concepts from the solidity language?
How is super resolved for those methods? It’s not clear to me which supercontract would be used.
pragma solidity ^0.8.26;
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import { ERC721URIStorage } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import { ERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract MemoryToken is ERC721, ERC721URIStorage, ERC721Enumerable {
mapping (uint256 => address) private _tokenOwner;
mapping(uint256 tokenId => string) private _tokenURIs;
constructor() ERC721("Memory Token", "MEMORY") {
}
function mint(address _to, string memory _tokenURI) public returns(bool) {
uint _tokenId = totalSupply() + 1;
_mint(_to, _tokenId);
_setTokenURI(_tokenId, _tokenURI);
return true;
}
function tokenURI(uint256 _tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(_tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable, ERC721URIStorage) returns (bool) {
return
interfaceId == type(ERC721).interfaceId ||
interfaceId == type(ERC721URIStorage).interfaceId ||
interfaceId == type(ERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
function _update(address to, uint256 tokenId, address auth) internal override(ERC721, ERC721Enumerable) returns (address) {
return super._update(to, tokenId, auth);
}
function _increaseBalance(address account, uint128 amount) internal override(ERC721, ERC721Enumerable) {
super._increaseBalance(account, amount);
}
}