Update from ERC721CToken to OpenZeppelin Contracts ERC721

I am trying to upgrade a project from ERC721CToken.sol contract to ERC721.sol contract

/// Requires the amount of Ether be at least or more of the currentPrice

  /// Creates an instance of an token and mints it to the purchaser

  /// _type The token type as an integer

  /// _title The short title of the token

  function buyToken (

    uint256 _type,

    string calldata _title

  ) external payable {

    bytes memory _titleBytes = bytes(_title);

    require(_titleBytes.length >= TITLE_MIN_LENGTH, "Title is too short");

    require(_titleBytes.length <= TITLE_MAX_LENGTH, "Title is too long");

    require(msg.value >= currentPrice, "Amount of Ether sent too small");

    uint256 index = allTokens.length + 1;

    _mint(msg.sender, index);

    tokenTypes[index] = _type;

    tokenTitles[index] = _title;

    emit BoughtToken(msg.sender, index);

  }

/**

   *  Returns all of the tokens that the user owns

   * An array of token indices

   */

  function myTokens()

    external

    view

    returns (

      uint256[] memory

    )

  {

    return ownedTokens[msg.sender];

  }

:computer: Environment
I am using truffle with “@openzeppelin/contracts”: “^2.5.0”,

:memo:Details
I would like to upgrade the above methods to ERC721 format. What will be the equivalent methods for the above?

:1234: Code to reproduce

1 Like

Hi @xariaSG,

Welcome to the community :wave:

I am not familiar with ERC721CToken. It looks like you are just adding a buy function which does the minting and keeping some onchain meta data.

You should be able to extend the OpenZeppelin Contracts ERC721 implementation to add the buy functionality to mint an ERC721 and the storing of metadata.

You can have a look at the simple example in the OpenZeppelin Contracts 3.x documentation:
https://docs.openzeppelin.com/contracts/3.x/erc721#constructing_an_erc721_token_contract

Otherwise OpenZeppelin Contracts 2.x documentation (as you are using OpenZeppelin Contracts 2.5): https://docs.openzeppelin.com/contracts/2.x/erc721#constructing_an_erc721_token_contract