Decentralized-Spotify icon indicating copy to clipboard operation
Decentralized-Spotify copied to clipboard

Convert album.sol to ERC721A

Open Arkay92 opened this issue 2 years ago • 0 comments

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

import "https://raw.githubusercontent.com/chiru-labs/ERC721A/main/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract NFT is ERC721A, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    address public theowner;
	string public baseURI;
	string public baseExtension = ".json";

    constructor() ERC721A("NonFungiMusic", "NFM") {
        theowner = msg.sender;
    }

    // Create token in sequentially
    function createToken(string memory currentToken) public returns (uint) {
        require(msg.sender == theowner, "Only owner is allowed to createTokens");
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();

        _mint(msg.sender, newItemId);
        tokenURI(newItemId);
        return newItemId;
    }
    
    // override _startTokenId() function ~ line 100 of ERC721A
    function _startTokenId() internal view virtual override returns (uint256) {
    return 1;
    }

    // override _baseURI() function  ~ line 240 of ERC721A
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    // override tokenURI() function ~ line 228 of ERC721A
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
	return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, Strings.toString(tokenId), baseExtension)) : "";
    }
}

Arkay92 avatar Jul 09 '22 11:07 Arkay92