Rarable Clone Part6 - truffle migrate fail wth error

After setup truffle.config.js, 2_token_migration.js and MorarableToken.sol, I tried to run truffle migrate but it failed with an error.

Is there a bad version of Node.js?

Error parsing /Users/mbp/NFT/moralis-rarible/contracts/contracts/Migrations.sol: Cannot read property ‘addFunction’ of undefined

truffle.config.js

version: "^0.8.0"

2_token_migration.js

const MorarableToken = artifacts.require("MorarableToken");

module.exports = function (deployer) {
  deployer.deploy(MorarableToken);
};

MorarableToken.sol

pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";

contract MorarableToken is ERC721 {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721("MorarableToken", "MORA") {}

    struct Item {
        uint256 id;
        address creator;
        string uri;
    }

    mapping(uint256 => Item) public Items;

    function createItem(string memory uri) public returns (uint256) {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _safeMint(msg.sender, newItemId);

        Items[newItemId] = Item(newItemId, msg.sender, uri);

        return newItemId;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        return Items[tokenId].uri;
    }
}
1 Like

I executed npm i @openzeppelin/contracts on the rarible-clone/contracts.
It’s right, I guess.

I changed Node v12.18.4 and npm i @openzeppelin/contracts , but the error message was same.

It Solved!

nodebrew use stable

npm install -g truffle

truffle version

truffle init

And then, truffle migrate has worked well.

And also, I should have killed the virtual environmental of conda.(Because I used conda for previous part.)
conda deactivated

1 Like

Hi @classlacia,

That’s great. Keep up the enthusiasm! It’s really infectious! :slight_smile: